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)))
|
(let ((family (socket:family sock)))
|
||||||
(cond ((not (= family (socket-address:family name)))
|
(cond ((not (= family (socket-address:family name)))
|
||||||
(error
|
(error
|
||||||
"connect: trying to connect socket to incompatible address ~s"
|
"connect: trying to connect socket to incompatible address ~s"
|
||||||
name))
|
name))
|
||||||
(else
|
(else
|
||||||
(%connect (socket->fdes sock)
|
(let loop ()
|
||||||
(socket:family sock)
|
((structure-ref interrupts disable-interrupts!))
|
||||||
(socket-address:address name))))))))
|
(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
|
(define-stubless-foreign %connect (sockfd family name) "scheme_connect")
|
||||||
(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)
|
|
||||||
|
|
||||||
;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||||
;;; listen syscall
|
;;; 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:
|
case AF_UNIX:
|
||||||
{
|
{
|
||||||
struct sockaddr_un name;
|
struct sockaddr_un name;
|
||||||
|
int ret;
|
||||||
int scheme_length=S48_STRING_LENGTH(scheme_name);
|
int scheme_length=S48_STRING_LENGTH(scheme_name);
|
||||||
|
|
||||||
name.sun_family=AF_UNIX;
|
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),
|
S48_ADDRESS_AFTER_HEADER(scheme_name,char),
|
||||||
scheme_length); /* copy to c string */
|
scheme_length); /* copy to c string */
|
||||||
name.sun_path[scheme_length]='\0'; /* add null */
|
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:
|
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_family=AF_INET;
|
||||||
name.sin_addr.s_addr=addr;
|
name.sin_addr.s_addr=addr;
|
||||||
name.sin_port=port;
|
name.sin_port=port;
|
||||||
|
|
||||||
return(connect(sockfd,(struct sockaddr *)&name,sizeof(name)));
|
if (connect(sockfd,(struct sockaddr *)&name,sizeof(name)) == 0)
|
||||||
|
return S48_TRUE;
|
||||||
break;
|
|
||||||
|
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:
|
default:
|
||||||
return(-1);
|
return(-1); /* error unknown address family */
|
||||||
/* 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);
|
int newsockfd=accept(sockfd,(struct sockaddr *)&name,&namelen);
|
||||||
|
|
||||||
if (newsockfd < 0)
|
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));
|
return(s48_enter_fixnum (newsockfd));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
int scheme_bind(int sockfd, int family, s48_value scheme_name);
|
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);
|
s48_value scheme_accept(s48_value sockfd, s48_value family, s48_value scheme_name);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue