bug-gnulib
[Top][All Lists]
Advanced

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

sys_socket: use POSIX compatible prototypes


From: Bruno Haible
Subject: sys_socket: use POSIX compatible prototypes
Date: Sun, 7 Mar 2010 19:55:33 +0100
User-agent: KMail/1.9.9

Hi,

When testing the gnulib provided replacements against the POSIX specified
declarations, some socket functions show errors, due to different prototypes:

../gllib/sys/socket.h:408:[connect] error: invalid conversion from 'int 
(*)(int, const sockaddr*, socklen_t)' to 'int (*)(int, sockaddr*, int)'
../gllib/sys/socket.h:431:[accept] error: invalid conversion from 'int (*)(int, 
sockaddr*, socklen_t*)' to 'int (*)(int, sockaddr*, int*)'
../gllib/sys/socket.h:455:[bind] error: invalid conversion from 'int (*)(int, 
const sockaddr*, socklen_t)throw ()' to 'int (*)(int, sockaddr*, int)'
../gllib/sys/socket.h:481:[getpeername] error: invalid conversion from 'int 
(*)(int, sockaddr*, socklen_t*)throw ()' to 'int (*)(int, sockaddr*, int*)'
../gllib/sys/socket.h:508:[getsockname] error: invalid conversion from 'int 
(*)(int, sockaddr*, socklen_t*)throw ()' to 'int (*)(int, sockaddr*, int*)'
../gllib/sys/socket.h:583:[recv] error: invalid conversion from 'ssize_t 
(*)(int, void*, size_t, int)' to 'int (*)(int, void*, int, int)'
../gllib/sys/socket.h:607:[send] error: invalid conversion from 'ssize_t 
(*)(int, const void*, size_t, int)' to 'int (*)(int, const void*, int, int)'
../gllib/sys/socket.h:633:[recvfrom] error: invalid conversion from 'ssize_t 
(*)(int, void*, size_t, int, sockaddr*, socklen_t*)' to 'int (*)(int, void*, 
int, int, sockaddr*, int*)'
../gllib/sys/socket.h:660:[sendto] error: invalid conversion from 'ssize_t 
(*)(int, const void*, size_t, int, const sockaddr*, socklen_t)' to 'int 
(*)(int, const void*, int, int, sockaddr*, int)'

C++ programs will expect the POSIX prototype, even on mingw. On mingw,
the types are effectively the same (ssize_t = int, socklen_t = int), therefore
this should not introduce bugs (possibly some warnings, that can be ignored).


2010-03-07  Bruno Haible  <address@hidden>

        Use POSIX declarations for socket functions.
        * lib/sys_socket.in.h (rpl_connect, rpl_accept, rpl_bind,
        rpl_getpeername, rpl_getsockname, rpl_recv, rpl_send, rpl_recvfrom,
        rpl_sendto): Change declaration to match POSIX.
        * lib/connect.c (rpl_connect): Likewise.
        * lib/accept.c (rpl_accept): Likewise.
        * lib/bind.c (rpl_bind): Likewise.
        * lib/getpeername.c (rpl_getpeername): Likewise.
        * lib/getsockname.c (rpl_getsockname): Likewise.
        * lib/recv.c (rpl_recv): Likewise.
        * lib/send.c (rpl_send): Likewise.
        * lib/recvfrom.c (rpl_recvfrom): Likewise.
        * lib/sendto.c (rpl_sendto): Likewise.

--- lib/sys_socket.in.h.orig    Sun Mar  7 19:44:10 2010
+++ lib/sys_socket.in.h Sun Mar  7 19:42:16 2010
@@ -197,7 +197,8 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef connect
 #   define connect              rpl_connect
-extern int rpl_connect (int, struct sockaddr *, int) _GL_ARG_NONNULL ((2));
+extern int rpl_connect (int, const struct sockaddr *, socklen_t)
+     _GL_ARG_NONNULL ((2));
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef connect
@@ -214,7 +215,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef accept
 #   define accept               rpl_accept
-extern int rpl_accept (int, struct sockaddr *, int *);
+extern int rpl_accept (int, struct sockaddr *, socklen_t *);
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef accept
@@ -231,7 +232,8 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef bind
 #   define bind                 rpl_bind
-extern int rpl_bind (int, struct sockaddr *, int) _GL_ARG_NONNULL ((2));
+extern int rpl_bind (int, const struct sockaddr *, socklen_t)
+     _GL_ARG_NONNULL ((2));
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef bind
@@ -248,7 +250,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef getpeername
 #   define getpeername          rpl_getpeername
-extern int rpl_getpeername (int, struct sockaddr *, int *)
+extern int rpl_getpeername (int, struct sockaddr *, socklen_t *)
      _GL_ARG_NONNULL ((2, 3));
 #  endif
 # elif @HAVE_WINSOCK2_H@
@@ -266,7 +268,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef getsockname
 #   define getsockname          rpl_getsockname
-extern int rpl_getsockname (int, struct sockaddr *, int *)
+extern int rpl_getsockname (int, struct sockaddr *, socklen_t *)
      _GL_ARG_NONNULL ((2, 3));
 #  endif
 # elif @HAVE_WINSOCK2_H@
@@ -319,7 +321,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef recv
 #   define recv                 rpl_recv
