[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH] EGAIN
From: |
Felix |
Subject: |
[Chicken-hackers] [PATCH] EGAIN |
Date: |
Tue, 12 Jun 2012 10:06:47 +0200 (CEST) |
The attached patch handles EAGAIN in I/O operations the same way as
EWOULDBLOCK (it reschedules the operation). Before, EAGAIN was treated
as an error. This may be a possible fix for part of the problems
reported in #858.
cheers,
felix
>From e007540f8e521618411e850569d21f6a48531ed4 Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Tue, 12 Jun 2012 10:01:41 +0200
Subject: [PATCH] handle EAGAIN in I/O operations
---
posixunix.scm | 10 ++++++----
tcp.scm | 8 ++++++--
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/posixunix.scm b/posixunix.scm
index 76a0349..1839061 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 0d49c22..b9cbec1 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
--
1.6.0.4
- [Chicken-hackers] [PATCH] EGAIN,
Felix <=