connect for non-blocking sockets. Untested code.
This commit is contained in:
parent
fd69c40875
commit
f095b068a8
|
@ -223,20 +223,21 @@
|
|||
(let ((family (socket:family sock)))
|
||||
(cond ((not (= family (socket-address:family name)))
|
||||
(error
|
||||
"connect: trying to connect socket to incompatible address ~s"
|
||||
name))
|
||||
"connect: trying to connect socket to incompatible address ~s"
|
||||
name))
|
||||
(else
|
||||
(%connect (socket->fdes sock)
|
||||
(socket:family sock)
|
||||
(socket-address:address name))))))))
|
||||
(let loop ()
|
||||
((structure-ref interrupts disable-interrupts!))
|
||||
(if (%connect (socket->fdes sock)
|
||||
(socket:family sock)
|
||||
(socket-address:address name))
|
||||
((structure-ref interrupts enable-interrupts!))
|
||||
(begin (wait-for-channel
|
||||
(fdport-data:channel
|
||||
(fdport-data (socket:inport sock))))
|
||||
(loop))))))))))
|
||||
|
||||
(define-foreign %connect/errno
|
||||
(scheme_connect (fixnum sockfd) ; socket fdes
|
||||
(fixnum family) ; address family
|
||||
(desc name)) ; scheme descriptor
|
||||
(to-scheme fixnum errno_or_false))
|
||||
|
||||
(define-errno-syscall (%connect sockfd family name) %connect/errno)
|
||||
(define-stubless-foreign %connect (sockfd family name) "scheme_connect")
|
||||
|
||||
;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
;;; listen syscall
|
||||
|
|
|
@ -66,13 +66,15 @@ int scheme_bind(int sockfd, int family, s48_value scheme_name)
|
|||
}
|
||||
|
||||
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
|
||||
int scheme_connect(int sockfd, int family, s48_value scheme_name)
|
||||
s48_value scheme_connect(s48_value sock, s48_value family, s48_value scheme_name)
|
||||
{
|
||||
switch(family)
|
||||
int sockfd = s48_extract_fixnum (sock);
|
||||
switch(s48_extract_fixnum (family))
|
||||
{
|
||||
case AF_UNIX:
|
||||
{
|
||||
struct sockaddr_un name;
|
||||
int ret;
|
||||
int scheme_length=S48_STRING_LENGTH(scheme_name);
|
||||
|
||||
name.sun_family=AF_UNIX;
|
||||
|
@ -82,8 +84,19 @@ int scheme_connect(int sockfd, int family, s48_value scheme_name)
|
|||
S48_ADDRESS_AFTER_HEADER(scheme_name,char),
|
||||
scheme_length); /* copy to c string */
|
||||
name.sun_path[scheme_length]='\0'; /* add null */
|
||||
return(connect(sockfd,(struct sockaddr *)&name,sizeof(name)));
|
||||
break;
|
||||
|
||||
if (connect(sockfd,(struct sockaddr *)&name,sizeof(name)) == 0)
|
||||
return S48_TRUE;
|
||||
|
||||
if (errno != EWOULDBLOCK && errno != EINTR && errno != EALREADY
|
||||
&& errno != EINPROGRESS && errno != EAGAIN)
|
||||
s48_raise_os_error(errno);
|
||||
|
||||
if (! (s48_add_pending_fd(sockfd, 0)))
|
||||
s48_raise_out_of_memory_error();
|
||||
|
||||
return S48_FALSE;
|
||||
|
||||
}
|
||||
case AF_INET:
|
||||
{
|
||||
|
@ -95,14 +108,22 @@ int scheme_connect(int sockfd, int family, s48_value scheme_name)
|
|||
name.sin_family=AF_INET;
|
||||
name.sin_addr.s_addr=addr;
|
||||
name.sin_port=port;
|
||||
|
||||
return(connect(sockfd,(struct sockaddr *)&name,sizeof(name)));
|
||||
|
||||
break;
|
||||
|
||||
if (connect(sockfd,(struct sockaddr *)&name,sizeof(name)) == 0)
|
||||
return S48_TRUE;
|
||||
|
||||
if (errno != EWOULDBLOCK && errno != EINTR && errno != EALREADY
|
||||
&& errno != EINPROGRESS && errno != EAGAIN)
|
||||
s48_raise_os_error(errno);
|
||||
|
||||
if (! (s48_add_pending_fd(sockfd, 0)))
|
||||
s48_raise_out_of_memory_error();
|
||||
|
||||
return S48_FALSE;
|
||||
|
||||
}
|
||||
default:
|
||||
return(-1);
|
||||
/* error unknown address family */
|
||||
return(-1); /* error unknown address family */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +140,13 @@ s48_value scheme_accept(s48_value sockfd_tagged, s48_value family, s48_value sch
|
|||
int newsockfd=accept(sockfd,(struct sockaddr *)&name,&namelen);
|
||||
|
||||
if (newsockfd < 0)
|
||||
s48_raise_os_error(errno);
|
||||
{
|
||||
if ((errno != EWOULDBLOCK) && (errno != EINTR) && (errno != EAGAIN))
|
||||
s48_raise_os_error(errno);
|
||||
if (! s48_add_pending_fd(sockfd, 1))// 1 for is_input
|
||||
s48_raise_out_of_memory_error();
|
||||
return S48_FALSE;
|
||||
}
|
||||
|
||||
return(s48_enter_fixnum (newsockfd));
|
||||
break;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
int scheme_bind(int sockfd, int family, s48_value scheme_name);
|
||||
|
||||
int scheme_connect(int sockfd, int family, s48_value scheme_name);
|
||||
s48_value scheme_connect(s48_value sockfd, s48_value family, s48_value scheme_name);
|
||||
|
||||
s48_value scheme_accept(s48_value sockfd, s48_value family, s48_value scheme_name);
|
||||
|
||||
|
|
Loading…
Reference in New Issue