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:
65
src/misc.c
65
src/misc.c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user