From f74f9b9b25aa461376b0b97e501ce66df29130e9 Mon Sep 17 00:00:00 2001 From: leitner Date: Fri, 16 Oct 2015 17:12:22 +0000 Subject: [PATCH] add socket_udp4b and socket_udp6b --- socket.h | 2 ++ socket/socket_udp4.c | 11 ++++++++--- socket/socket_udp6.c | 11 ++++++++--- t.c | 3 +++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/socket.h b/socket.h index 2ece1fd..20b6f91 100644 --- a/socket.h +++ b/socket.h @@ -14,9 +14,11 @@ extern "C" { int socket_tcp4(void); int socket_tcp4b(void); int socket_udp4(void); +int socket_udp4b(void); int socket_tcp6(void); int socket_tcp6b(void); int socket_udp6(void); +int socket_udp6b(void); int socket_sctp4(void); int socket_sctp4b(void); diff --git a/socket/socket_udp4.c b/socket/socket_udp4.c index e0a07d0..00812fc 100644 --- a/socket/socket_udp4.c +++ b/socket/socket_udp4.c @@ -9,11 +9,16 @@ #include "socket.h" #include "ndelay.h" -int socket_udp4(void) { +int socket_udp4b(void) { int s; __winsock_init(); s = winsock2errno(socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP)); - if (s == -1) return -1; - if (ndelay_on(s) == -1) { close(s); return -1; } + return s; +} + +int socket_udp4(void) { + int s; + s=socket_udp4b(); + if (s!=-1 && ndelay_on(s) == -1) { close(s); return -1; } return s; } diff --git a/socket/socket_udp6.c b/socket/socket_udp6.c index 14d6987..72b3971 100644 --- a/socket/socket_udp6.c +++ b/socket/socket_udp6.c @@ -20,7 +20,7 @@ #define EPROTONOSUPPORT EAFNOSUPPORT #endif -int socket_udp6(void) +int socket_udp6b(void) { #ifdef LIBC_HAS_IP6 int s; @@ -43,9 +43,14 @@ compat: winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero))); } #endif - if (ndelay_on(s) == -1) { close(s); return -1; } return s; #else - return socket_udp(); + return socket_udp4b(); #endif } + +int socket_udp6(void) { + int s=socket_udp6b(); + if (s!=-1 && ndelay_on(s) == -1) { close(s); return -1; } + return s; +} diff --git a/t.c b/t.c index a170826..f41dff0 100644 --- a/t.c +++ b/t.c @@ -68,10 +68,13 @@ static int ret1(const char* s,void* foo) { } int main(int argc,char* argv[]) { + int s=socket_udp6(); +#if 0 char buf[100]; assert(fmt_varint(buf,1)==1 && buf[0]==1); fmt_varint(buf,300); assert(fmt_varint(buf,300)==2 && buf[0]==(char)0xac && buf[1]==0x02); +#endif #if 0 const char buf[]="fnord\n"; buffer_puts(buffer_1,buf);