Introduced connect-socket-no-wait and connect-socket-successful?.

This commit is contained in:
mainzelm 2002-11-22 12:26:08 +00:00
parent b2f0570a86
commit 21364665ee
1 changed files with 25 additions and 19 deletions

View File

@ -216,7 +216,7 @@
;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;;; connect syscall
;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(define (connect-socket sock name)
(define (connect-socket-no-wait sock name)
(cond ((not (socket? sock))
(error "connect-socket: socket expected ~s" sock))
((not (socket-address? name))
@ -240,24 +240,30 @@
(socket-address:address name))))
(if (car error?.einprogress?)
(if (cdr error?.einprogress?)
(begin
(select '#()
(vector (fdport-data:fd
(fdport-data
(socket:outport sock))))
'#())
;; If connect returned EINPROGRESS, we can check
;; it's success after the next success with getsockopt
(let ((val (socket-option sock
level/socket
socket/error)))
(if (not (zero? val))
(errno-error val
(errno-msg val)
%connect
sock
name))))
(loop)))))))))))
#f
(loop))
#t)))))))))
(define (connect-socket-successful? sock)
;; If connect returned EINPROGRESS, we can check
;; it's success after the next success with getsockopt
(zero? (socket-option sock level/socket socket/error)))
(define (connect-socket sock name)
(let ((success? (connect-socket-no-wait sock name)))
(cond ((not success?)
(select '#()
(vector (fdport-data:fd
(fdport-data
(socket:outport sock))))
'#())
(if (not (connect-socket-successful? sock))
(let ((errno (socket-option sock level/socket socket/error)))
(errno-error errno
(errno-msg errno)
%connect
sock
name)))))))
(import-os-error-syscall %connect (sockfd family name) "scheme_connect")