Revert "Unbraindead"

This reverts commit b21c658b8c.
This commit is contained in:
Arnaud Cornet 2010-02-17 12:32:15 +00:00
parent b21c658b8c
commit 5c3f22d8a8
2 changed files with 23 additions and 24 deletions

View File

@ -32,7 +32,7 @@ int link_add_untrusted(void *ls, X509 *cert);
static int connection_timedout(connection_t *cn); static int connection_timedout(connection_t *cn);
static int socket_set_nonblock(int s); static int socket_set_nonblock(int s);
static void connection_connected(connection_t *c); static void connection_connected(connection_t *c);
void cn_use_token(connection_t *); int cn_want_write(connection_t *cn);
struct connecting_data struct connecting_data
{ {
@ -292,8 +292,6 @@ static int real_write_all(connection_t *cn)
if (cn == NULL) if (cn == NULL)
fatal("real_write_all: wrong arguments"); fatal("real_write_all: wrong arguments");
if (cn->token == 0)
return 0;
if (cn->partial) { if (cn->partial) {
line = cn->partial; line = cn->partial;
@ -303,7 +301,11 @@ static int real_write_all(connection_t *cn)
} }
do { do {
ret = write_socket(cn, line); if (!cn_want_write(cn))
ret = WRITE_KEEP;
else
ret = write_socket(cn, line);
switch (ret) { switch (ret) {
case WRITE_ERROR: case WRITE_ERROR:
/* we might as well free(line) here */ /* we might as well free(line) here */
@ -315,14 +317,13 @@ static int real_write_all(connection_t *cn)
cn->partial = line; cn->partial = line;
return 0; return 0;
case WRITE_OK: case WRITE_OK:
cn_use_token(cn);
free(line); free(line);
break; break;
default: default:
fatal("internal error 6"); fatal("internal error 6");
break; break;
} }
} while (cn->token && (line = list_remove_first(cn->outgoing))); } while ((line = list_remove_first(cn->outgoing)));
return 0; 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 (!FD_ISSET(cn->handle, fds)) {
if (cn_is_connected(cn)) { if (cn_is_connected(cn))
if (!list_is_empty(cn->outgoing))
real_write_all(cn);
return 0; return 0;
}
mylog(LOG_DEBUG, "New socket still not connected (%d)", mylog(LOG_DEBUG, "New socket still not connected (%d)",
cn->handle); cn->handle);
@ -721,7 +719,7 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc)
/* token generation interval: 1200ms */ /* token generation interval: 1200ms */
#define TOKEN_INTERVAL 1200 #define TOKEN_INTERVAL 1200
void cn_use_token(connection_t *cn) int cn_want_write(connection_t *cn)
{ {
struct timeval tv; struct timeval tv;
unsigned long now; unsigned long now;
@ -748,13 +746,17 @@ void cn_use_token(connection_t *cn)
cn->token = 1; cn->token = 1;
cn->lasttoken = now; cn->lasttoken = now;
} }
} else { } else
/* if gettimeofday() fails, juste ignore antiflood */ /* if gettimeofday() fails, juste ignore
* antiflood */
cn->token = 1; 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--; cn->token--;
return 1;
}
return 0;
} }
list_t *wait_event(list_t *cn_list, int *msec, int *nc) 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; continue;
if (!cn_is_connected(cn) || !list_is_empty(cn->outgoing)) { if (!cn_is_connected(cn) || !list_is_empty(cn->outgoing)) {
if (cn->token) { FD_SET(cn->handle, &fds_write);
FD_SET(cn->handle, &fds_write); mylog(LOG_DEBUGTOOMUCH, "Test write on fd %d %d:%d",
mylog(LOG_DEBUGTOOMUCH, cn->handle, cn->connected,
"Test write on fd %d %d:%d", cn_is_connected(cn));
cn->handle, cn->connected,
cn_is_connected(cn));
}
} }
} }

View File

@ -221,6 +221,8 @@ static void irc_server_connected(struct link_server *server)
log_connected(LINK(server)->log); log_connected(LINK(server)->log);
CONN(server)->token = 1;
if (LINK(server)->cli_nick) { if (LINK(server)->cli_nick) {
/* we change nick on client */ /* we change nick on client */
for (i = 0; i < LINK(server)->l_clientc; i++) { 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 *nick;
char *username, *realname; char *username, *realname;
CONN(ircs)->token = 1;
if (LINK(ircs)->s_password) if (LINK(ircs)->s_password)
WRITE_LINE1(CONN(ircs), NULL, "PASS", LINK(ircs)->s_password); WRITE_LINE1(CONN(ircs), NULL, "PASS", LINK(ircs)->s_password);