-extern int rpl_recv (int, void *, int, int) _GL_ARG_NONNULL ((2));
+extern ssize_t rpl_recv (int, void *, size_t, int) _GL_ARG_NONNULL ((2));
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef recv
@@ -336,7 +338,7 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef send
 #   define send                 rpl_send
-extern int rpl_send (int, const void *, int, int) _GL_ARG_NONNULL ((2));
+extern ssize_t rpl_send (int, const void *, size_t, int) _GL_ARG_NONNULL ((2));
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef send
@@ -353,7 +355,8 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef recvfrom
 #   define recvfrom             rpl_recvfrom
-extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *)
+extern ssize_t rpl_recvfrom (int, void *, size_t, int,
+                             struct sockaddr *, socklen_t *)
      _GL_ARG_NONNULL ((2));
 #  endif
 # elif @HAVE_WINSOCK2_H@
@@ -371,7 +374,8 @@
 #  if @HAVE_WINSOCK2_H@
 #   undef sendto
 #   define sendto               rpl_sendto
-extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int)
+extern ssize_t rpl_sendto (int, const void *, size_t, int,
+                           const struct sockaddr *, socklen_t)
      _GL_ARG_NONNULL ((2));
 #  endif
 # elif @HAVE_WINSOCK2_H@
--- lib/accept.c.orig   Sun Mar  7 19:44:10 2010
+++ lib/accept.c        Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* accept.c --- wrappers for Windows accept function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -29,7 +29,7 @@
 #undef accept
 
 int
-rpl_accept (int fd, struct sockaddr *addr, int *addrlen)
+rpl_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
 {
   SOCKET fh = accept (FD_TO_SOCKET (fd), addr, addrlen);
   if (fh == INVALID_SOCKET)
--- lib/bind.c.orig     Sun Mar  7 19:44:10 2010
+++ lib/bind.c  Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* bind.c --- wrappers for Windows bind function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -29,7 +29,7 @@
 #undef bind
 
 int
-rpl_bind (int fd, struct sockaddr *sockaddr, int len)
+rpl_bind (int fd, const struct sockaddr *sockaddr, socklen_t len)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = bind (sock, sockaddr, len);
--- lib/connect.c.orig  Sun Mar  7 19:44:10 2010
+++ lib/connect.c       Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* connect.c --- wrappers for Windows connect function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -29,7 +29,7 @@
 #undef connect
 
 int
-rpl_connect (int fd, struct sockaddr *sockaddr, int len)
+rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = connect (sock, sockaddr, len);
--- lib/getpeername.c.orig      Sun Mar  7 19:44:10 2010
+++ lib/getpeername.c   Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* getpeername.c --- wrappers for Windows getpeername function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -29,7 +29,7 @@
 #undef getpeername
 
 int
-rpl_getpeername (int fd, struct sockaddr *addr, int *addrlen)
+rpl_getpeername (int fd, struct sockaddr *addr, socklen_t *addrlen)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = getpeername (sock, addr, addrlen);
--- lib/getsockname.c.orig      Sun Mar  7 19:44:10 2010
+++ lib/getsockname.c   Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* getsockname.c --- wrappers for Windows getsockname function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -29,7 +29,7 @@
 #undef getsockname
 
 int
-rpl_getsockname (int fd, struct sockaddr *addr, int *addrlen)
+rpl_getsockname (int fd, struct sockaddr *addr, socklen_t *addrlen)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = getsockname (sock, addr, addrlen);
--- lib/recv.c.orig     Sun Mar  7 19:44:10 2010
+++ lib/recv.c  Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* recv.c --- wrappers for Windows recv function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -28,8 +28,8 @@
 
 #undef recv
 
-int
-rpl_recv (int fd, void *buf, int len, int flags)
+ssize_t
+rpl_recv (int fd, void *buf, size_t len, int flags)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = recv (sock, buf, len, flags);
--- lib/recvfrom.c.orig Sun Mar  7 19:44:10 2010
+++ lib/recvfrom.c      Sun Mar  7 19:42:48 2010
@@ -28,9 +28,9 @@
 
 #undef recvfrom
 
-int
-rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
-              int *fromlen)
+ssize_t
+rpl_recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from,
+              socklen_t *fromlen)
 {
   int frombufsize = (from != NULL ? *fromlen : 0);
   SOCKET sock = FD_TO_SOCKET (fd);
--- lib/send.c.orig     Sun Mar  7 19:44:10 2010
+++ lib/send.c  Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* send.c --- wrappers for Windows send function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -28,8 +28,8 @@
 
 #undef send
 
-int
-rpl_send (int fd, const void *buf, int len, int flags)
+ssize_t
+rpl_send (int fd, const void *buf, size_t len, int flags)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = send (sock, buf, len, flags);
--- lib/sendto.c.orig   Sun Mar  7 19:44:10 2010
+++ lib/sendto.c        Sun Mar  7 19:42:48 2010
@@ -1,6 +1,6 @@
 /* sendto.c --- wrappers for Windows sendto function
 
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008-2010 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
@@ -28,9 +28,9 @@
 
 #undef sendto
 
-int
-rpl_sendto (int fd, const void *buf, int len, int flags,
-            struct sockaddr *to, int tolen)
+ssize_t
+rpl_sendto (int fd, const void *buf, size_t len, int flags,
+            const struct sockaddr *to, socklen_t tolen)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = sendto (sock, buf, len, flags, to, tolen);




reply via email to

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