1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-21 14:00:51 +03:00

- (Mar 19 2009) Daniel Stenberg: based on a patch by "E L" we now use errno

properly after recv() and send() calls (that internally are now known as
  _libssh2_recv() and _libssh2_send()) so that the API and more works fine on
  windows too!
This commit is contained in:
Daniel Stenberg
2009-03-19 12:45:59 +00:00
parent 563f627647
commit 468272d648
5 changed files with 96 additions and 66 deletions

View File

@@ -45,6 +45,71 @@
#include <sys/time.h>
#endif
#include <errno.h>
#ifdef WIN32
static int wsa2errno(void)
{
switch (WSAGetLastError()) {
case WSAEWOULDBLOCK:
return EAGAIN;
case WSAENOTSOCK:
return EBADF;
case WSAENOTCONN:
case WSAECONNABORTED:
return ENOTCONN;
case WSAEINTR:
return EINTR;
default:
/* It is most important to ensure errno does not stay at EAGAIN
* when a different error occurs so just set errno to a generic
* error */
return EIO;
}
}
#endif
#ifndef _libssh2_recv
/* _libssh2_recv
*
* Wrapper around standard recv to allow WIN32 systems
* to set errno
*/
ssize_t
_libssh2_recv(int socket, void *buffer, size_t length, int flags)
{
ssize_t rc = recv(socket, buffer, length, flags);
#ifdef WIN32
if (rc < 0 )
errno = wsa2errno();
#endif
return rc;
}
#endif /* _libssh2_recv */
#ifndef _libssh2_send
/* _libssh2_send
*
* Wrapper around standard send to allow WIN32 systems
* to set errno
*/
ssize_t
_libssh2_send(int socket, const void *buffer, size_t length, int flags)
{
ssize_t rc = send(socket, buffer, length, flags);
#ifdef WIN32
if (rc < 0 )
errno = wsa2errno();
#endif
return rc;
}
#endif /* _libssh2_recv */
/* libssh2_ntohu32
*/
unsigned long