1
0
mirror of https://github.com/moparisthebest/hexchat synced 2024-11-22 01:02:20 -05:00

Use only one GIOChannel instead of making a new one every time.

This commit is contained in:
Arnavion 2014-12-06 12:18:40 -08:00
parent 5152040c17
commit 0ff0fd4493
6 changed files with 95 additions and 86 deletions

View File

@ -375,9 +375,7 @@ const struct prefs vars[] =
{"dcc_blocksize", P_OFFINT (hex_dcc_blocksize), TYPE_INT}, {"dcc_blocksize", P_OFFINT (hex_dcc_blocksize), TYPE_INT},
{"dcc_completed_dir", P_OFFSET (hex_dcc_completed_dir), TYPE_STR}, {"dcc_completed_dir", P_OFFSET (hex_dcc_completed_dir), TYPE_STR},
{"dcc_dir", P_OFFSET (hex_dcc_dir), TYPE_STR}, {"dcc_dir", P_OFFSET (hex_dcc_dir), TYPE_STR},
#ifndef WIN32
{"dcc_fast_send", P_OFFINT (hex_dcc_fast_send), TYPE_BOOL}, {"dcc_fast_send", P_OFFINT (hex_dcc_fast_send), TYPE_BOOL},
#endif
{"dcc_global_max_get_cps", P_OFFINT (hex_dcc_global_max_get_cps), TYPE_INT}, {"dcc_global_max_get_cps", P_OFFINT (hex_dcc_global_max_get_cps), TYPE_INT},
{"dcc_global_max_send_cps", P_OFFINT (hex_dcc_global_max_send_cps), TYPE_INT}, {"dcc_global_max_send_cps", P_OFFINT (hex_dcc_global_max_send_cps), TYPE_INT},
{"dcc_ip", P_OFFSET (hex_dcc_ip), TYPE_STR}, {"dcc_ip", P_OFFSET (hex_dcc_ip), TYPE_STR},
@ -740,9 +738,7 @@ load_default_config(void)
prefs.hex_away_show_once = 1; prefs.hex_away_show_once = 1;
prefs.hex_away_track = 1; prefs.hex_away_track = 1;
prefs.hex_dcc_auto_resume = 1; prefs.hex_dcc_auto_resume = 1;
#ifndef WIN32
prefs.hex_dcc_fast_send = 1; prefs.hex_dcc_fast_send = 1;
#endif
prefs.hex_gui_autoopen_chat = 1; prefs.hex_gui_autoopen_chat = 1;
prefs.hex_gui_autoopen_dialog = 1; prefs.hex_gui_autoopen_dialog = 1;
prefs.hex_gui_autoopen_recv = 1; prefs.hex_gui_autoopen_recv = 1;

View File

@ -330,15 +330,16 @@ dcc_lookup_proxy (char *host, struct sockaddr_in *addr)
#define DCC_USE_PROXY() (prefs.hex_net_proxy_host[0] && prefs.hex_net_proxy_type>0 && prefs.hex_net_proxy_type<5 && prefs.hex_net_proxy_use!=1) #define DCC_USE_PROXY() (prefs.hex_net_proxy_host[0] && prefs.hex_net_proxy_type>0 && prefs.hex_net_proxy_type<5 && prefs.hex_net_proxy_use!=1)
static int static void
dcc_connect_sok (struct DCC *dcc) dcc_connect_sok (struct DCC *dcc)
{ {
int sok;
struct sockaddr_in addr; struct sockaddr_in addr;
sok = socket (AF_INET, SOCK_STREAM, 0); dcc->sok = socket(AF_INET, SOCK_STREAM, 0);
if (sok == -1) if (dcc->sok == -1)
return -1; {
return;
}
memset (&addr, 0, sizeof (addr)); memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
@ -346,8 +347,9 @@ dcc_connect_sok (struct DCC *dcc)
{ {
if (!dcc_lookup_proxy (prefs.hex_net_proxy_host, &addr)) if (!dcc_lookup_proxy (prefs.hex_net_proxy_host, &addr))
{ {
closesocket (sok); closesocket (dcc->sok);
return -1; dcc->sok = - 1;
return;
} }
addr.sin_port = htons (prefs.hex_net_proxy_port); addr.sin_port = htons (prefs.hex_net_proxy_port);
} }
@ -357,10 +359,14 @@ dcc_connect_sok (struct DCC *dcc)
addr.sin_addr.s_addr = htonl (dcc->addr); addr.sin_addr.s_addr = htonl (dcc->addr);
} }
set_nonblocking (sok); set_nonblocking (dcc->sok);
connect (sok, (struct sockaddr *) &addr, sizeof (addr)); connect (dcc->sok, (struct sockaddr *) &addr, sizeof (addr));
return sok; #ifdef WIN32
dcc->channel = g_io_channel_win32_new_socket (dcc->sok);
#else
dcc->channel = g_io_channel_unix_new (dcc->sok);
#endif
} }
static void static void
@ -368,16 +374,22 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
{ {
if (dcc->wiotag) if (dcc->wiotag)
{ {
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
} }
if (dcc->iotag) if (dcc->iotag)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
if (dcc->channel != NULL)
{
g_io_channel_unref (dcc->channel);
dcc->channel = NULL;
}
if (dcc->sok != -1) if (dcc->sok != -1)
{ {
closesocket (dcc->sok); closesocket (dcc->sok);
@ -609,13 +621,15 @@ dcc_read_chat (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
{ {
if (dcc->throttled) if (dcc->throttled)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
return FALSE; return FALSE;
} }
if (!dcc->iotag) if (!dcc->iotag)
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc); {
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
}
len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0); len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0);
if (len < 1) if (len < 1)
@ -748,13 +762,15 @@ dcc_read (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (need_ack) if (need_ack)
dcc_send_ack (dcc); dcc_send_ack (dcc);
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
return FALSE; return FALSE;
} }
if (!dcc->iotag) if (!dcc->iotag)
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc); {
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read, dcc);
}
n = recv (dcc->sok, buf, sizeof (buf), 0); n = recv (dcc->sok, buf, sizeof (buf), 0);
if (n < 1) if (n < 1)
@ -868,7 +884,7 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
if (dcc->iotag) if (dcc->iotag)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
@ -881,16 +897,14 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
switch (dcc->type) switch (dcc->type)
{ {
case TYPE_RECV: case TYPE_RECV:
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc); dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read, dcc);
EMIT_SIGNAL (XP_TE_DCCCONRECV, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONRECV, dcc->serv->front_session,
dcc->nick, host, dcc->file, NULL, 0); dcc->nick, host, dcc->file, NULL, 0);
break; break;
case TYPE_SEND: case TYPE_SEND:
/* passive send */ /* passive send */
dcc->fastsend = prefs.hex_dcc_fast_send; dcc->fastsend = prefs.hex_dcc_fast_send;
if (dcc->fastsend) dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_ack, dcc);
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE, dcc_send_data, dcc);
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_ack, dcc);
dcc_send_data (NULL, 0, (gpointer) dcc); dcc_send_data (NULL, 0, (gpointer) dcc);
EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session,
dcc->nick, host, dcc->file, NULL, 0); dcc->nick, host, dcc->file, NULL, 0);
@ -898,7 +912,7 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
case TYPE_CHATSEND: /* pchat */ case TYPE_CHATSEND: /* pchat */
dcc_open_query (dcc->serv, dcc->nick); dcc_open_query (dcc->serv, dcc->nick);
case TYPE_CHATRECV: /* normal chat */ case TYPE_CHATRECV: /* normal chat */
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc); dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
dcc->dccchat = malloc (sizeof (struct dcc_chat)); dcc->dccchat = malloc (sizeof (struct dcc_chat));
dcc->dccchat->pos = 0; dcc->dccchat->pos = 0;
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
@ -932,7 +946,7 @@ read_proxy (struct DCC *dcc)
fe_dcc_update (dcc); fe_dcc_update (dcc);
if (dcc->iotag) if (dcc->iotag)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
return FALSE; return FALSE;
@ -962,7 +976,7 @@ write_proxy (struct DCC *dcc)
fe_dcc_update (dcc); fe_dcc_update (dcc);
if (dcc->wiotag) if (dcc->wiotag)
{ {
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
} }
return FALSE; return FALSE;
@ -1000,15 +1014,14 @@ dcc_wingate_proxy_traverse (GIOChannel *source, GIOCondition condition, struct D
"%s %d\r\n", net_ip(dcc->addr), "%s %d\r\n", net_ip(dcc->addr),
dcc->port); dcc->port);
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_wingate_proxy_traverse, dcc);
dcc_wingate_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
if (proxy->phase == 1) if (proxy->phase == 1)
{ {
if (!read_proxy (dcc)) if (!read_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
dcc_connect_finished (source, 0, dcc); dcc_connect_finished (source, 0, dcc);
} }
@ -1039,8 +1052,7 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
memcpy (proxy->buffer, &sc, sizeof (sc)); memcpy (proxy->buffer, &sc, sizeof (sc));
proxy->buffersize = 8 + strlen (sc.username) + 1; proxy->buffersize = 8 + strlen (sc.username) + 1;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks_proxy_traverse, dcc);
dcc_socks_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1048,12 +1060,11 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->bufferused = 0; proxy->bufferused = 0;
proxy->buffersize = 8; proxy->buffersize = 8;
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks_proxy_traverse, dcc);
dcc_socks_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1061,7 +1072,7 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
{ {
if (!read_proxy (dcc)) if (!read_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
if (proxy->buffer[1] == 90) if (proxy->buffer[1] == 90)
dcc_connect_finished (source, 0, dcc); dcc_connect_finished (source, 0, dcc);
@ -1099,8 +1110,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
memcpy (proxy->buffer, &sc1, 3); memcpy (proxy->buffer, &sc1, 3);
proxy->buffersize = 3; proxy->buffersize = 3;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1108,12 +1118,11 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->bufferused = 0; proxy->bufferused = 0;
proxy->buffersize = 2; proxy->buffersize = 2;
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1121,7 +1130,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!read_proxy (dcc)) if (!read_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
/* did the server say no auth required? */ /* did the server say no auth required? */
@ -1155,8 +1164,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
proxy->buffersize = 3 + len_u + len_p; proxy->buffersize = 3 + len_u + len_p;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
else else
@ -1176,12 +1184,11 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->buffersize = 2; proxy->buffersize = 2;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1191,7 +1198,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
return TRUE; return TRUE;
if (dcc->iotag) if (dcc->iotag)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
if (proxy->buffer[1] != 0) if (proxy->buffer[1] != 0)
@ -1219,8 +1226,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
proxy->buffer[9] = (dcc->port & 0xFF); proxy->buffer[9] = (dcc->port & 0xFF);
proxy->buffersize = 10; proxy->buffersize = 10;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1228,12 +1234,11 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->buffersize = 4; proxy->buffersize = 4;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1243,7 +1248,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
return TRUE; return TRUE;
if (proxy->buffer[0] != 5 || proxy->buffer[1] != 0) if (proxy->buffer[0] != 5 || proxy->buffer[1] != 0)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
if (proxy->buffer[1] == 2) if (proxy->buffer[1] == 2)
PrintText (dcc->serv->front_session, "SOCKS\tProxy refused to connect to host (not allowed).\n"); PrintText (dcc->serv->front_session, "SOCKS\tProxy refused to connect to host (not allowed).\n");
@ -1274,7 +1279,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
/* everything done? */ /* everything done? */
if (proxy->bufferused == proxy->buffersize) if (proxy->bufferused == proxy->buffersize)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
dcc_connect_finished (source, 0, dcc); dcc_connect_finished (source, 0, dcc);
} }
@ -1307,8 +1312,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
proxy->buffersize = n; proxy->buffersize = n;
proxy->bufferused = 0; proxy->bufferused = 0;
memcpy (proxy->buffer, buf, proxy->buffersize); memcpy (proxy->buffer, buf, proxy->buffersize);
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_http_proxy_traverse, dcc);
dcc_http_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1316,11 +1320,10 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->bufferused = 0; proxy->bufferused = 0;
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_http_proxy_traverse, dcc);
dcc_http_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@ -1332,7 +1335,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
if (proxy->bufferused < 12 || if (proxy->bufferused < 12 ||
memcmp (proxy->buffer, "HTTP/", 5) || memcmp (proxy->buffer + 9, "200", 3)) memcmp (proxy->buffer, "HTTP/", 5) || memcmp (proxy->buffer + 9, "200", 3))
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
PrintText (dcc->serv->front_session, proxy->buffer); PrintText (dcc->serv->front_session, proxy->buffer);
dcc->dccstat = STAT_FAILED; dcc->dccstat = STAT_FAILED;
@ -1362,7 +1365,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
else else
return TRUE; return TRUE;
} }
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
dcc_connect_finished (source, 0, dcc); dcc_connect_finished (source, 0, dcc);
} }
@ -1373,7 +1376,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
static gboolean static gboolean
dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc) dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
{ {
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
if (!dcc_did_connect (source, condition, dcc)) if (!dcc_did_connect (source, condition, dcc))
@ -1432,7 +1435,7 @@ dcc_connect (struct DCC *dcc)
} }
else else
{ {
dcc->sok = dcc_connect_sok (dcc); dcc_connect_sok (dcc);
if (dcc->sok == -1) if (dcc->sok == -1)
{ {
dcc->dccstat = STAT_FAILED; dcc->dccstat = STAT_FAILED;
@ -1440,9 +1443,13 @@ dcc_connect (struct DCC *dcc)
return; return;
} }
if (DCC_USE_PROXY ()) if (DCC_USE_PROXY ())
dcc->iotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc_proxy_connect, dcc); {
g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_proxy_connect, dcc);
}
else else
dcc->iotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc_connect_finished, dcc); {
g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_connect_finished, dcc);
}
} }
fe_dcc_update (dcc); fe_dcc_update (dcc);
@ -1462,7 +1469,7 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (dcc->throttled) if (dcc->throttled)
{ {
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
return FALSE; return FALSE;
} }
@ -1472,8 +1479,6 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (dcc->ack < (dcc->pos & 0xFFFFFFFF)) if (dcc->ack < (dcc->pos & 0xFFFFFFFF))
return TRUE; return TRUE;
} }
else if (!dcc->wiotag)
dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc);
buf = malloc (prefs.hex_dcc_blocksize); buf = malloc (prefs.hex_dcc_blocksize);
if (!buf) if (!buf)
@ -1501,13 +1506,18 @@ abortit:
dcc->lasttime = time (0); dcc->lasttime = time (0);
} }
/* have we sent it all yet? */ if (dcc->pos < dcc->size)
if (dcc->pos >= dcc->size) {
if (!dcc->wiotag)
{
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_HUP | G_IO_ERR, dcc_send_data, dcc);
}
}
else
{ {
/* it's all sent now, so remove the WRITE/SEND handler */
if (dcc->wiotag) if (dcc->wiotag)
{ {
fe_input_remove (dcc->wiotag); g_source_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
} }
} }
@ -1606,7 +1616,7 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
len = sizeof (CAddr); len = sizeof (CAddr);
sok = accept (dcc->sok, (struct sockaddr *) &CAddr, &len); sok = accept (dcc->sok, (struct sockaddr *) &CAddr, &len);
fe_input_remove (dcc->iotag); g_source_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
closesocket (dcc->sok); closesocket (dcc->sok);
if (sok < 0) if (sok < 0)
@ -1632,8 +1642,10 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
{ {
case TYPE_SEND: case TYPE_SEND:
if (dcc->fastsend) if (dcc->fastsend)
dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc); {
dcc->iotag = fe_input_add (sok, FIA_READ|FIA_EX, dcc_read_ack, dcc); dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR, dcc_send_data, dcc);
}
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_ack, dcc);
dcc_send_data (NULL, 0, (gpointer) dcc); dcc_send_data (NULL, 0, (gpointer) dcc);
EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session,
dcc->nick, host, dcc->file, NULL, 0); dcc->nick, host, dcc->file, NULL, 0);
@ -1641,7 +1653,7 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
case TYPE_CHATSEND: case TYPE_CHATSEND:
dcc_open_query (dcc->serv, dcc->nick); dcc_open_query (dcc->serv, dcc->nick);
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc); dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
dcc->dccchat = malloc (sizeof (struct dcc_chat)); dcc->dccchat = malloc (sizeof (struct dcc_chat));
dcc->dccchat->pos = 0; dcc->dccchat->pos = 0;
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
@ -1759,7 +1771,7 @@ dcc_listen_init (struct DCC *dcc, session *sess)
listen (dcc->sok, 1); listen (dcc->sok, 1);
set_blocking (dcc->sok); set_blocking (dcc->sok);
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_accept, dcc); dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_accept, dcc);
return TRUE; return TRUE;
} }

