From 5c3f22d8a84b0fcd45ba192026d1bc1fbbbc75ec Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Wed, 17 Feb 2010 12:32:15 +0000 Subject: [PATCH] Revert "Unbraindead" This reverts commit b21c658b8cec8cebfb7de52f6ecb9c50e263fb89. --- src/connection.c | 43 +++++++++++++++++++++---------------------- src/irc.c | 4 ++-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/connection.c b/src/connection.c index 8b999d8..e6dc0cd 100644 --- a/src/connection.c +++ b/src/connection.c @@ -32,7 +32,7 @@ int link_add_untrusted(void *ls, X509 *cert); static int connection_timedout(connection_t *cn); static int socket_set_nonblock(int s); static void connection_connected(connection_t *c); -void cn_use_token(connection_t *); +int cn_want_write(connection_t *cn); struct connecting_data { @@ -292,8 +292,6 @@ static int real_write_all(connection_t *cn) if (cn == NULL) fatal("real_write_all: wrong arguments"); - if (cn->token == 0) - return 0; if (cn->partial) { line = cn->partial; @@ -303,7 +301,11 @@ static int real_write_all(connection_t *cn) } do { - ret = write_socket(cn, line); + if (!cn_want_write(cn)) + ret = WRITE_KEEP; + else + ret = write_socket(cn, line); + switch (ret) { case WRITE_ERROR: /* we might as well free(line) here */ @@ -315,14 +317,13 @@ static int real_write_all(connection_t *cn) cn->partial = line; return 0; case WRITE_OK: - cn_use_token(cn); free(line); break; default: fatal("internal error 6"); break; } - } while (cn->token && (line = list_remove_first(cn->outgoing))); + } while ((line = list_remove_first(cn->outgoing))); return 0; } @@ -638,11 +639,8 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc) } if (!FD_ISSET(cn->handle, fds)) { - if (cn_is_connected(cn)) { - if (!list_is_empty(cn->outgoing)) - real_write_all(cn); + if (cn_is_connected(cn)) return 0; - } mylog(LOG_DEBUG, "New socket still not connected (%d)", cn->handle); @@ -721,7 +719,7 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc) /* token generation interval: 1200ms */ #define TOKEN_INTERVAL 1200 -void cn_use_token(connection_t *cn) +int cn_want_write(connection_t *cn) { struct timeval tv; unsigned long now; @@ -748,13 +746,17 @@ void cn_use_token(connection_t *cn) cn->token = 1; cn->lasttoken = now; } - } else { - /* if gettimeofday() fails, juste ignore antiflood */ + } else + /* if gettimeofday() fails, juste ignore + * antiflood */ cn->token = 1; - } - if (cn->token > 0) + /* use a token if needed and available */ + if (!list_is_empty(cn->outgoing) && cn->token > 0) { cn->token--; + return 1; + } + return 0; } list_t *wait_event(list_t *cn_list, int *msec, int *nc) @@ -815,13 +817,10 @@ list_t *wait_event(list_t *cn_list, int *msec, int *nc) continue; if (!cn_is_connected(cn) || !list_is_empty(cn->outgoing)) { - if (cn->token) { - FD_SET(cn->handle, &fds_write); - mylog(LOG_DEBUGTOOMUCH, - "Test write on fd %d %d:%d", - cn->handle, cn->connected, - cn_is_connected(cn)); - } + FD_SET(cn->handle, &fds_write); + mylog(LOG_DEBUGTOOMUCH, "Test write on fd %d %d:%d", + cn->handle, cn->connected, + cn_is_connected(cn)); } } diff --git a/src/irc.c b/src/irc.c index b2acfef..c44987b 100644 --- a/src/irc.c +++ b/src/irc.c @@ -221,6 +221,8 @@ static void irc_server_connected(struct link_server *server) log_connected(LINK(server)->log); + CONN(server)->token = 1; + if (LINK(server)->cli_nick) { /* we change nick on client */ for (i = 0; i < LINK(server)->l_clientc; i++) { @@ -1961,8 +1963,6 @@ static void irc_server_startup(struct link_server *ircs) char *nick; char *username, *realname; - CONN(ircs)->token = 1; - if (LINK(ircs)->s_password) WRITE_LINE1(CONN(ircs), NULL, "PASS", LINK(ircs)->s_password);