From 82c3f0ba7258e480d2f1e8c2458bf8a6131c8689 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Aug 2009 14:07:05 +0200 Subject: [PATCH] introducing libssh2_socket_t type and fixed iovec for windows Steven Van Ingelgem introduces libssh2_socket_t as a generic socket type to use internally to avoid compiler warnings and mistakes. Also, the private struct iovec declaration for windows is now made to look like the POSIX struct does. --- src/libssh2_priv.h | 17 +++++++++++------ src/misc.c | 4 ++-- src/session.c | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 7b9abad..d845d28 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -97,10 +97,9 @@ /* Provide iovec / writev on WIN32 platform. */ #ifdef WIN32 -/* same as WSABUF */ struct iovec { - u_long iov_len; - char *iov_base; + size_t iov_len; + void * iov_base; }; #define inline __inline @@ -150,6 +149,12 @@ static inline int writev(int sock, struct iovec *iov, int nvecs) #endif +#ifdef WIN32 +typedef SOCKET libssh2_socket_t; +#else /* !WIN32 */ +typedef int libssh2_socket_t; +#endif /* WIN32 */ + /* RFC4253 section 6.1 Maximum Packet Length says: * * "All implementations MUST be able to process packets with @@ -716,7 +721,7 @@ struct _LIBSSH2_SESSION struct list_head listeners; /* list of LIBSSH2_LISTENER structs */ /* Actual I/O socket */ - int socket_fd; + libssh2_socket_t socket_fd; int socket_state; int socket_block_directions; int socket_prev_blockstate; /* stores the state of the socket blockiness @@ -1136,8 +1141,8 @@ libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf); void _libssh2_htonu32(unsigned char *buf, unsigned int val); #ifdef WIN32 -ssize_t _libssh2_recv(int socket, void *buffer, size_t length, int flags); -ssize_t _libssh2_send(int socket, const void *buffer, size_t length, int flags); +ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags); +ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags); #else #define _libssh2_recv(a,b,c,d) recv(a,b,c,d) #define _libssh2_send(a,b,c,d) send(a,b,c,d) diff --git a/src/misc.c b/src/misc.c index adf2b0b..665f51a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -78,7 +78,7 @@ static int wsa2errno(void) * to set errno */ ssize_t -_libssh2_recv(int socket, void *buffer, size_t length, int flags) +_libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags) { ssize_t rc = recv(socket, buffer, length, flags); #ifdef WIN32 @@ -97,7 +97,7 @@ _libssh2_recv(int socket, void *buffer, size_t length, int flags) * to set errno */ ssize_t -_libssh2_send(int socket, const void *buffer, size_t length, int flags) +_libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags) { ssize_t rc = send(socket, buffer, length, flags); #ifdef WIN32 diff --git a/src/session.c b/src/session.c index 158a854..40a1eaf 100644 --- a/src/session.c +++ b/src/session.c @@ -1349,7 +1349,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) } #elif defined(HAVE_SELECT) LIBSSH2_SESSION *session = NULL; - int maxfd = 0; + libssh2_socket_t maxfd = 0; fd_set rfds, wfds; struct timeval tv;