Connect can now handle non-blocking sockets that return EINPROGRESS.

This commit is contained in:
marting 2000-07-11 10:30:23 +00:00
parent f095b068a8
commit 52291acc0e
2 changed files with 27 additions and 13 deletions

View File

@ -55,9 +55,10 @@
(dynamic-wind (dynamic-wind
(lambda () #f) (lambda () #f)
(lambda () (connect-socket sock addr) (set! connected #t)) (lambda () (connect-socket sock addr) (set! connected #t))
(lambda () (lambda () #f
(if (not connected) ;(if (not connected)
(close-socket sock)))) ; (close-socket sock))
))
(if connected (if connected
sock sock
#f)))) #f))))
@ -228,14 +229,25 @@
(else (else
(let loop () (let loop ()
((structure-ref interrupts disable-interrupts!)) ((structure-ref interrupts disable-interrupts!))
(if (%connect (socket->fdes sock) (let ((res (%connect (socket->fdes sock)
(socket:family sock) (socket:family sock)
(socket-address:address name)) (socket-address:address name))))
((structure-ref interrupts enable-interrupts!)) (cond ((eq? res #t)
(begin (wait-for-channel ((structure-ref interrupts enable-interrupts!)))
(fdport-data:channel (else (wait-for-channel
(fdport-data (socket:inport sock)))) (fdport-data:channel
(loop)))))))))) (fdport-data (socket:inport sock))))
(if (eq? res 0)
(handle-EINPROGRESS sock)
(loop))))))))))))
;;; If connect returned EINPROGRESS, we can check it's success after
;;; the next success with getsockopt
(define (handle-EINPROGRESS sock)
(let ((val (socket-option sock level/socket socket/error)))
(if (not (zero? val))
(errno-error val "scheme_connnect"))))
(define-stubless-foreign %connect (sockfd family name) "scheme_connect") (define-stubless-foreign %connect (sockfd family name) "scheme_connect")

View File

@ -115,11 +115,13 @@ s48_value scheme_connect(s48_value sock, s48_value family, s48_value scheme_name
if (errno != EWOULDBLOCK && errno != EINTR && errno != EALREADY if (errno != EWOULDBLOCK && errno != EINTR && errno != EALREADY
&& errno != EINPROGRESS && errno != EAGAIN) && errno != EINPROGRESS && errno != EAGAIN)
s48_raise_os_error(errno); s48_raise_os_error(errno);
if (! (s48_add_pending_fd(sockfd, 0))) if (! (s48_add_pending_fd(sockfd, 0)))
s48_raise_out_of_memory_error(); s48_raise_out_of_memory_error();
return S48_FALSE; if (errno == EINPROGRESS)
return s48_enter_fixnum (0);
else return S48_FALSE;
} }
default: default: