@@ -21,7 +21,7 @@ static void sslDebug(void *ctx, int level, const char *file, int line, const cha
2121 printl (LOG_INFO , "%s:%04d: %s" , file , line , str );
2222}
2323#endif /*MBEDTLS_DEBUG_C*/
24- //TODO: Add checks if the socket is nonblocking or not as the implementation for net_would_block is missing
24+ // TODO: Add checks if the socket is nonblocking or not as the implementation for net_would_block is missing
2525int mbedtls_net_recv (void * ctx , unsigned char * buf , size_t len )
2626{
2727 int ret ;
@@ -91,6 +91,12 @@ int httpsConnect(player_t *currentPlayer, const char *hostname, const char *port
9191 printl (LOG_ERROR , "U_socket returned %d\n" , httpsData .net .fd );
9292 return 1 ;
9393 }
94+ ret = U_setsocknonblock (httpsData .net .fd );
95+ if (ret != 0 )
96+ {
97+ printl (LOG_ERROR , "U_setsocknonblock returned %d\n" , ret );
98+ return 1 ;
99+ }
94100 struct sockaddr_in server ;
95101 server .sin_family = AF_INET ;
96102 server .sin_port = htons (atoi (port ));
@@ -102,15 +108,9 @@ int httpsConnect(player_t *currentPlayer, const char *hostname, const char *port
102108 }
103109 server .sin_addr = * ((struct in_addr * )hostinfo -> h_addr );
104110 ret = U_connect (httpsData .net .fd , (struct sockaddr * )& server , sizeof (server ));
105- if (ret != 0 )
111+ if (ret != 0 && ( errno != 0 || errno != EINPROGRESS ) )
106112 {
107- printl (LOG_ERROR , "U_connect returned %d errno: %d\n" , ret ,errno );
108- return 1 ;
109- }
110- ret = U_setsocknonblock (httpsData .net .fd );
111- if (ret != 0 )
112- {
113- printl (LOG_ERROR , "U_setsocknonblock returned %d\n" , ret );
113+ printl (LOG_ERROR , "U_connect returned %d errno: %s\n" , ret , strerror (errno ));
114114 return 1 ;
115115 }
116116 ret = mbedtls_ssl_config_defaults (& httpsData .conf , MBEDTLS_SSL_IS_CLIENT , MBEDTLS_SSL_TRANSPORT_STREAM , MBEDTLS_SSL_PRESET_DEFAULT );
@@ -178,6 +178,7 @@ void httpsGetPlayerInfo(player_t *currentPlayer)
178178 ret = httpsConnect (currentPlayer , AUTH_HOST , AUTH_HOST_PORT );
179179 if (ret != 0 )
180180 {
181+ strncpy ((char * )currentPlayer -> disconnect_reason , "Internal server error!" , sizeof (((player_t * )0 )-> disconnect_reason ));
181182 printl (LOG_ERROR , "httpsConnect returned %d\n" , ret );
182183 httpsFreePlayer (currentPlayer );
183184 currentPlayer -> remove_player_event = 1 ;
0 commit comments