diff --git a/ChangeLog b/ChangeLog index 710c38351..c8d30e419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2008-05-11 +ChangeLog - 2008-06-15 Version 0.2.7 (under dev!): + * added speed limit for DCC files sending (task #6178) * new input action "set_unread_current_buffer" to set unread marker for current buffer only (task #7286) * new option "xfer.file.use_nick_in_filename" for Xfer files (task #7140) diff --git a/po/cs.po b/po/cs.po index 995ebecad..92a0bdc92 100644 --- a/po/cs.po +++ b/po/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" "PO-Revision-Date: 2007-09-06 12:44+0200\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -4488,6 +4488,10 @@ msgstr "" "IP nebo DNS adresa použitá pro odchozí dcc (pokud je prázdné použije se " "lokální IP)" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "path for writing incoming files" msgstr "cesta pro příchozí dcc soubory" diff --git a/po/de.po b/po/de.po index f78fd2509..338514258 100644 --- a/po/de.po +++ b/po/de.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" "PO-Revision-Date: 2007-09-06 12:44+0200\n" "Last-Translator: Thomas Schuetz \n" "Language-Team: weechat-dev \n" @@ -4475,6 +4475,10 @@ msgstr "" "IP- oder DNS-Adresse für ausgehenden DCC (wenn kein Wert angegeben wird, " "wird die IP des lokalen Interfaces benutzt)" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "path for writing incoming files" msgstr "Pfad für per DCC eingehende Dateien" diff --git a/po/es.po b/po/es.po index 1f2078992..85324de34 100644 --- a/po/es.po +++ b/po/es.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" "PO-Revision-Date: 2007-09-19 12:09+0200\n" "Last-Translator: Roberto González Cardenete \n" "Language-Team: weechat-dev \n" @@ -4480,6 +4480,10 @@ msgstr "" "dirección IP o DNS usado para dcc de salida (si está vacío, se utiliza la " "IP de interfaz local)" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "path for writing incoming files" msgstr "ruta para los ficheros recibidos con dcc" diff --git a/po/fr.po b/po/fr.po index efbfd7393..37423be55 100644 --- a/po/fr.po +++ b/po/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" -"PO-Revision-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" +"PO-Revision-Date: 2008-06-15 13:47+0200\n" "Last-Translator: FlashCode \n" "Language-Team: weechat-dev \n" "MIME-Version: 1.0\n" @@ -4421,6 +4421,10 @@ msgstr "" "adresse IP ou DNS utilisée pour envoyer les fichiers/discussions (si non " "renseigné, l'interface IP locale est utilisée)" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "limitation de vitesse pour l'envoi des fichiers, en kilo-octets par seconde (0 signifie pas de limite)" + msgid "path for writing incoming files" msgstr "chemin où écrire les fichiers reçus" diff --git a/po/hu.po b/po/hu.po index 89df7d2b0..ccff47986 100644 --- a/po/hu.po +++ b/po/hu.po @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" "PO-Revision-Date: 2007-10-10 18:07+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -4491,6 +4491,10 @@ msgid "" "is used)" msgstr "kimenő dcc forgalom IP/DNS-címe (ha üres, a helyi interfész IP-címe)" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "path for writing incoming files" msgstr "dcc-n beérkező fájlok helye" diff --git a/po/ru.po b/po/ru.po index a3ea5b3ea..94a5c514f 100644 --- a/po/ru.po +++ b/po/ru.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" "PO-Revision-Date: 2007-09-06 12:44+0200\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -4476,6 +4476,10 @@ msgstr "" "IP адрес или домен, используемый для исходящих DCC соединений (пустое " "значение означает текущий IP адрес)" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "path for writing incoming files" msgstr "путь для получаемых файлов" diff --git a/po/weechat.pot b/po/weechat.pot index c473e4460..dc57c1aef 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-06-01 22:03+0200\n" +"POT-Creation-Date: 2008-06-15 13:47+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3884,6 +3884,10 @@ msgid "" "is used)" msgstr "" +msgid "" +"speed limit for sending files, in kilo-bytes by second (0 means no limit)" +msgstr "" + msgid "path for writing incoming files" msgstr "" diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c index a8e6593c0..3d0f3a7ec 100644 --- a/src/plugins/xfer/xfer-config.c +++ b/src/plugins/xfer/xfer-config.c @@ -49,6 +49,7 @@ struct t_config_option *xfer_config_network_blocksize; struct t_config_option *xfer_config_network_fast_send; struct t_config_option *xfer_config_network_port_range; struct t_config_option *xfer_config_network_own_ip; +struct t_config_option *xfer_config_network_speed_limit; /* xfer config, file section */ @@ -234,6 +235,12 @@ xfer_config_init () N_("IP or DNS address used for sending files/chats " "(if empty, local interface IP is used)"), NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL); + xfer_config_network_speed_limit = weechat_config_new_option ( + xfer_config_file, ptr_section, + "speed_limit", "integer", + N_("speed limit for sending files, in kilo-bytes by second (0 means " + "no limit)"), + NULL, 0, INT_MAX, "0", NULL, NULL, NULL, NULL, NULL, NULL); ptr_section = weechat_config_new_section (xfer_config_file, "file", 0, 0, diff --git a/src/plugins/xfer/xfer-config.h b/src/plugins/xfer/xfer-config.h index 963d964ea..8450cf714 100644 --- a/src/plugins/xfer/xfer-config.h +++ b/src/plugins/xfer/xfer-config.h @@ -39,6 +39,7 @@ extern struct t_config_option *xfer_config_network_blocksize; extern struct t_config_option *xfer_config_network_fast_send; extern struct t_config_option *xfer_config_network_port_range; extern struct t_config_option *xfer_config_network_own_ip; +extern struct t_config_option *xfer_config_network_speed_limit; extern struct t_config_option *xfer_config_file_download_path; extern struct t_config_option *xfer_config_file_upload_path; diff --git a/src/plugins/xfer/xfer-dcc.c b/src/plugins/xfer/xfer-dcc.c index 97d8c51aa..c44868f3a 100644 --- a/src/plugins/xfer/xfer-dcc.c +++ b/src/plugins/xfer/xfer-dcc.c @@ -32,6 +32,8 @@ #include "../weechat-plugin.h" #include "xfer.h" +#include "xfer-config.h" +#include "xfer-file.h" #include "xfer-network.h" @@ -42,12 +44,22 @@ void xfer_dcc_send_file_child (struct t_xfer *xfer) { - int num_read, num_sent; + int num_read, num_sent, blocksize; static char buffer[XFER_BLOCKSIZE_MAX]; uint32_t ack; - time_t last_sent, new_time; + time_t last_sent, new_time, last_second; + long sent_last_second; + + blocksize = xfer->blocksize; + if (weechat_config_integer (xfer_config_network_speed_limit) > 0) + { + if (blocksize > weechat_config_integer (xfer_config_network_speed_limit) * 1024) + blocksize = weechat_config_integer (xfer_config_network_speed_limit) * 1024; + } last_sent = time (NULL); + last_second = time (NULL); + sent_last_second = 0; while (1) { /* read DCC ACK (sent by receiver) */ @@ -87,42 +99,58 @@ xfer_dcc_send_file_child (struct t_xfer *xfer) if ((xfer->pos < xfer->size) && (xfer->fast_send || (xfer->pos <= xfer->ack))) { - lseek (xfer->file, xfer->pos, SEEK_SET); - num_read = read (xfer->file, buffer, xfer->blocksize); - if (num_read < 1) + if ((weechat_config_integer (xfer_config_network_speed_limit) > 0) + && (sent_last_second >= weechat_config_integer (xfer_config_network_speed_limit) * 1024)) { - xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, - XFER_ERROR_READ_LOCAL); - return; + /* we're sending too fast (according to speed limit set by user) */ + usleep (100); } - num_sent = send (xfer->sock, buffer, num_read, 0); - if (num_sent < 0) + else { - /* socket is temporarily not available (receiver can't receive - amount of data we sent ?!) */ - if (errno == EAGAIN) - usleep (1000); - else + lseek (xfer->file, xfer->pos, SEEK_SET); + num_read = read (xfer->file, buffer, blocksize); + if (num_read < 1) { xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, - XFER_ERROR_SEND_BLOCK); + XFER_ERROR_READ_LOCAL); return; } - } - if (num_sent > 0) - { - xfer->pos += (unsigned long) num_sent; - new_time = time (NULL); - if (last_sent != new_time) + num_sent = send (xfer->sock, buffer, num_read, 0); + if (num_sent < 0) { - last_sent = new_time; - xfer_network_write_pipe (xfer, XFER_STATUS_ACTIVE, - XFER_NO_ERROR); + /* socket is temporarily not available (receiver can't receive + amount of data we sent ?!) */ + if (errno == EAGAIN) + usleep (1000); + else + { + xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, + XFER_ERROR_SEND_BLOCK); + return; + } + } + if (num_sent > 0) + { + xfer->pos += (unsigned long) num_sent; + sent_last_second += (unsigned long) num_sent; + new_time = time (NULL); + if (last_sent != new_time) + { + last_sent = new_time; + xfer_network_write_pipe (xfer, XFER_STATUS_ACTIVE, + XFER_NO_ERROR); + } } } } else usleep (1000); + + if (time (NULL) > last_second) + { + last_second = time (NULL); + sent_last_second = 0; + } } } diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c index ac81e1b36..b2424e200 100644 --- a/src/plugins/xfer/xfer-network.c +++ b/src/plugins/xfer/xfer-network.c @@ -473,9 +473,9 @@ xfer_network_connect (struct t_xfer *xfer) return 0; xfer->hook_fd = weechat_hook_fd (xfer->sock, - 1, 0, 0, - &xfer_network_fd_cb, - xfer); + 1, 0, 0, + &xfer_network_fd_cb, + xfer); /* add timeout */ if (weechat_config_integer (xfer_config_network_timeout) > 0)