- it's not fucking outdated, it just needed one very minor fix
[packages/irssi.git] / irssi-dcc-send-limit.patch
CommitLineData
cdc4109b
JR
1diff -ur irssi-0.7.98.4/src/irc/dcc/dcc-rec.h irssi-0.7.98.4.limited/src/irc/dcc/dcc-rec.h
2--- irssi-0.7.98.4/src/irc/dcc/dcc-rec.h Mon Feb 19 04:40:06 2001
3+++ irssi-0.7.98.4.limited/src/irc/dcc/dcc-rec.h Sat Jan 19 19:40:16 2002
4@@ -20,6 +20,12 @@
5 time_t starttime; /* transfer start time */
6 unsigned long transfd; /* bytes transferred */
7
8+int timeout_tag;
9+
10+unsigned long skip_bytes;
11+unsigned long limit_starttime;
12+unsigned long max_speed;
13+
14 unsigned int destroyed:1; /* We're about to destroy this DCC recond */
15
16 GHashTable *module_data;
17diff -ur irssi-0.7.98.4/src/irc/dcc/dcc-send.c irssi-0.7.98.4.limited/src/irc/dcc/dcc-send.c
18--- irssi-0.7.98.4/src/irc/dcc/dcc-send.c Wed Feb 28 20:26:21 2001
19+++ irssi-0.7.98.4.limited/src/irc/dcc/dcc-send.c Sat Jan 19 19:43:15 2002
20@@ -48,14 +48,84 @@
21 {
22 if (!IS_DCC_SEND(dcc)) return;
23
24+ if (dcc->timeout_tag != -1)
25+ g_source_remove(dcc->timeout_tag);
26+
27 if (dcc->fhandle != -1) close(dcc->fhandle);
28 }
29
30+static int sent_too_much(SEND_DCC_REC *dcc)
31+{
32+ GTimeVal gtv;
33+ gulong timediff, curtime;
34+ gulong transfd, speed;
35+
36+ /* 0 == unlimited speed */
37+ if (dcc->max_speed == 0) return 0;
38+
39+ /* get time difference in milliseconds */
40+ g_get_current_time(&gtv);
41+ curtime = (gtv.tv_sec * 1000) + (gtv.tv_usec / 1000);
42+
43+ transfd = (dcc->transfd - dcc->skip_bytes);
44+ timediff = curtime - dcc->limit_starttime + 1;
45+ speed = ((transfd * 1000) / timediff);
46+
47+ /* reset speed counter every 30 seconds */
48+ if (timediff >= 30000) {
49+ dcc->limit_starttime = curtime;
50+ dcc->skip_bytes = dcc->transfd;
51+ }
52+
53+ return (speed > (dcc->max_speed * 1024));
54+}
55+
56+static void dcc_send_data(SEND_DCC_REC *dcc);
57+
58+static void reset_dcc_send(SEND_DCC_REC *dcc)
59+{
60+ if (g_slist_find(dcc_conns, dcc) == NULL) {
61+ /* the DCC was closed during the wait */
62+ return;
63+ }
64+
65+ if (dcc->timeout_tag != -1)
66+ g_source_remove(dcc->timeout_tag);
67+ dcc->timeout_tag = -1;
68+
69+ dcc->tagwrite = g_input_add(dcc->handle, G_INPUT_WRITE,
70+ (GInputFunction) dcc_send_data, dcc);
71+
72+ return;
73+}
74+
75 /* input function: DCC SEND - we're ready to send more data */
76 static void dcc_send_data(SEND_DCC_REC *dcc)
77 {
78 char buffer[512];
79- int ret;
80+ int ret, max_speed;
81+ GTimeVal gtv;
82+
83+ max_speed = settings_get_int("dcc_send_top_speed");
84+ if (max_speed != dcc->max_speed) {
85+ /* speed setting has changed, calculate speed from current position
86+ instead of from the start to eliminate speed boosts/slowdowns */
87+
88+ dcc->max_speed = max_speed;
89+ dcc->skip_bytes = dcc->transfd;
90+
91+ g_get_current_time(&gtv);
92+ dcc->limit_starttime = (gtv.tv_sec * 1000) + (gtv.tv_usec / 1000);
93+ }
94+
95+ if (sent_too_much(dcc)) {
96+ /* disable calling this function for 1/10th of a second. */
97+ g_source_remove(dcc->tagwrite);
98+ dcc->tagwrite = -1;
99+ dcc->timeout_tag = g_timeout_add(100, (GSourceFunc)
100+ reset_dcc_send, dcc);
101+ return;
102+ }
103
104 ret = read(dcc->fhandle, buffer, sizeof(buffer));
105 if (ret <= 0) {
106@@ -116,6 +185,7 @@
107 GIOChannel *handle;
108 IPADDR addr;
109 int port;
110+ GTimeVal gtv;
111
112 /* accept connection */
113 handle = net_accept(dcc->handle, &addr, &port);
114@@ -129,6 +199,14 @@
115 g_source_remove(dcc->tagconn);
116 net_disconnect(dcc->handle);
117
118+ dcc->timeout_tag = -1;
119+ dcc->skip_bytes = 0;
120+ dcc->max_speed = settings_get_int("dcc_send_top_speed");
121+
122+ /* get starttime in milliseconds */
123+ g_get_current_time(&gtv);
124+ dcc->limit_starttime = (gtv.tv_sec * 1000) + (gtv.tv_usec / 1000);
125+
126 dcc->starttime = time(NULL);
127 dcc->handle = handle;
128 memcpy(&dcc->addr, &addr, sizeof(IPADDR));
129@@ -246,6 +324,7 @@
130 {
131 dcc_register_type("SEND");
132 settings_add_str("dcc", "dcc_upload_path", "~");
133+ settings_add_int("dcc", "dcc_send_top_speed", 0);
134
135 signal_add("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
136 command_bind("dcc send", NULL, (SIGNAL_FUNC) cmd_dcc_send);
This page took 0.126629 seconds and 4 git commands to generate.