mudgangster

Log | Files | Refs

commit 64602479bfe215b4f1fa4cafacd26b9dbca9e3d8
parent 8e8d6068659aeb9d8e68a6667dfe43038c4bf065
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat,  8 Sep 2018 17:52:50 +0300

Windows connection error strings

Diffstat:
src/platform_network.cc | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/platform_network.cc b/src/platform_network.cc @@ -78,6 +78,11 @@ static void setsockoptone( PlatformSocket fd, int level, int opt ) { } } +#if PLATFORM_WINDOWS +// TODO: horrible +char last_error_str[ 1024 ]; +#endif + bool net_new_tcp( TCPSocket * sock, const NetAddress & addr, const char ** err ) { struct sockaddr_storage ss = netaddress_to_sockaddr( addr ); socklen_t ss_size = sockaddr_size( ss ); @@ -91,7 +96,17 @@ bool net_new_tcp( TCPSocket * sock, const NetAddress & addr, const char ** err ) int ok_close = closesocket( sock->fd ); if( ok_close == -1 ) FATAL( "closesocket" ); - *err = strerror( errno ); + if( err != NULL ) { +#if PLATFORM_WINDOWS + int error = GetLastError(); + FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, + MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), last_error_str, sizeof( last_error_str ), NULL ); + + *err = last_error_str; +#else + *err = strerror( errno ); +#endif + } // TODO: check for actual coding errors too return false; }