[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
test-poll vs ioctl
From: |
Simon Josefsson |
Subject: |
test-poll vs ioctl |
Date: |
Mon, 20 Oct 2008 16:44:41 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> This defines a module for the 'ioctl' function, and moves its declaration
> from <sys/socket.h> to <sys/ioctl.h>.
The poll-tests module uses sys/ioctl.h and ioctl, even though poll
doesn't need them, so I added these modules to the poll-tests module
dependencies.
However that doesn't seem to work. Here is what happens:
gnulib-tool --import adds the sys_ioctl module to $gltests/ which
appears correct, but things won't build because winsock.c in $gl/ tries
to include sys/ioctl.h:
#if GNULIB_IOCTL
#include <sys/ioctl.h>
#endif
There is no -I for the $gltests/ directory in $gl/, so this fails.
I think the ioctl replacement function should be moved out from
winsock.c to a new ioctl.c.
What do you think of the patch below?
There is some code duplication. Maybe we should add gl_fd_to_socket and
gl_set_winsock_errno to the sockets module, to be able to use them from
everywhere. Thoughts?
/Simon
>From d2a6f36cac7939d3f9c0a395d67db0d2fbeac9e4 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Mon, 20 Oct 2008 16:41:27 +0200
Subject: [PATCH] Make test-poll module work.
* modules/poll-tests (Depends-on): Add sys_ioctl and ioctl.
* modules/ioctl (Files): Replace winsock.c with ioctl.c.
(configure.ac): Run AC_LIBOBJ([ioctl]) instead of
AC_LIBOBJ([winsock]).
* lib/winsock.c: Move ioctl related code from winsock.c to ioctl.c.
* lib/ioctl.c: Likewise.
---
ChangeLog | 9 +++++
lib/ioctl.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/winsock.c | 25 ---------------
modules/ioctl | 4 +-
modules/poll-tests | 2 +
5 files changed, 96 insertions(+), 27 deletions(-)
create mode 100644 lib/ioctl.c
diff --git a/ChangeLog b/ChangeLog
index 2cf7e62..bac19f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-10-20 Simon Josefsson <address@hidden>
+
+ * modules/poll-tests (Depends-on): Add sys_ioctl and ioctl.
+ * modules/ioctl (Files): Replace winsock.c with ioctl.c.
+ (configure.ac): Run AC_LIBOBJ([ioctl]) instead of
+ AC_LIBOBJ([winsock]).
+ * lib/winsock.c: Move ioctl related code from winsock.c to ioctl.c.
+ * lib/ioctl.c: Likewise.
+
2008-10-20 Bruno Haible <address@hidden>
* m4/posix_spawn.m4 (gl_POSIX_SPAWN_WORKS): Test against another bug
diff --git a/lib/ioctl.c b/lib/ioctl.c
new file mode 100644
index 0000000..a8edbc1
--- /dev/null
+++ b/lib/ioctl.c
@@ -0,0 +1,83 @@
+/* ioctl.c --- wrappers for Windows socket ioctl function
+
+ Copyright (C) 2008 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <io.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd)))
+
+static inline void
+set_winsock_errno (void)
+{
+ int err = WSAGetLastError ();
+ WSASetLastError (0);
+
+ /* Map some WSAE* errors to the runtime library's error codes. */
+ switch (err)
+ {
+ case WSA_INVALID_HANDLE:
+ errno = EBADF;
+ break;
+ case WSA_NOT_ENOUGH_MEMORY:
+ errno = ENOMEM;
+ break;
+ case WSA_INVALID_PARAMETER:
+ errno = EINVAL;
+ break;
+ case WSAEWOULDBLOCK:
+ errno = EWOULDBLOCK;
+ break;
+ case WSAENAMETOOLONG:
+ errno = ENAMETOOLONG;
+ break;
+ case WSAENOTEMPTY:
+ errno = ENOTEMPTY;
+ break;
+ default:
+ errno = (err > 10000 && err < 10025) ? err - 10000 : err;
+ break;
+ }
+}
+
+int
+rpl_ioctl (int fd, int req, ...)
+{
+ void *buf;
+ va_list args;
+ SOCKET sock;
+ int r;
+
+ va_start (args, req);
+ buf = va_arg (args, void *);
+ va_end (args);
+
+ sock = FD_TO_SOCKET (fd);
+ r = ioctlsocket (sock, req, buf);
+ if (r < 0)
+ set_winsock_errno ();
+
+ return r;
+}
diff --git a/lib/winsock.c b/lib/winsock.c
index 979360b..f90ce66 100644
--- a/lib/winsock.c
+++ b/lib/winsock.c
@@ -25,9 +25,6 @@
#include <fcntl.h>
#include <io.h>
#include <sys/socket.h>
-#if GNULIB_IOCTL
-#include <sys/ioctl.h>
-#endif
#undef socket
#undef connect
@@ -238,28 +235,6 @@ rpl_listen (int fd, int backlog)
}
#endif
-#if GNULIB_IOCTL
-int
-rpl_ioctl (int fd, int req, ...)
-{
- void *buf;
- va_list args;
- SOCKET sock;
- int r;
-
- va_start (args, req);
- buf = va_arg (args, void *);
- va_end (args);
-
- sock = FD_TO_SOCKET (fd);
- r = ioctlsocket (sock, req, buf);
- if (r < 0)
- set_winsock_errno ();
-
- return r;
-}
-#endif
-
#if GNULIB_RECV
int
rpl_recv (int fd, void *buf, int len, int flags)
diff --git a/modules/ioctl b/modules/ioctl
index b425dee..867b676 100644
--- a/modules/ioctl
+++ b/modules/ioctl
@@ -2,7 +2,7 @@ Description:
ioctl() function: issue device specific requests on files, devices, or sockets.
Files:
-lib/winsock.c
+lib/ioctl.c
Depends-on:
sys_ioctl
@@ -12,7 +12,7 @@ errno
configure.ac:
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
- AC_LIBOBJ([winsock])
+ AC_LIBOBJ([ioctl])
gl_REPLACE_SYS_IOCTL_H
fi
gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
diff --git a/modules/poll-tests b/modules/poll-tests
index 403287c..b21db80 100644
--- a/modules/poll-tests
+++ b/modules/poll-tests
@@ -18,6 +18,8 @@ listen
connect
accept
close
+sys_ioctl
+ioctl
configure.ac:
AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
--
1.5.6.5
- new module 'ioctl', Bruno Haible, 2008/10/09
- Re: new module 'ioctl', Paolo Bonzini, 2008/10/10
- test-poll vs ioctl,
Simon Josefsson <=
- Re: test-poll vs ioctl, Paolo Bonzini, 2008/10/20
- Re: test-poll vs ioctl, Simon Josefsson, 2008/10/20
- Re: test-poll vs ioctl, Bruno Haible, 2008/10/20
- Re: test-poll vs ioctl, Paolo Bonzini, 2008/10/20
- Re: test-poll vs ioctl, Simon Josefsson, 2008/10/21
- winsock.c split, Simon Josefsson, 2008/10/21
- Re: winsock.c split, Bruno Haible, 2008/10/21
- Re: winsock.c split, Simon Josefsson, 2008/10/21
- Re: winsock.c split, Simon Josefsson, 2008/10/21
- Re: winsock.c split, Bruno Haible, 2008/10/25