commit 8e8d6068659aeb9d8e68a6667dfe43038c4bf065
parent 694303b3fd17bf2fbf4def1cd5bff624d5090e02
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sat, 8 Sep 2018 17:47:41 +0300
Better error message when you can't connect
Diffstat:
4 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/platform_network.cc b/src/platform_network.cc
@@ -78,21 +78,20 @@ static void setsockoptone( PlatformSocket fd, int level, int opt ) {
}
}
-bool net_new_tcp( TCPSocket * sock, const NetAddress & addr ) {
+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 );
sock->fd = socket( ss.ss_family, SOCK_STREAM, IPPROTO_TCP );
- if( sock->fd == INVALID_SOCKET ) {
+ if( sock->fd == INVALID_SOCKET )
FATAL( "socket" );
- }
int ok = connect( sock->fd, ( const sockaddr * ) &ss, ss_size );
if( ok == -1 ) {
int ok_close = closesocket( sock->fd );
- if( ok_close == -1 ) {
+ if( ok_close == -1 )
FATAL( "closesocket" );
- }
+ *err = strerror( errno );
// TODO: check for actual coding errors too
return false;
}
diff --git a/src/platform_network.h b/src/platform_network.h
@@ -42,7 +42,7 @@ bool operator!=( const NetAddress & lhs, const NetAddress & rhs );
void net_init();
void net_term();
-bool net_new_tcp( TCPSocket * sock, const NetAddress & addr );
+bool net_new_tcp( TCPSocket * sock, const NetAddress & addr, const char ** err );
bool net_send( TCPSocket sock, const void * data, size_t len );
TCPRecvResult net_recv( TCPSocket sock, void * buf, size_t buf_size, size_t * bytes_read );
void net_destroy( TCPSocket * sock );
diff --git a/src/win32.cc b/src/win32.cc
@@ -58,11 +58,9 @@ void * platform_connect( const char ** err, const char * host, int port ) {
addr.port = checked_cast< u16 >( port );
TCPSocket sock;
- bool ok = net_new_tcp( &sock, addr );
- if( !ok ) {
- *err = "net_new_tcp";
+ bool ok = net_new_tcp( &sock, addr, err );
+ if( !ok )
return NULL;
- }
sockets[ idx ].sock = sock;
sockets[ idx ].in_use = true;
diff --git a/src/x11.cc b/src/x11.cc
@@ -51,11 +51,9 @@ void * platform_connect( const char ** err, const char * host, int port ) {
addr.port = checked_cast< u16 >( port );
TCPSocket sock;
- bool ok = net_new_tcp( &sock, addr );
- if( !ok ) {
- *err = "net_new_tcp";
+ bool ok = net_new_tcp( &sock, addr, err );
+ if( !ok )
return NULL;
- }
sockets[ idx ].sock = sock;
sockets[ idx ].in_use = true;
@@ -547,6 +545,10 @@ bool ui_set_font( const char * name, int size ) {
return false;
}
+void platform_set_clipboard( const char * str, size_t len ) {
+ // TODO
+}
+
void platform_ui_term() {
XFreeFont( UI.display, Style.font.regular );
XFreeFont( UI.display, Style.font.bold );