View File

@ -47,6 +47,7 @@ struct DCC
guint32 addr; /* the 32bit IP number, host byte order */ guint32 addr; /* the 32bit IP number, host byte order */
int fp; /* file pointer */ int fp; /* file pointer */
int sok; int sok;
GIOChannel* channel;
int iotag; /* reading io tag */ int iotag; /* reading io tag */
int wiotag; /* writing/sending io tag */ int wiotag; /* writing/sending io tag */
int port; int port;

View File

@ -64,7 +64,7 @@ void fe_message (char *msg, int flags);
#define FIA_WRITE 2 #define FIA_WRITE 2
#define FIA_EX 4 #define FIA_EX 4
#define FIA_FD 8 #define FIA_FD 8
int fe_input_add (int sok, int flags, void *func, void *data); int fe_input_add (int sok, int flags, GIOFunc func, void *data);
void fe_input_remove (int tag); void fe_input_remove (int tag);
void fe_idle_add (void *func, void *data); void fe_idle_add (void *func, void *data);
void fe_set_topic (struct session *sess, char *topic, char *stripped_topic); void fe_set_topic (struct session *sess, char *topic, char *stripped_topic);

View File

@ -466,7 +466,7 @@ fe_input_remove (int tag)
} }
int int
fe_input_add (int sok, int flags, void *func, void *data) fe_input_add (int sok, int flags, GIOFunc func, void *data)
{ {
int tag, type = 0; int tag, type = 0;
GIOChannel *channel; GIOChannel *channel;
@ -487,7 +487,7 @@ fe_input_add (int sok, int flags, void *func, void *data)
if (flags & FIA_EX) if (flags & FIA_EX)
type |= G_IO_PRI; type |= G_IO_PRI;
tag = g_io_add_watch (channel, type, (GIOFunc) func, data); tag = g_io_add_watch (channel, type, func, data);
g_io_channel_unref (channel); g_io_channel_unref (channel);
return tag; return tag;

View File

@ -426,7 +426,7 @@ fe_input_remove (int tag)
} }
int int
fe_input_add (int sok, int flags, void *func, void *data) fe_input_add (int sok, int flags, GIOFunc func, void *data)
{ {
int tag, type = 0; int tag, type = 0;
GIOChannel *channel; GIOChannel *channel;
@ -447,7 +447,7 @@ fe_input_add (int sok, int flags, void *func, void *data)
if (flags & FIA_EX) if (flags & FIA_EX)
type |= G_IO_PRI; type |= G_IO_PRI;
tag = g_io_add_watch (channel, type, (GIOFunc) func, data); tag = g_io_add_watch (channel, type, func, data);
g_io_channel_unref (channel); g_io_channel_unref (channel);
return tag; return tag;