~ chicken-core (chicken-5) 7a1146608edf8339b9671c2baec487d318da0c36
commit 7a1146608edf8339b9671c2baec487d318da0c36
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Tue Jun 12 10:01:41 2012 +0200
Commit: Christian Kellermann <ckeen@pestilenz.org>
CommitDate: Tue Jun 12 10:55:01 2012 +0200
handle EAGAIN in I/O operations
Signed-off-by: Christian Kellermann <ckeen@pestilenz.org>
diff --git a/posixunix.scm b/posixunix.scm
index 76a0349b..18390613 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -1294,7 +1294,8 @@ EOF
(lambda ()
(let ((res (##sys#file-select-one fd)))
(if (fx= -1 res)
- (if (fx= _errno _ewouldblock)
+ (if (or (fx= _errno _ewouldblock)
+ (rx= _errno _eagain))
#f
(posix-error #:file-error loc "cannot select" fd nam))
(fx= 1 res))))]
@@ -1310,7 +1311,7 @@ EOF
(let ([cnt (##core#inline "C_read" fd buf bufsiz)])
(cond ((fx= cnt -1)
(select _errno
- ((_ewouldblock)
+ ((_ewouldblock _egain)
(##sys#thread-block-for-i/o! ##sys#current-thread fd #:input)
(##sys#thread-yield!)
(loop) )
@@ -1326,7 +1327,8 @@ EOF
(loop) )
(let ([cnt (##core#inline "C_read" fd buf bufsiz)])
(when (fx= cnt -1)
- (if (fx= _errno _ewouldblock)
+ (if (or (fx= _errno _ewouldblock)
+ (fx= _errno _eagain))
(set! cnt 0)
(posix-error #:file-error loc "cannot read" fd nam) ) )
(set! buflen cnt)
@@ -1423,7 +1425,7 @@ EOF
(let ([cnt (##core#inline "C_write" fd str len)])
(cond ((fx= -1 cnt)
(select _errno
- ((_ewouldblock)
+ ((_ewouldblock _eagain)
(##sys#thread-yield!)
(poke str len) )
((_eintr)
diff --git a/tcp.scm b/tcp.scm
index 0d49c227..b9cbec1a 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -45,6 +45,7 @@
static WSADATA wsa;
# define fcntl(a, b, c) 0
# define EWOULDBLOCK 0
+# define EAGAIN 0
# define EINPROGRESS 0
# define typecorrect_getsockopt(socket, level, optname, optval, optlen) \
getsockopt(socket, level, optname, (char *)optval, optlen)
@@ -99,6 +100,7 @@ EOF
(define-foreign-variable _ipproto_tcp int "IPPROTO_TCP")
(define-foreign-variable _invalid_socket int "INVALID_SOCKET")
(define-foreign-variable _ewouldblock int "EWOULDBLOCK")
+(define-foreign-variable _eagain int "EAGAIN")
(define-foreign-variable _eintr int "EINTR")
(define-foreign-variable _einprogress int "EINPROGRESS")
@@ -348,7 +350,8 @@ EOF
(let loop ()
(let ((n (##net#recv fd buf +input-buffer-size+ 0)))
(cond ((eq? -1 n)
- (cond ((eq? errno _ewouldblock)
+ (cond ((or (eq? errno _ewouldblock)
+ (eq? errno _eagain))
(when tmr
(##sys#thread-block-for-timeout!
##sys#current-thread
@@ -465,7 +468,8 @@ EOF
(let* ((count (fxmin +output-chunk-size+ len))
(n (##net#send fd s offset count 0)) )
(cond ((eq? -1 n)
- (cond ((eq? errno _ewouldblock)
+ (cond ((or (eq? errno _ewouldblock)
+ (eq? errno _eagain))
(when tmw
(##sys#thread-block-for-timeout!
##sys#current-thread
Trap