mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 14:30:34 +02:00
`accept' on nonblocking socket can return #f
* doc/ref/posix.texi (Network Sockets and Communication): * libguile/socket.c (scm_accept): Return #f if the socket is nonblocking and no connection is ready.
This commit is contained in:
parent
d8067213dc
commit
e6cc051f8c
2 changed files with 32 additions and 18 deletions
|
@ -3260,15 +3260,26 @@ The return value is unspecified.
|
||||||
@deffn {Scheme Procedure} accept sock
|
@deffn {Scheme Procedure} accept sock
|
||||||
@deffnx {C Function} scm_accept (sock)
|
@deffnx {C Function} scm_accept (sock)
|
||||||
Accept a connection from socket port @var{sock} which has been enabled
|
Accept a connection from socket port @var{sock} which has been enabled
|
||||||
for listening with @code{listen} above. If there are no incoming
|
for listening with @code{listen} above.
|
||||||
connections in the queue, wait until one is available (unless
|
|
||||||
@code{O_NONBLOCK} has been set on the socket, @pxref{Ports and File
|
If there are no incoming connections in the queue, there are two
|
||||||
Descriptors,@code{fcntl}}).
|
possible behaviors, depending on whether @var{sock} has been configured
|
||||||
|
for non-blocking operation or not:
|
||||||
|
|
||||||
|
@itemize
|
||||||
|
@item
|
||||||
|
If there is no connection waiting and the socket was set to non-blocking
|
||||||
|
mode with the @code{O_NONBLOCK} port option (@pxref{Ports and File
|
||||||
|
Descriptors,@code{fcntl}}), return @code{#f} directly.
|
||||||
|
|
||||||
|
@item
|
||||||
|
Otherwise wait until a connection is available.
|
||||||
|
@end itemize
|
||||||
|
|
||||||
The return value is a pair. The @code{car} is a new socket port,
|
The return value is a pair. The @code{car} is a new socket port,
|
||||||
connected and ready to communicate. The @code{cdr} is a socket
|
connected and ready to communicate. The @code{cdr} is a socket address
|
||||||
address object (@pxref{Network Socket Address}) which is where the
|
object (@pxref{Network Socket Address}) which is where the remote
|
||||||
remote connection is from (like @code{getpeername} below).
|
connection is from (like @code{getpeername} below).
|
||||||
|
|
||||||
All communication takes place using the new socket returned. The
|
All communication takes place using the new socket returned. The
|
||||||
given @var{sock} remains bound and listening, and @code{accept} may be
|
given @var{sock} remains bound and listening, and @code{accept} may be
|
||||||
|
|
|
@ -1236,16 +1236,15 @@ SCM_DEFINE (scm_make_socket_address, "make-socket-address", 2, 0, 1,
|
||||||
|
|
||||||
SCM_DEFINE (scm_accept, "accept", 1, 0, 0,
|
SCM_DEFINE (scm_accept, "accept", 1, 0, 0,
|
||||||
(SCM sock),
|
(SCM sock),
|
||||||
"Accept a connection on a bound, listening socket.\n"
|
"Accept a connection on a bound, listening socket. If there\n"
|
||||||
"If there\n"
|
"are no pending connections in the queue, there are two\n"
|
||||||
"are no pending connections in the queue, wait until\n"
|
"possibilities: if the socket has been configured as\n"
|
||||||
"one is available unless the non-blocking option has been\n"
|
"non-blocking, return @code{#f} directly. Otherwise wait\n"
|
||||||
"set on the socket.\n\n"
|
"until a connection is available. When a connection comes,\n"
|
||||||
"The return value is a\n"
|
"the return value is a pair in which the @emph{car} is a new\n"
|
||||||
"pair in which the @emph{car} is a new socket port for the\n"
|
"socket port for the connection and the @emph{cdr} is an\n"
|
||||||
"connection and\n"
|
"object with address information about the client which\n"
|
||||||
"the @emph{cdr} is an object with address information about the\n"
|
"initiated the connection.\n\n"
|
||||||
"client which initiated the connection.\n\n"
|
|
||||||
"@var{sock} does not become part of the\n"
|
"@var{sock} does not become part of the\n"
|
||||||
"connection and will continue to accept new requests.")
|
"connection and will continue to accept new requests.")
|
||||||
#define FUNC_NAME s_scm_accept
|
#define FUNC_NAME s_scm_accept
|
||||||
|
@ -1262,7 +1261,11 @@ SCM_DEFINE (scm_accept, "accept", 1, 0, 0,
|
||||||
fd = SCM_FPORT_FDES (sock);
|
fd = SCM_FPORT_FDES (sock);
|
||||||
SCM_SYSCALL (newfd = accept (fd, (struct sockaddr *) &addr, &addr_size));
|
SCM_SYSCALL (newfd = accept (fd, (struct sockaddr *) &addr, &addr_size));
|
||||||
if (newfd == -1)
|
if (newfd == -1)
|
||||||
|
{
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
|
return SCM_BOOL_F;
|
||||||
SCM_SYSERROR;
|
SCM_SYSERROR;
|
||||||
|
}
|
||||||
newsock = SCM_SOCK_FD_TO_PORT (newfd);
|
newsock = SCM_SOCK_FD_TO_PORT (newfd);
|
||||||
address = _scm_from_sockaddr (&addr, addr_size,
|
address = _scm_from_sockaddr (&addr, addr_size,
|
||||||
FUNC_NAME);
|
FUNC_NAME);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue