diff options
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/core/irc-server.c | 42 | ||||
-rw-r--r-- | src/irc/core/irc.c | 26 | ||||
-rw-r--r-- | src/irc/dcc/dcc-chat.c | 3 | ||||
-rw-r--r-- | src/irc/dcc/dcc-files.c | 3 |
4 files changed, 35 insertions, 39 deletions
diff --git a/src/irc/core/irc-server.c b/src/irc/core/irc-server.c index 376b503e..1439157d 100644 --- a/src/irc/core/irc-server.c +++ b/src/irc/core/irc-server.c @@ -21,6 +21,7 @@ #include "module.h" #include "net-nonblock.h" +#include "net-sendbuffer.h" #include "line-split.h" #include "signals.h" #include "modules.h" @@ -208,16 +209,17 @@ static void sig_disconnected(IRC_SERVER_REC *server) g_slist_foreach(server->cmdqueue, (GFunc) g_free, NULL); g_slist_free(server->cmdqueue); - if (server->handle != -1) { + if (server->handle != NULL) { if (!chans || server->connection_lost) - net_disconnect(server->handle); + net_sendbuffer_destroy(server->handle, TRUE); else { /* we were on some channels, try to let the server disconnect so that our quit message is guaranteed to get displayed */ - net_disconnect_later(server->handle); + net_disconnect_later(net_sendbuffer_handle(server->handle)); + net_sendbuffer_destroy(server->handle, FALSE); } - server->handle = -1; + server->handle = NULL; } irc_server_connect_free(server->connrec); @@ -239,7 +241,7 @@ static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) { long usecs; char *cmd; - int len, ret, add_rawlog; + int len, add_rawlog; if (!irc_server_check(server)) return; @@ -262,22 +264,16 @@ static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) add_rawlog = !server->cmd_last_split; - ret = net_transmit(server->handle, cmd, len); - if (ret != len) { - /* we didn't transmit all data, try again a bit later.. */ - if (ret > 0) { - cmd = g_strdup((char *) (server->cmdqueue->data) + ret); - g_free(server->cmdqueue->data); - server->cmdqueue->data = cmd; - } - server->cmd_last_split = TRUE; - server->cmdcount++; - } else { - memcpy(&server->last_cmd, now, sizeof(GTimeVal)); - if (server->cmd_last_split) - server->cmd_last_split = FALSE; + if (net_sendbuffer_send(server->handle, cmd, len) == -1) { + /* something bad happened */ + g_warning("net_sendbuffer_send() failed: %s", g_strerror(errno)); + return; } + memcpy(&server->last_cmd, now, sizeof(GTimeVal)); + if (server->cmd_last_split) + server->cmd_last_split = FALSE; + if (add_rawlog) { /* add to rawlog without CR+LF */ int slen; @@ -288,11 +284,9 @@ static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) cmd[slen-2] = '\r'; } - if (ret == len) { - /* remove from queue */ - g_free(cmd); - server->cmdqueue = g_slist_remove(server->cmdqueue, cmd); - } + /* remove from queue */ + g_free(cmd); + server->cmdqueue = g_slist_remove(server->cmdqueue, cmd); } /* check every now and then if there's data to be sent in command buffer */ diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index d464b098..c58b5db1 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -21,6 +21,7 @@ #include "module.h" #include "modules.h" #include "network.h" +#include "net-sendbuffer.h" #include "line-split.h" #include "rawlog.h" @@ -38,7 +39,7 @@ static int signal_server_incoming; static void cmd_send(IRC_SERVER_REC *server, const char *cmd, int send_now, int immediate) { char str[513], *ptr; - int len, ret; + int len; server->cmdcount++; @@ -53,25 +54,22 @@ static void cmd_send(IRC_SERVER_REC *server, const char *cmd, int send_now, int ptr = str; if (send_now) { - ret = net_transmit(server->handle, str, len); - if (ret == len) { - g_get_current_time(&server->last_cmd); - return; + if (net_sendbuffer_send(server->handle, str, len) == -1) { + /* something bad happened */ + g_warning("net_sendbuffer_send() failed: %s", + g_strerror(errno)); } - /* we didn't transmit all data, try again a bit later.. */ - ptr += ret; - server->cmd_last_split = TRUE; + g_get_current_time(&server->last_cmd); + return; } /* add to queue */ ptr = g_strdup(ptr); if (!immediate) server->cmdqueue = g_slist_append(server->cmdqueue, ptr); - else if (send_now) - server->cmdqueue = g_slist_prepend(server->cmdqueue, ptr); else - server->cmdqueue = g_slist_insert(server->cmdqueue, ptr, 1); + server->cmdqueue = g_slist_prepend(server->cmdqueue, ptr); } /* Send command to IRC server */ @@ -280,7 +278,8 @@ static int irc_receive_line(SERVER_REC *server, char **str) g_return_val_if_fail(server != NULL, -1); g_return_val_if_fail(str != NULL, -1); - recvlen = net_receive(server->handle, tmpbuf, sizeof(tmpbuf)); + recvlen = net_receive(net_sendbuffer_handle(server->handle), + tmpbuf, sizeof(tmpbuf)); ret = line_split(tmpbuf, recvlen, str, (LINEBUF_REC **) &server->buffer); if (ret == -1) { @@ -346,7 +345,8 @@ static void irc_init_server(IRC_SERVER_REC *server) g_return_if_fail(server != NULL); server->readtag = - g_input_add(server->handle, G_INPUT_READ, + g_input_add(net_sendbuffer_handle(server->handle), + G_INPUT_READ, (GInputFunction) irc_parse_incoming, server); } diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c index 83330c6a..8cae1265 100644 --- a/src/irc/dcc/dcc-chat.c +++ b/src/irc/dcc/dcc-chat.c @@ -23,6 +23,7 @@ #include "commands.h" #include "network.h" #include "net-nonblock.h" +#include "net-sendbuffer.h" #include "line-split.h" #include "settings.h" @@ -281,7 +282,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server) if (server == NULL || !server->connected) cmd_param_error(CMDERR_NOT_CONNECTED); - if (net_getsockname(server->handle, &own_ip, NULL) == -1) + if (net_getsockname(net_sendbuffer_handle(server->handle), &own_ip, NULL) == -1) cmd_param_error(CMDERR_ERRNO); port = settings_get_int("dcc_port"); diff --git a/src/irc/dcc/dcc-files.c b/src/irc/dcc/dcc-files.c index 68df8033..e367f23f 100644 --- a/src/irc/dcc/dcc-files.c +++ b/src/irc/dcc/dcc-files.c @@ -22,6 +22,7 @@ #include "signals.h" #include "commands.h" #include "network.h" +#include "net-sendbuffer.h" #include "line-split.h" #include "misc.h" #include "settings.h" @@ -541,7 +542,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i lseek(hfile, 0, SEEK_SET); /* get the IP address we use with IRC server */ - if (net_getsockname(chat != NULL ? chat->handle : server->handle, &own_ip, NULL) == -1) { + if (net_getsockname(chat != NULL ? chat->handle : net_sendbuffer_handle(server->handle), &own_ip, NULL) == -1) { close(hfile); cmd_param_error(CMDERR_ERRNO); } |