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
|
||||
@deffnx {C Function} scm_accept (sock)
|
||||
Accept a connection from socket port @var{sock} which has been enabled
|
||||
for listening with @code{listen} above. If there are no incoming
|
||||
connections in the queue, wait until one is available (unless
|
||||
@code{O_NONBLOCK} has been set on the socket, @pxref{Ports and File
|
||||
Descriptors,@code{fcntl}}).
|
||||
for listening with @code{listen} above.
|
||||
|
||||
If there are no incoming connections in the queue, there are two
|
||||
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,
|
||||
connected and ready to communicate. The @code{cdr} is a socket
|
||||
address object (@pxref{Network Socket Address}) which is where the
|
||||
remote connection is from (like @code{getpeername} below).
|
||||
connected and ready to communicate. The @code{cdr} is a socket address
|
||||
object (@pxref{Network Socket Address}) which is where the remote
|
||||
connection is from (like @code{getpeername} below).
|
||||
|
||||
All communication takes place using the new socket returned. The
|
||||
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 sock),
|
||||
"Accept a connection on a bound, listening socket.\n"
|
||||
"If there\n"
|
||||
"are no pending connections in the queue, wait until\n"
|
||||
"one is available unless the non-blocking option has been\n"
|
||||
"set on the socket.\n\n"
|
||||
"The return value is a\n"
|
||||
"pair in which the @emph{car} is a new socket port for the\n"
|
||||
"connection and\n"
|
||||
"the @emph{cdr} is an object with address information about the\n"
|
||||
"client which initiated the connection.\n\n"
|
||||
"Accept a connection on a bound, listening socket. If there\n"
|
||||
"are no pending connections in the queue, there are two\n"
|
||||
"possibilities: if the socket has been configured as\n"
|
||||
"non-blocking, return @code{#f} directly. Otherwise wait\n"
|
||||
"until a connection is available. When a connection comes,\n"
|
||||
"the return value is a pair in which the @emph{car} is a new\n"
|
||||
"socket port for the connection and the @emph{cdr} is an\n"
|
||||
"object with address information about the client which\n"
|
||||
"initiated the connection.\n\n"
|
||||
"@var{sock} does not become part of the\n"
|
||||
"connection and will continue to accept new requests.")
|
||||
#define FUNC_NAME s_scm_accept
|
||||
|
@ -1262,7 +1261,11 @@ SCM_DEFINE (scm_accept, "accept", 1, 0, 0,
|
|||
fd = SCM_FPORT_FDES (sock);
|
||||
SCM_SYSCALL (newfd = accept (fd, (struct sockaddr *) &addr, &addr_size));
|
||||
if (newfd == -1)
|
||||
SCM_SYSERROR;
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
return SCM_BOOL_F;
|
||||
SCM_SYSERROR;
|
||||
}
|
||||
newsock = SCM_SOCK_FD_TO_PORT (newfd);
|
||||
address = _scm_from_sockaddr (&addr, addr_size,
|
||||
FUNC_NAME);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue