1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

add portable LIBSSH2_SOCKET_CLOSE() macro

Add `LIBSSH2_SOCKET_CLOSE()` to the public `libssh2.h` header, for user
code. It translates to `closesocket()` on Windows and `close()` on other
platforms.

Use it in example code.

It makes them more readable by reducing the number of `_WIN32` guards.

Closes #1278
This commit is contained in:
Viktor Szakats
2023-12-08 02:22:48 +00:00
parent 46333adfb8
commit 28dbf01667
25 changed files with 36 additions and 138 deletions

View File

@ -313,20 +313,12 @@ shutdown:
if(forwardsock != LIBSSH2_INVALID_SOCKET) {
shutdown(forwardsock, 2);
#ifdef _WIN32
closesocket(forwardsock);
#else
close(forwardsock);
#endif
LIBSSH2_SOCKET_CLOSE(forwardsock);
}
if(listensock != LIBSSH2_INVALID_SOCKET) {
shutdown(listensock, 2);
#ifdef _WIN32
closesocket(listensock);
#else
close(listensock);
#endif
LIBSSH2_SOCKET_CLOSE(listensock);
}
if(channel)
@ -339,11 +331,7 @@ shutdown:
if(sock != LIBSSH2_INVALID_SOCKET) {
shutdown(sock, 2);
#ifdef _WIN32
closesocket(sock);
#else
close(sock);
#endif
LIBSSH2_SOCKET_CLOSE(sock);
}
libssh2_exit();