From d1e13bc526c016914cc36b55879ddcd9ba579d18 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Thu, 30 Sep 2010 13:26:06 +0000 Subject: [PATCH] Show correct message ("Remote end closed connection") when we get EOF on a socket. I also added a wrapper function around strerror() for dgets_errno, since we did the same thing in a few places. This all needs to be cleaned up a little - the -1 value we use could in theory clash with an actual errno error number. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@104 13b04d17-f746-0410-82c6-800466cd88b0 --- Changelog | 2 ++ include/newio.h | 1 + source/dcc.c | 6 +++--- source/newio.c | 16 +++++++++++++++- source/server.c | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 53d6479..df13a6a 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ [Changes 1.2c01] +* Show correct message when a socket connection is closed cleanly. (caf) + * Add /FSET WHOIS_CALLERID for +g mode notification on hybrid & ratbox. (caf) * Build script fix to allow plugins to build on x86-64. (caf) diff --git a/include/newio.h b/include/newio.h index 14541c7..8f8d150 100644 --- a/include/newio.h +++ b/include/newio.h @@ -12,6 +12,7 @@ extern int dgets_errno; + const char *dgets_strerror(int); int BX_dgets (char *, int, int, int, void *); int new_select (fd_set *, fd_set *, struct timeval *); int BX_new_open (int); diff --git a/source/dcc.c b/source/dcc.c index 2a59d5c..619009d 100644 --- a/source/dcc.c +++ b/source/dcc.c @@ -818,7 +818,7 @@ SocketList *sl; { case -1: { - char *real_tmp = ((dgets_errno == -1) ? "Remote End Closed Connection" : strerror(dgets_errno)); + const char *real_tmp = dgets_strerror(dgets_errno); if (do_hook(DCC_LOST_LIST, "%s %s %s", nick, dcc_types[type]->name, real_tmp)) put_it("%s", convert_output_format(fget_string_var(FORMAT_DCC_ERROR_FSET), "%s %s %s %s", update_clock(GET_TIME), @@ -952,8 +952,8 @@ SocketList *sl; { case -1: { - char *real_tmp = ((dgets_errno == -1) ? "Remote End Closed Connection" : strerror(dgets_errno)); - if (do_hook(DCC_LOST_LIST, "%s %s %s", nick, dcc_types[type]->name, real_tmp)) + const char *real_tmp = dgets_strerror(dgets_errno); + if (do_hook(DCC_LOST_LIST, "%s %s %s", nick, dcc_types[type]->name, real_tmp)) put_it("%s", convert_output_format(fget_string_var(FORMAT_DCC_ERROR_FSET), "%s %s %s %s", update_clock(GET_TIME), dcc_types[type]->name, nick, real_tmp)); diff --git a/source/newio.c b/source/newio.c index f4edf88..4ef2896 100644 --- a/source/newio.c +++ b/source/newio.c @@ -100,6 +100,20 @@ void SSL_show_errors(void) } #endif +/* Wrapper around strerror() for dgets_errno. + */ +const char *dgets_strerror(int dgets_errno) +{ + switch (dgets_errno) + { + case -1: + return "Remote end closed connection"; + + default: + return strerror(dgets_errno); + } +} + /* * All new dgets -- no more trap doors! * @@ -204,7 +218,7 @@ int BX_dgets (char *str, int des, int buffer, int buffersize, void *ssl_fd) else if (!nbytes && ioe->write_pos == 0) { *str = 0; - dgets_errno = errno; + dgets_errno = -1; return -1; } diff --git a/source/server.c b/source/server.c index b5f090c..7e60353 100644 --- a/source/server.c +++ b/source/server.c @@ -535,7 +535,7 @@ static time_t last_timeout = 0; /* Try to make sure output goes to the correct window */ if(server_list[i].server_change_refnum > -1) set_display_target_by_winref(server_list[i].server_change_refnum); - say("Connection closed from %s: %s", server_list[i].name, (dgets_errno == -1) ? "Remote end closed connection" : strerror(dgets_errno)); + say("Connection closed from %s: %s", server_list[i].name, dgets_strerror(dgets_errno)); server_list[i].reconnecting = 1; close_server(i, empty_string);