@@ -22,7 +22,6 @@ using socklen_t = int32_t;
2222using ssize_t = signed long long int ;
2323#else
2424// headers
25- #include " error.hpp"
2625#include < arpa/inet.h>
2726#include < chrono>
2827#include < fcntl.h>
@@ -39,6 +38,14 @@ using socket_t = int32_t;
3938
4039namespace netlib {
4140
41+ static std::error_condition socket_get_last_error (){
42+ #ifdef _WIN32
43+ return WASGetLastError ();
44+ #else
45+ return std::make_error_condition (static_cast <std::errc>(errno));
46+ #endif
47+ }
48+
4249 enum class AddressFamily {IPv4 = AF_INET, IPv6 = AF_INET6, unspecified = AF_UNSPEC};
4350 enum class AddressProtocol {TCP = SOCK_STREAM, UDP = SOCK_DGRAM};
4451 enum class OperationClass {read = 1 , write = 2 , both = 3 };
@@ -72,8 +79,8 @@ namespace netlib {
7279
7380 bool set_nonblocking (bool nonblocking = true ) {
7481#ifdef _WIN32
75- uint32_t mode = static_cast <uint32_t >(nonblocking);
76- return ioctlsocket (sockfd , FIONBIO, &mode) == 0 ;
82+ u_long mode = static_cast <u_long >(nonblocking);
83+ return ioctlsocket (_socket. value () , FIONBIO, &mode) == 0 ;
7784#else
7885 return fcntl (_socket.value (), F_SETFL, fcntl (_socket.value (), F_GETFL, 0 ) | (nonblocking ? O_NONBLOCK : 0 )) == 0 ;
7986#endif
@@ -82,7 +89,7 @@ namespace netlib {
8289 bool set_reuseaddr (bool reuseaddr = true ){
8390#ifdef _WIN32
8491 int32_t val = static_cast <int32_t >(reuseaddr);
85- return setsockopt (sock , SOL_SOCKET, SO_REUSEADDR,
92+ return setsockopt (_socket. value () , SOL_SOCKET, SO_REUSEADDR,
8693 reinterpret_cast <char *>(&val), sizeof (val)) == 0 ;
8794#else
8895 auto mode = static_cast <int32_t >(reuseaddr);
@@ -107,7 +114,7 @@ namespace netlib {
107114 void close () {
108115 if (_socket) {
109116#ifdef _WIN32
110- closesocket (sockfd );
117+ closesocket (_socket. value () );
111118#else
112119 ::close (_socket.value());
113120#endif
0 commit comments