1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-20 02:42:09 +03:00

send/recv: use _libssh2_recv and _libssh2_send now

Starting now, we unconditionally use the internal replacement functions
for send() and recv() - creatively named _libssh2_recv() and
_libssh2_send().

On errors, these functions return the negative 'errno' value instead of
the traditional -1. This design allows systems that have no "natural"
errno support to not have to invent it. It also means that no code
outside of these two transfer functions should use the errno variable.
This commit is contained in:
Daniel Stenberg
2010-11-12 21:53:35 +01:00
parent aff9c825c8
commit ca2e81eb1f
6 changed files with 58 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
/* Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* Copyright (c) 2009-2010 by Daniel Stenberg
* Copyright (c) 2010 Simon Josefsson
* All rights reserved.
*
@@ -89,53 +89,56 @@ static int wsa2errno(void)
}
#endif
#ifndef _libssh2_recv
/* _libssh2_recv
*
* Wrapper around standard recv to allow WIN32 systems
* to set errno
* Replacement for the standard recv, return -errno on failure.
*/
ssize_t
_libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags)
_libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, int flags)
{
ssize_t rc = recv(socket, buffer, length, flags);
ssize_t rc = recv(sock, buffer, length, flags);
#ifdef WIN32
if (rc < 0 )
errno = wsa2errno();
#endif
#ifdef __VMS
return -wsa2errno();
#elsif defined(__VMS)
if (rc < 0 ){
if ( errno == EWOULDBLOCK ) errno = EAGAIN;
if ( errno == EWOULDBLOCK )
return -EAGAIN;
else
return -errno;
}
#else
if (rc < 0 )
return -errno;
#endif
return rc;
}
#endif /* _libssh2_recv */
#ifndef _libssh2_send
/* _libssh2_send
*
* Wrapper around standard send to allow WIN32 systems
* to set errno
* Replacement for the standard send, return -errno on failure.
*/
ssize_t
_libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length,
_libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length,
int flags)
{
ssize_t rc = send(socket, buffer, length, flags);
ssize_t rc = send(sock, buffer, length, flags);
#ifdef WIN32
if (rc < 0 )
errno = wsa2errno();
#endif
#ifdef VMS
if (rc < 0 ){
if ( errno == EWOULDBLOCK ) errno = EAGAIN;
return -wsa2errno();
#elsif defined(__VMS)
if (rc < 0 ) {
if ( errno == EWOULDBLOCK )
return -EAGAIN;
else
return -errno;
}
#else
if (rc < 0 )
return -errno;
#endif
return rc;
}
#endif /* _libssh2_recv */
/* libssh2_ntohu32
*/