diff options
author | Andy Wingo <wingo@pobox.com> | 2012-02-08 20:11:28 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-02-14 22:47:15 +0100 |
commit | d7bbda6fd7b79917bd963f6c156c8539414a35f8 (patch) | |
tree | 9e607b7a76b4d866bfa210c43907ccf99c9f11bf | |
parent | f503c1d6be378c3351b7011b07c4fa32230698f1 (diff) | |
download | guile-d7bbda6fd7b79917bd963f6c156c8539414a35f8.tar.gz |
optional flags arg to scm_accept, which uses accept4
* libguile/socket.c (scm_accept): Take another argument, "flags". This
dispatches to accept4, if it's available, to possibly set the CLOEXEC
flag on the accepted port.
-rw-r--r-- | libguile/socket.c | 18 | ||||
-rw-r--r-- | libguile/socket.h | 4 |
2 files changed, 16 insertions, 6 deletions
diff --git a/libguile/socket.c b/libguile/socket.c index 149ec005f..33309cd45 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -1,5 +1,5 @@ /* Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, - * 2006, 2007, 2009, 2011 Free Software Foundation, Inc. + * 2006, 2007, 2009, 2011, 2012 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -20,6 +20,8 @@ +#define _GNU_SOURCE /* accept4 */ + #ifdef HAVE_CONFIG_H # include <config.h> #endif @@ -1299,8 +1301,8 @@ SCM_DEFINE (scm_make_socket_address, "make-socket-address", 2, 0, 1, #undef FUNC_NAME -SCM_DEFINE (scm_accept, "accept", 1, 0, 0, - (SCM sock), +SCM_DEFINE (scm_accept, "accept", 1, 1, 0, + (SCM sock, SCM flags), "Accept a connection on a bound, listening socket.\n" "If there\n" "are no pending connections in the queue, wait until\n" @@ -1316,6 +1318,7 @@ SCM_DEFINE (scm_accept, "accept", 1, 0, 0, #define FUNC_NAME s_scm_accept { int fd; + int fd_flags; int newfd; SCM address; SCM newsock; @@ -1325,7 +1328,8 @@ SCM_DEFINE (scm_accept, "accept", 1, 0, 0, sock = SCM_COERCE_OUTPORT (sock); SCM_VALIDATE_OPFPORT (1, sock); fd = SCM_FPORT_FDES (sock); - newfd = accept (fd, (struct sockaddr *) &addr, &addr_size); + fd_flags = SCM_UNBNDP (flags) ? 0 : scm_to_int (flags); + newfd = accept4 (fd, (struct sockaddr *) &addr, &addr_size, fd_flags); if (newfd == -1) SCM_SYSERROR; newsock = SCM_SOCK_FD_TO_PORT (newfd); @@ -1696,6 +1700,12 @@ scm_init_socket () #ifdef SOCK_RDM scm_c_define ("SOCK_RDM", scm_from_int (SOCK_RDM)); #endif +#ifdef SOCK_RDM + scm_c_define ("SOCK_NONBLOCK", scm_from_int (SOCK_NONBLOCK)); +#endif +#ifdef SOCK_CLOEXEC + scm_c_define ("SOCK_CLOEXEC", scm_from_int (SOCK_CLOEXEC)); +#endif /* setsockopt level. diff --git a/libguile/socket.h b/libguile/socket.h index fcddd780d..bdd9f01da 100644 --- a/libguile/socket.h +++ b/libguile/socket.h @@ -3,7 +3,7 @@ #ifndef SCM_SOCKET_H #define SCM_SOCKET_H -/* Copyright (C) 1995,1996,1997,2000,2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,2000,2001, 2004, 2005, 2006, 2008, 2012 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -46,7 +46,7 @@ SCM_API SCM scm_shutdown (SCM sfd, SCM how); SCM_API SCM scm_connect (SCM sockfd, SCM fam, SCM address, SCM args); SCM_API SCM scm_bind (SCM sockfd, SCM fam, SCM address, SCM args); SCM_API SCM scm_listen (SCM sfd, SCM backlog); -SCM_API SCM scm_accept (SCM sockfd); +SCM_API SCM scm_accept (SCM sockfd, SCM flags); SCM_API SCM scm_getsockname (SCM sockfd); SCM_API SCM scm_getpeername (SCM sockfd); SCM_API SCM scm_recv (SCM sockfd, SCM buff_or_size, SCM flags); |