Don't suppress errno

Refs #583
This commit is contained in:
Derek Bankieris 2018-03-20 15:21:13 -05:00
parent 69d64fb582
commit c1aff35a6a
2 changed files with 9 additions and 5 deletions

View File

@ -3,6 +3,8 @@
* Establish a connection with a communications server
*/
#include <string.h>
#ifndef __WIN32__
#include <netdb.h>
#include <errno.h>
@ -86,7 +88,7 @@ int tc_connect_(TCDevice * device, const char *file, int line)
the_socket = socket( TRICKCOMM_SOCKET_FAMILY, SOCK_STREAM, TRICKCOMM_SOCKET_PROTO );
if ( the_socket == TRICKCOMM_INVALID_SOCKET){
trick_error_report(device->error_handler,TRICK_ERROR_ALERT, file, line, "%s: could not open socket\n", client_str);
trick_error_report(device->error_handler,TRICK_ERROR_ALERT, file, line, "%s: could not open socket: %s\n", client_str, strerror(errno));
return (TC_COULD_NOT_OPEN_SOCKET);
}
@ -141,7 +143,7 @@ int tc_connect_(TCDevice * device, const char *file, int line)
#endif
if ( ret < 0) {
trick_error_report(device->error_handler,TRICK_ERROR_ALERT, file, line, "%s: could not connect to host\n", client_str);
trick_error_report(device->error_handler,TRICK_ERROR_ALERT, file, line, "%s: could not connect to host: %s\n", client_str, strerror(errno));
CLOSE_SOCKET(the_socket);
return (TC_COULD_NOT_CONNECT);
}

View File

@ -3,6 +3,8 @@
* Set up a device on which to listen for connections
*/
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#ifndef __WIN32__
#include <netinet/tcp.h>
@ -61,7 +63,7 @@ int tc_init_with_connection_info( TCDevice * listen_device,
if (listen_socket == TRICKCOMM_INVALID_SOCKET) {
trick_error_report(listen_device->error_handler,
TRICK_ERROR_ALERT, __FILE__, __LINE__,
"could not open socket on port %d\n", (listen_device->port));
"could not open socket on port %d: %s\n", listen_device->port, strerror(errno));
return (TC_COULD_NOT_OPEN_SOCKET);
}
@ -105,7 +107,7 @@ int tc_init_with_connection_info( TCDevice * listen_device,
if (bind(listen_socket, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) {
trick_error_report(listen_device->error_handler,
TRICK_ERROR_ADVISORY, __FILE__, __LINE__,
"could not bind socket for port %d\n", (listen_device->port));
"could not bind socket for port %d: %s\n", listen_device->port, strerror(errno));
return (TC_COULD_NOT_BIND_SOCKET);
}
@ -122,7 +124,7 @@ int tc_init_with_connection_info( TCDevice * listen_device,
/* listen can get EADDRINUSE when server & client are same machine */
trick_error_report(listen_device->error_handler,
TRICK_ERROR_ADVISORY, __FILE__, __LINE__,
"could not listen on port %d\n", (listen_device->port));
"could not listen on port %d: %s\n", listen_device->port, strerror(errno));
return (TC_COULD_NOT_LISTEN_SOCKET);
}
}