Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tarot
gnulib
Commits
e8c71d94
Commit
e8c71d94
authored
Aug 25, 2009
by
Bruno Haible
Browse files
New module 'accept4'.
parent
9cedf3e1
Changes
8
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
e8c71d94
2009-08-23 Bruno Haible <bruno@clisp.org>
New module 'accept4'.
* lib/sys_socket.in.h (accept4): New declaration.
* lib/accept4.c: New file.
* m4/accept4.m4: New file.
* m4/sys_socket_h.m4 (gl_SYS_SOCKET_H_DEFAULTS): Initialize
GNULIB_ACCEPT4, HAVE_ACCEPT4.
* modules/sys_socket (Makefile.am): Substitute GNULIB_ACCEPT4,
HAVE_ACCEPT4.
* modules/accept4: New file.
* doc/glibc-functions/accept4.texi: Mention the new module.
2009-08-24 Jim Meyering <meyering@redhat.com>
progname: also set global program_invocation_name, when possible
doc/glibc-functions/accept4.texi
View file @
e8c71d94
...
...
@@ -2,15 +2,15 @@
@subsection @code{accept4}
@findex accept4
Gnulib module:
---
Gnulib module:
accept4
Portability problems fixed by Gnulib:
@itemize
@item
This function is missing on all non-glibc platforms:
MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
This function is missing on all non-glibc platforms:
MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS.
@end itemize
lib/accept4.c
0 → 100644
View file @
e8c71d94
/* Accept a connection on a socket, with specific opening flags.
Copyright (C) 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include "binary-io.h"
#ifndef SOCK_CLOEXEC
# define SOCK_CLOEXEC 0
#endif
int
accept4
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
int
flags
)
{
int
fd
;
/* Check the supported flags. */
if
((
flags
&
~
(
SOCK_CLOEXEC
|
O_TEXT
|
O_BINARY
))
!=
0
)
{
errno
=
EINVAL
;
return
-
1
;
}
fd
=
accept
(
sockfd
,
addr
,
addrlen
);
if
(
fd
<
0
)
return
-
1
;
#if SOCK_CLOEXEC
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Native Woe32 API. */
if
(
flags
&
SOCK_CLOEXEC
)
{
HANDLE
curr_process
=
GetCurrentProcess
();
HANDLE
old_handle
=
(
HANDLE
)
_get_osfhandle
(
fd
);
HANDLE
new_handle
;
int
nfd
;
if
(
!
DuplicateHandle
(
curr_process
,
/* SourceProcessHandle */
old_handle
,
/* SourceHandle */
curr_process
,
/* TargetProcessHandle */
(
PHANDLE
)
&
new_handle
,
/* TargetHandle */
(
DWORD
)
0
,
/* DesiredAccess */
FALSE
,
/* InheritHandle */
DUPLICATE_SAME_ACCESS
))
/* Options */
{
close
(
fd
);
errno
=
EBADF
;
/* arbitrary */
return
-
1
;
}
/* Closing fd before allocating the new fd ensures that the new fd will
have the minimum possible value. */
close
(
fd
);
nfd
=
_open_osfhandle
((
long
)
new_handle
,
O_NOINHERIT
|
(
flags
&
(
O_TEXT
|
O_BINARY
)));
if
(
nfd
<
0
)
{
CloseHandle
(
new_handle
);
return
-
1
;
}
return
nfd
;
}
# else
/* Unix API. */
if
(
flags
&
SOCK_CLOEXEC
)
{
int
fcntl_flags
;
if
((
fcntl_flags
=
fcntl
(
fd
,
F_GETFD
,
0
))
<
0
||
fcntl
(
fd
,
F_SETFD
,
fcntl_flags
|
FD_CLOEXEC
)
==
-
1
)
{
int
saved_errno
=
errno
;
close
(
fd
);
errno
=
saved_errno
;
return
-
1
;
}
}
# endif
#endif
#if O_BINARY
if
(
flags
&
O_BINARY
)
setmode
(
fd
,
O_BINARY
);
else
if
(
flags
&
O_TEXT
)
setmode
(
fd
,
O_TEXT
);
#endif
return
fd
;
}
lib/sys_socket.in.h
View file @
e8c71d94
...
...
@@ -423,5 +423,31 @@ extern int rpl_shutdown (int, int);
#endif
/* HAVE_SYS_SOCKET_H */
#ifdef __cplusplus
extern
"C"
{
#endif
#if @GNULIB_ACCEPT4@
# if !@HAVE_ACCEPT4@
/* Accept a connection on a socket, with specific opening flags.
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
and O_TEXT, O_BINARY (defined in "binary-io.h").
See also the Linux man page at
<http://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */
extern
int
accept4
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
int
flags
);
# endif
#elif defined GNULIB_POSIXCHECK
# undef accept4
# define accept4(s,a,l,f) \
(GL_LINK_WARNING ("accept4 is unportable - " \
"use gnulib module accept4 for portability"), \
accept4 (s, a, l, f))
#endif
#ifdef __cplusplus
}
#endif
#endif
/* _GL_SYS_SOCKET_H */
#endif
/* _GL_SYS_SOCKET_H */
m4/accept4.m4
0 → 100644
View file @
e8c71d94
# accept4.m4 serial 1
dnl Copyright (C) 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_ACCEPT4],
[
AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
dnl Persuade glibc <sys/socket.h> to declare accept4().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
AC_CHECK_FUNCS_ONCE([accept4])
if test $ac_cv_func_accept4 != yes; then
HAVE_ACCEPT4=0
AC_LIBOBJ([accept4])
fi
])
m4/sys_socket_h.m4
View file @
e8c71d94
# sys_socket_h.m4 serial 1
2
# sys_socket_h.m4 serial 1
3
dnl Copyright (C) 2005-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
...
...
@@ -140,6 +140,8 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
])
modules/accept4
0 → 100644
View file @
e8c71d94
Description:
accept4() function: accept a connection on a socket, with specific opening
flags.
Files:
lib/accept4.c
m4/accept4.m4
Depends-on:
sys_socket
accept
fcntl
binary-io
configure.ac:
gl_FUNC_ACCEPT4
gl_SYS_SOCKET_MODULE_INDICATOR([accept4])
Makefile.am:
Include:
<sys/socket.h>
License:
LGPL
Maintainer:
Bruno Haible, Simon Josefsson
modules/sys_socket
View file @
e8c71d94
...
...
@@ -44,10 +44,12 @@ sys/socket.h: sys_socket.in.h
-e 's|@''GNULIB_SENDTO''@|$(GNULIB_SENDTO)|g' \
-e 's|@''GNULIB_SETSOCKOPT''@|$(GNULIB_SETSOCKOPT)|g' \
-e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \
-e 's|@''GNULIB_ACCEPT4''@|$(GNULIB_ACCEPT4)|g' \
-e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
-e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
-e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
-e 's|@''HAVE_SA_FAMILY_T''@|$(HAVE_SA_FAMILY_T)|g' \
-e 's|@''HAVE_ACCEPT4''@|$(HAVE_ACCEPT4)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
< $(srcdir)/sys_socket.in.h; \
} > $@-t && \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment