Welcome to the CHICKEN Scheme pasting service

tcp nonblocking fix added by rivo on Thu Nov 28 13:05:03 2013

diff --git a/tcp.scm b/tcp.scm
index 7609157..d140d09 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -59,6 +59,21 @@ static C_word make_socket_nonblocking (C_word sock) {
   int fd = C_unfix(sock);
   C_return(C_mk_bool(ioctlsocket(fd, FIONBIO, (void *)&fd) != SOCKET_ERROR)) ;
 }
+static int connect_nonblocking(int fd, void *addr, int addr_size) {
+  if (connect(fd, addr, addr_size) == SOCKET_ERROR) {
+    if (WSAGetLastError() == WSAEISCONN) { _set_errno(0); return 0; }
+    if (WSAGetLastError() == WSAEWOULDBLOCK) _set_errno(EINPROGRESS);
+    return -1;
+  }
+  return 0;
+}
+static int recv_nonblocking(int fd, void *buf, int size, int flags) {
+  int n = recv(fd, buf, size, flags);
+  if (n == SOCKET_ERROR) {
+    if (WSAGetLastError() == WSAEWOULDBLOCK) _set_errno(EAGAIN);
+  }
+  return n;
+}
 #else
 # include <fcntl.h>
 # include <sys/socket.h>
@@ -124,9 +139,9 @@ EOF
 (define ##net#listen (foreign-lambda int "listen" int int))
 (define ##net#accept (foreign-lambda int "accept" int c-pointer c-pointer))
 (define ##net#close (foreign-lambda int "closesocket" int))
-(define ##net#recv (foreign-lambda int "recv" int scheme-pointer int int))
+(define ##net#recv (foreign-lambda int "recv_nonblocking" int scheme-pointer int int))
 (define ##net#shutdown (foreign-lambda int "shutdown" int int))
-(define ##net#connect (foreign-lambda int "connect" int scheme-pointer int))
+(define ##net#connect (foreign-lambda int "connect_nonblocking" int scheme-pointer int))
 (define ##net#check-fd-ready (foreign-lambda int "C_check_fd_ready" int))
 
 (define ##net#send
@@ -555,7 +570,8 @@ EOF
 		 (when dlc
 		   (##sys#thread-block-for-timeout! ##sys#current-thread dlc))
 		 (##sys#thread-block-for-i/o! ##sys#current-thread s #:all)
-                 (##sys#thread-yield!))
+                 (##sys#thread-yield!)
+                 (loop))
 		((eq? errno _eintr)
 		 (##sys#dispatch-interrupt loop))
 		(else

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which relatively recent Scheme report version does CHICKEN _not_ implement?
Visually impaired? Let me spell it for you (wav file) download WAV