bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] setsockopt: Add support for timeouts on W32


From: Bruno Haible
Subject: Re: [PATCH] setsockopt: Add support for timeouts on W32
Date: Fri, 26 Dec 2008 01:35:46 +0100
User-agent: KMail/1.9.9

Hello Martin,

Martin Lambers wrote:
> Here's an updated
> patch. I used memcpy() because POSIX requires silent truncation of the
> option value in case optlen is smaller than necessary. 

Looks all fine to me, but it's Simon and Paolo who have to decide on this.

> Is there a reason that the replacement getsockopt and setsockopt
> functions do not use the POSIX prototype (pointers with the 'restrict'
> keyword, length arguments with socklen_t)?

Good point. The prototypes should have socklen_t. Here is another proposed
patch, also for consideration by Simon and Paolo. - Regarding 'restrict',
I never use this keyword because AFAIK, omitting it has no effect on
correct programs; its presence is only a hint to the user that uses of
the functions with daring overlap of argument locations are invalid,
and in most cases a considerate programmer will not pass overlapping
arguments to functions anyway. - Please correct me if I'm wrong.

This patch is tested on mingw.

2008-12-25  Bruno Haible  <address@hidden>

        Use socklen_t in the native Windows replacements prototypes.
        * lib/sys_socket.in.h (rpl_getsockopt, rpl_setsockopt): Use socklen_t
        instead of 'int'.
        * lib/getsockopt.c (rpl_getsockopt): Likewise.
        * lib/setsockopt.c (rpl_setsockopt): Likewise.
        * modules/getsockopt (Depends-on): Add socklen.
        * modules/setsockopt (Depends-on): Add socklen.

--- lib/sys_socket.in.h.orig    2008-12-26 01:23:23.000000000 +0100
+++ lib/sys_socket.in.h 2008-12-26 01:01:14.000000000 +0100
@@ -256,7 +256,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef getsockopt
 #   define getsockopt          rpl_getsockopt
-extern int rpl_getsockopt (int, int, int, void *, int *);
+extern int rpl_getsockopt (int, int, int, void *, socklen_t *);
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef getsockopt
@@ -358,7 +358,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef setsockopt
 #   define setsockopt          rpl_setsockopt
-extern int rpl_setsockopt (int, int, int, const void *, int);
+extern int rpl_setsockopt (int, int, int, const void *, socklen_t);
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef setsockopt
--- lib/getsockopt.c.orig       2008-12-26 01:23:23.000000000 +0100
+++ lib/getsockopt.c    2008-12-26 01:01:48.000000000 +0100
@@ -29,7 +29,7 @@
 #undef getsockopt
 
 int
-rpl_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
+rpl_getsockopt (int fd, int level, int optname, void *optval, socklen_t 
*optlen)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = getsockopt (sock, level, optname, optval, optlen);
--- lib/setsockopt.c.orig       2008-12-26 01:23:23.000000000 +0100
+++ lib/setsockopt.c    2008-12-26 01:02:03.000000000 +0100
@@ -29,7 +29,7 @@
 #undef setsockopt
 
 int
-rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen)
+rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t 
optlen)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = setsockopt (sock, level, optname, optval, optlen);
--- modules/getsockopt.orig     2008-12-26 01:23:23.000000000 +0100
+++ modules/getsockopt  2008-12-26 01:04:07.000000000 +0100
@@ -7,6 +7,7 @@
 
 Depends-on:
 sys_socket
+socklen
 errno
 
 configure.ac:
--- modules/setsockopt.orig     2008-12-26 01:23:23.000000000 +0100
+++ modules/setsockopt  2008-12-26 01:04:07.000000000 +0100
@@ -7,6 +7,7 @@
 
 Depends-on:
 sys_socket
+socklen
 errno
 
 configure.ac:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]