瀏覽代碼

Win32 socket changes.

Brucey 3 年之前
父節點
當前提交
385a4c648a
共有 2 個文件被更改,包括 135 次插入8 次删除
  1. 58 3
      stdc.mod/stdc.bmx
  2. 77 5
      stdc.mod/stdc.c

+ 58 - 3
stdc.mod/stdc.bmx

@@ -318,33 +318,76 @@ Function htons_:Int( n:Int )
 Function ntohs_:Int( n:Int )
 Function htonl_:Int( n:Int )
 Function ntohl_:Int( n:Int )
+?win32 and ptr64
+Function socket_:Long( addr_type:Int,comm_type:Int,protocol:Int=0 )
+Function closesocket_( socket:Long )
+Function bind_:Int( socket:Long,addr_type:Int,port:Int )
+?win32 and ptr32
 Function socket_:Int( addr_type:Int,comm_type:Int,protocol:Int=0 )
 Function closesocket_( socket:Int )
 Function bind_:Int( socket:Int,addr_type:Int,port:Int )
+?not win32
+Function socket_:Int( addr_type:Int,comm_type:Int,protocol:Int=0 )
+Function closesocket_( socket:Int )
+Function bind_:Int( socket:Int,addr_type:Int,port:Int )
+?
 Function gethostbyaddr_:Byte Ptr( addr:Byte Ptr,addr_len:Int,addr_type:Int )
 
 'Function gethostbyname_:Byte Ptr Ptr( name$,addr_type:Int Var,addr_len:Int Var )
 Function getaddrinfo_:TAddrInfo[](name:String, service:String = "http", family:Int = AF_UNSPEC_)
 Function getaddrinfo_hints:TAddrInfo[](name:String, service:String, hints:Byte Ptr)
 
+?not win32
 Function connect_:Int( socket:Int, addrinfo:Byte Ptr )
 Function listen_:Int( socket:Int,backlog:Int )
 Function accept_:Int( socket:Int,addr:Byte Ptr,addr_len:Byte Ptr)
 Function select_:Int( n_read:Int,read_socks:Int Ptr,n_write:Int,write_socks:Int Ptr,n_except:Int,except_socks:Int Ptr,millis:Int )
 Function sendto_:Int( socket:Int,buf:Byte Ptr,size:Int,flags:Int,dest_ip:Byte Ptr,dest_port:Int, addr_type:Int = AF_INET_ )
-?ptr64
+Function recvfrom_:Int( socket:Int,buf:Byte Ptr,size:Int,flags:Int,sender_ip:Int Var,sender_port:Int Var)
+Function setsockopt_:Int( socket:Int,level:Int,optname:Int,optval:Byte Ptr,count:Int)
+Function getsockopt_:Int( socket:Int,level:Int,optname:Int,optval:Byte Ptr,count:Int Var)
+Function shutdown_:Int( socket:Int,how:Int )
+Function getsockname_:Int( socket:Int,addr:Byte Ptr,addr_len:Int Var )
+Function getpeername_:Int( socket:Int,addr:Byte Ptr,addr_len:Int Var )
+?not win32 and ptr64
 Function send_:Long( socket:Int,buf:Byte Ptr,size:Size_T,flags:Int )
 Function recv_:Long( socket:Int,buf:Byte Ptr,size:Size_T,flags:Int )
-?Not ptr64
+?not win32 and Not ptr64
 Function send_:Int( socket:Int,buf:Byte Ptr,size:Size_T,flags:Int )
 Function recv_:Int( socket:Int,buf:Byte Ptr,size:Size_T,flags:Int )
 ?
+
+?win32 and ptr32
+Function connect_:Int( socket:Int, addrinfo:Byte Ptr )
+Function listen_:Int( socket:Int,backlog:Int )
+Function accept_:Int( socket:Int,addr:Byte Ptr,addr_len:Byte Ptr)
+Function select_:Int( n_read:Int,read_socks:Int Ptr,n_write:Int,write_socks:Int Ptr,n_except:Int,except_socks:Int Ptr,millis:Int )
+Function sendto_:Int( socket:Int,buf:Byte Ptr,size:Int,flags:Int,dest_ip:Byte Ptr,dest_port:Int, addr_type:Int = AF_INET_ )
 Function recvfrom_:Int( socket:Int,buf:Byte Ptr,size:Int,flags:Int,sender_ip:Int Var,sender_port:Int Var)
 Function setsockopt_:Int( socket:Int,level:Int,optname:Int,optval:Byte Ptr,count:Int)
 Function getsockopt_:Int( socket:Int,level:Int,optname:Int,optval:Byte Ptr,count:Int Var)
 Function shutdown_:Int( socket:Int,how:Int )
 Function getsockname_:Int( socket:Int,addr:Byte Ptr,addr_len:Int Var )
 Function getpeername_:Int( socket:Int,addr:Byte Ptr,addr_len:Int Var )
+Function send_:Int( socket:Int,buf:Byte Ptr,size:Size_T,flags:Int )
+Function recv_:Int( socket:Int,buf:Byte Ptr,size:Size_T,flags:Int )
+?
+
+?win32 and ptr64
+Function connect_:Int( socket:Long, addrinfo:Byte Ptr )
+Function listen_:Int( socket:Long,backlog:Int )
+Function accept_:Int( socket:Long,addr:Byte Ptr,addr_len:Byte Ptr)
+Function select_:Int( n_read:Int,read_socks:Long Ptr,n_write:Int,write_socks:Long Ptr,n_except:Int,except_socks:Long Ptr,millis:Int )
+Function sendto_:Int( socket:Long,buf:Byte Ptr,size:Int,flags:Int,dest_ip:Byte Ptr,dest_port:Int, addr_type:Int = AF_INET_ )
+Function recvfrom_:Int( socket:Long,buf:Byte Ptr,size:Int,flags:Int,sender_ip:Int Var,sender_port:Int Var)
+Function setsockopt_:Int( socket:Long,level:Int,optname:Int,optval:Byte Ptr,count:Int)
+Function getsockopt_:Int( socket:Long,level:Int,optname:Int,optval:Byte Ptr,count:Int Var)
+Function shutdown_:Int( socket:Long,how:Int )
+Function getsockname_:Int( socket:Long,addr:Byte Ptr,addr_len:Int Var )
+Function getpeername_:Int( socket:Long,addr:Byte Ptr,addr_len:Int Var )
+Function send_:Long( socket:Long,buf:Byte Ptr,size:Size_T,flags:Int )
+Function recv_:Long( socket:Long,buf:Byte Ptr,size:Size_T,flags:Int )
+?
 
 Function freeaddrinfo_(res:Byte Ptr)
 Function bmx_stdc_addrinfo_flags:Int(info:Byte Ptr)
@@ -362,12 +405,24 @@ Function bmx_stdc_addrinfo_setfamily(info:Byte Ptr, family:Int)
 Function bmx_stdc_addrinfo_setsocktype(info:Byte Ptr, sockType:Int)
 Function bmx_stdc_addrinfo_setprotocol(info:Byte Ptr, protocol:Int)
 
-Function bmx_stdc_bind_info:Int(socket:Int, info:Byte Ptr)
 Function bmx_stdc_sockaddrestorage_new:Byte Ptr()
 Function bmx_stdc_sockaddrestorage_address:String(handle:Byte Ptr)
+?not win32
+Function bmx_stdc_bind_info:Int(socket:Int, info:Byte Ptr)
 Function bmx_stdc_accept_:Int(socket:Int, storage:Byte Ptr)
 Function bmx_stdc_getsockname:Int(socket:Int, port:Int Var, address:String Var)
 Function bmx_stdc_getpeername:Int(socket:Int, port:Int Var, address:String Var)
+?win32 and ptr32
+Function bmx_stdc_bind_info:Int(socket:Int, info:Byte Ptr)
+Function bmx_stdc_accept_:Int(socket:Int, storage:Byte Ptr)
+Function bmx_stdc_getsockname:Int(socket:Int, port:Int Var, address:String Var)
+Function bmx_stdc_getpeername:Int(socket:Int, port:Int Var, address:String Var)
+?win32 and ptr64
+Function bmx_stdc_bind_info:Int(socket:Long, info:Byte Ptr)
+Function bmx_stdc_accept_:Int(socket:Long, storage:Byte Ptr)
+Function bmx_stdc_getsockname:Int(socket:Long, port:Int Var, address:String Var)
+Function bmx_stdc_getpeername:Int(socket:Long, port:Int Var, address:String Var)
+?
 
 'time
 

+ 77 - 5
stdc.mod/stdc.c

@@ -545,19 +545,20 @@ int ntohl_( int n ){
 	return ntohl( n );
 }
 
-int socket_( int addr_type,int comm_type,int protocol ){
 #if _WIN32
-	SOCKET s = socket( addr_type,comm_type,protocol );
-	return (s != INVALID_SOCKET) ? s :-1;
+SOCKET socket_( int addr_type,int comm_type,int protocol ){
+	return socket( addr_type,comm_type,protocol );
 #else
+int socket_( int addr_type,int comm_type,int protocol ){
 	return socket( addr_type,comm_type,protocol );
 #endif
 }
 
-void closesocket_( int s ){
 #if _WIN32
+void closesocket_( SOCKET s ){
 	closesocket( s );
 #else
+void closesocket_( int s ){
 	close( s );
 #endif
 }
@@ -574,7 +575,11 @@ int bmx_stdc_convertAFFamily(int family) {
 	return family;
 }
 
+#if _WIN32
+int bind_( SOCKET socket,int addr_type,int port ){
+#else
 int bind_( int socket,int addr_type,int port ){
+#endif
 	int r;
 	
 	//	if ( addr_type!=AF_INET ) return -1;
@@ -604,7 +609,11 @@ int bind_( int socket,int addr_type,int port ){
 	
 }
 
+#if _WIN32
+int bmx_stdc_bind_info(SOCKET socket, struct addrinfo * info) {
+#else
 int bmx_stdc_bind_info(int socket, struct addrinfo * info) {
+#endif
 	return bind(socket, info->ai_addr, info->ai_addrlen);
 }
 
@@ -671,19 +680,35 @@ void freeaddrinfo_(struct addrinfo * info ) {
 	freeaddrinfo(info);
 }
 
+#if _WIN32
+int connect_( SOCKET socket, struct addrinfo * info ){
+#else
 int connect_( int socket, struct addrinfo * info ){
+#endif
 	return connect( socket, info->ai_addr, info->ai_addrlen);
 }
 
+#if _WIN32
+int listen_( SOCKET socket,int backlog ){
+#else
 int listen_( int socket,int backlog ){
+#endif
 	return listen( socket,backlog );
 }
 
+#if _WIN32
+int accept_( SOCKET socket,const char *addr,unsigned int *addr_len ){
+#else
 int accept_( int socket,const char *addr,unsigned int *addr_len ){
+#endif
 	return accept( socket,(void*)addr,addr_len );
 }
 
+#if _WIN32
+int bmx_stdc_accept_(SOCKET socket, struct sockaddr_storage * storage) {
+#else
 int bmx_stdc_accept_(int socket, struct sockaddr_storage * storage) {
+#endif
 	if (storage) {
 		int size = sizeof(struct sockaddr_storage );
 		return accept(socket, (struct sockaddr *)storage, &size);
@@ -692,8 +717,11 @@ int bmx_stdc_accept_(int socket, struct sockaddr_storage * storage) {
 	}
 }
 
-
+#if _WIN32
+int select_( int n_read,SOCKET *r_socks,int n_write,SOCKET *w_socks,int n_except,SOCKET *e_socks,int millis ){
+#else
 int select_( int n_read,int *r_socks,int n_write,int *w_socks,int n_except,int *e_socks,int millis ){
+#endif
 
 	int i,n,r;
 	struct timeval tv,*tvp;
@@ -740,11 +768,19 @@ int select_( int n_read,int *r_socks,int n_write,int *w_socks,int n_except,int *
 	return r;
 }
 
+#if _WIN32
+ssize_t send_( SOCKET socket,const char *buf,size_t size,int flags ){
+#else
 ssize_t send_( int socket,const char *buf,size_t size,int flags ){
+#endif
 	return send( socket,buf,size,flags );
 }
 
+#if _WIN32
+int sendto_( SOCKET socket,const char *buf,int size,int flags,const char * dest_ip,int dest_port, int addr_type ){
+#else
 int sendto_( int socket,const char *buf,int size,int flags,const char * dest_ip,int dest_port, int addr_type ){
+#endif
 	addr_type = bmx_stdc_convertAFFamily(addr_type);
 	
 	switch (addr_type) {
@@ -776,11 +812,19 @@ int sendto_( int socket,const char *buf,int size,int flags,const char * dest_ip,
 	return 0;
 }
 
+#if _WIN32
+ssize_t recv_( SOCKET socket,char *buf,size_t size,int flags ){
+#else
 ssize_t recv_( int socket,char *buf,size_t size,int flags ){
+#endif
 	return recv( socket,buf,size,flags );
 }
 
+#if _WIN32
+int recvfrom_( SOCKET socket,char *buf,int size,int flags,int *_ip,int *_port){
+#else
 int recvfrom_( int socket,char *buf,int size,int flags,int *_ip,int *_port){
+#endif
 	struct	sockaddr_in sa;
 	int		sasize;
 	int		count;
@@ -792,23 +836,43 @@ int recvfrom_( int socket,char *buf,int size,int flags,int *_ip,int *_port){
 	return count;
 }
 
+#if _WIN32
+int setsockopt_( SOCKET socket,int level,int optname,const void *optval,int count){
+#else
 int setsockopt_( int socket,int level,int optname,const void *optval,int count){
+#endif
 	return setsockopt( socket,level,optname,optval,count);
 }
 
+#if _WIN32
+int getsockopt_( SOCKET socket,int level,int optname,void *optval,int *count){
+#else
 int getsockopt_( int socket,int level,int optname,void *optval,int *count){
+#endif
 	return getsockopt( socket,level,optname,optval,count);
 }
 
+#if _WIN32
+int shutdown_( SOCKET socket,int how ){
+#else
 int shutdown_( int socket,int how ){
+#endif
 	return shutdown( socket,how );
 }
 
+#if _WIN32
+int getsockname_( SOCKET socket,void *addr,int *len ){
+#else
 int getsockname_( int socket,void *addr,int *len ){
+#endif
 	return getsockname( socket,addr,len );
 }
 
+#if _WIN32
+int getpeername_( SOCKET socket,void *addr,int *len ){
+#else
 int getpeername_( int socket,void *addr,int *len ){
+#endif
 	return getpeername( socket,addr,len );
 }
 
@@ -958,7 +1022,11 @@ BBString * bmx_stdc_sockaddrestorage_address(struct sockaddr_storage * storage)
 	return address;
 }
 
+#if _WIN32
+int bmx_stdc_getsockname(SOCKET socket, int * port, BBSTRING * address) {
+#else
 int bmx_stdc_getsockname(int socket, int * port, BBSTRING * address) {
+#endif
 	struct sockaddr_storage storage;
 	int len = sizeof(struct sockaddr_storage);
 	
@@ -977,7 +1045,11 @@ int bmx_stdc_getsockname(int socket, int * port, BBSTRING * address) {
 	return res;
 }
 
+#if _WIN32
+int bmx_stdc_getpeername(SOCKET socket, int * port, BBSTRING * address) {
+#else
 int bmx_stdc_getpeername(int socket, int * port, BBSTRING * address) {
+#endif
 	struct sockaddr_storage storage;
 	int len = sizeof(struct sockaddr_storage);