diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 58d86e583..a2fd53c31 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -29,6 +29,7 @@ New features:: * relay: add option relay.weechat.commands (issue #928) * script: use SHA-512 instead of MD5 for script checksum * spell: rename aspell plugin to spell (issue #1299) + * xfer: rename option xfer.network.speed_limit to xfer.network.speed_limit_send, add option xfer.network.speed_limit_recv (issue #269) Bug fixes:: diff --git a/ReleaseNotes.adoc b/ReleaseNotes.adoc index f8b55be3a..156987c47 100644 --- a/ReleaseNotes.adoc +++ b/ReleaseNotes.adoc @@ -20,6 +20,17 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog] [[v2.5]] == Version 2.5 (under dev) +[[v2.5_xfer_option_speed_limit]] +=== Speed limit option for DCC files + +The option _xfer.network.speed_limit_ has been renamed to +_xfer.network.speed_limit_send_. + +If you changed the value of this option, you must set it again after upgrade. + +A new option _xfer.network.speed_limit_recv_ has been added to limit the +speed of received files. + [[v2.5_aspell_plugin_renamed]] === Aspell plugin renamed to Spell diff --git a/doc/de/autogen/user/xfer_options.adoc b/doc/de/autogen/user/xfer_options.adoc index 384e7df67..246ea10a3 100644 --- a/doc/de/autogen/user/xfer_options.adoc +++ b/doc/de/autogen/user/xfer_options.adoc @@ -164,7 +164,13 @@ ** Werte: on, off ** Standardwert: `+on+` -* [[option_xfer.network.speed_limit]] *xfer.network.speed_limit* +* [[option_xfer.network.speed_limit_recv]] *xfer.network.speed_limit_recv* +** Beschreibung: pass:none[speed limit for receiving files, in kilo-bytes by second (0 means no limit)] +** Typ: integer +** Werte: 0 .. 2147483647 +** Standardwert: `+0+` + +* [[option_xfer.network.speed_limit_send]] *xfer.network.speed_limit_send* ** Beschreibung: pass:none[Begrenzt die Übertragungsgeschwindigkeit beim Versenden, in Kilobytes pro Sekunde (0 = keine Begrenzung)] ** Typ: integer ** Werte: 0 .. 2147483647 diff --git a/doc/en/autogen/user/xfer_options.adoc b/doc/en/autogen/user/xfer_options.adoc index b41f67b26..d6e502055 100644 --- a/doc/en/autogen/user/xfer_options.adoc +++ b/doc/en/autogen/user/xfer_options.adoc @@ -164,7 +164,13 @@ ** values: on, off ** default value: `+on+` -* [[option_xfer.network.speed_limit]] *xfer.network.speed_limit* +* [[option_xfer.network.speed_limit_recv]] *xfer.network.speed_limit_recv* +** description: pass:none[speed limit for receiving files, in kilo-bytes by second (0 means no limit)] +** type: integer +** values: 0 .. 2147483647 +** default value: `+0+` + +* [[option_xfer.network.speed_limit_send]] *xfer.network.speed_limit_send* ** description: pass:none[speed limit for sending files, in kilo-bytes by second (0 means no limit)] ** type: integer ** values: 0 .. 2147483647 diff --git a/doc/fr/autogen/user/xfer_options.adoc b/doc/fr/autogen/user/xfer_options.adoc index 56c189926..89cf9da7d 100644 --- a/doc/fr/autogen/user/xfer_options.adoc +++ b/doc/fr/autogen/user/xfer_options.adoc @@ -164,7 +164,13 @@ ** valeurs: on, off ** valeur par défaut: `+on+` -* [[option_xfer.network.speed_limit]] *xfer.network.speed_limit* +* [[option_xfer.network.speed_limit_recv]] *xfer.network.speed_limit_recv* +** description: pass:none[limitation de vitesse pour la réception de fichiers, en kilo-octets par seconde (0 signifie pas de limite)] +** type: entier +** valeurs: 0 .. 2147483647 +** valeur par défaut: `+0+` + +* [[option_xfer.network.speed_limit_send]] *xfer.network.speed_limit_send* ** description: pass:none[limitation de vitesse pour l'envoi des fichiers, en kilo-octets par seconde (0 signifie pas de limite)] ** type: entier ** valeurs: 0 .. 2147483647 diff --git a/doc/it/autogen/user/xfer_options.adoc b/doc/it/autogen/user/xfer_options.adoc index 425be6757..e10746396 100644 --- a/doc/it/autogen/user/xfer_options.adoc +++ b/doc/it/autogen/user/xfer_options.adoc @@ -164,7 +164,13 @@ ** valori: on, off ** valore predefinito: `+on+` -* [[option_xfer.network.speed_limit]] *xfer.network.speed_limit* +* [[option_xfer.network.speed_limit_recv]] *xfer.network.speed_limit_recv* +** descrizione: pass:none[speed limit for receiving files, in kilo-bytes by second (0 means no limit)] +** tipo: intero +** valori: 0 .. 2147483647 +** valore predefinito: `+0+` + +* [[option_xfer.network.speed_limit_send]] *xfer.network.speed_limit_send* ** descrizione: pass:none[limite di velocità per l'invio dei file, in kb per secondo (0 vuol dire senza limite)] ** tipo: intero ** valori: 0 .. 2147483647 diff --git a/doc/ja/autogen/user/xfer_options.adoc b/doc/ja/autogen/user/xfer_options.adoc index 747e0bd35..56ef39218 100644 --- a/doc/ja/autogen/user/xfer_options.adoc +++ b/doc/ja/autogen/user/xfer_options.adoc @@ -164,7 +164,13 @@ ** 値: on, off ** デフォルト値: `+on+` -* [[option_xfer.network.speed_limit]] *xfer.network.speed_limit* +* [[option_xfer.network.speed_limit_recv]] *xfer.network.speed_limit_recv* +** 説明: pass:none[speed limit for receiving files, in kilo-bytes by second (0 means no limit)] +** タイプ: 整数 +** 値: 0 .. 2147483647 +** デフォルト値: `+0+` + +* [[option_xfer.network.speed_limit_send]] *xfer.network.speed_limit_send* ** 説明: pass:none[ファイル送信の速度制限、1 秒あたりのキロバイトで指定 (0 は制限無し)] ** タイプ: 整数 ** 値: 0 .. 2147483647 diff --git a/doc/pl/autogen/user/xfer_options.adoc b/doc/pl/autogen/user/xfer_options.adoc index 6c4def9e9..4c9bfd8e2 100644 --- a/doc/pl/autogen/user/xfer_options.adoc +++ b/doc/pl/autogen/user/xfer_options.adoc @@ -164,7 +164,13 @@ ** wartości: on, off ** domyślna wartość: `+on+` -* [[option_xfer.network.speed_limit]] *xfer.network.speed_limit* +* [[option_xfer.network.speed_limit_recv]] *xfer.network.speed_limit_recv* +** opis: pass:none[speed limit for receiving files, in kilo-bytes by second (0 means no limit)] +** typ: liczba +** wartości: 0 .. 2147483647 +** domyślna wartość: `+0+` + +* [[option_xfer.network.speed_limit_send]] *xfer.network.speed_limit_send* ** opis: pass:none[limit prędkości wysyłania plików, w kilobajtach na sekundę (0 oznacza brak limitu)] ** typ: liczba ** wartości: 0 .. 2147483647 diff --git a/po/cs.po b/po/cs.po index 05a77c725..5d6084f93 100644 --- a/po/cs.po +++ b/po/cs.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-17 18:32+0100\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: weechat-dev \n" @@ -12588,6 +12588,13 @@ msgstr "" "rychlostní limit pro posílání souboru, v kilobytech za sekundu (0 znamená " "žádný limit)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"rychlostní limit pro posílání souboru, v kilobytech za sekundu (0 znamená " +"žádný limit)" + msgid "timeout for xfer request (in seconds)" msgstr "časový limit pro xfer požadavek (v sekundách)" diff --git a/po/de.po b/po/de.po index 9f967801a..5d6112236 100644 --- a/po/de.po +++ b/po/de.po @@ -24,7 +24,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-04-02 21:50+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -14721,6 +14721,13 @@ msgstr "" "Begrenzt die Übertragungsgeschwindigkeit beim Versenden, in Kilobytes pro " "Sekunde (0 = keine Begrenzung)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"Begrenzt die Übertragungsgeschwindigkeit beim Versenden, in Kilobytes pro " +"Sekunde (0 = keine Begrenzung)" + msgid "timeout for xfer request (in seconds)" msgstr "Zeitüberschreitung bei Transferanfrage (in Sekunden)" diff --git a/po/es.po b/po/es.po index a6c105d2d..1730b096d 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-17 16:04+0100\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -12874,6 +12874,12 @@ msgid "" msgstr "" "límite de velocidad al enviar archivos, en kb/s (0 significa sin límite)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"límite de velocidad al enviar archivos, en kb/s (0 significa sin límite)" + msgid "timeout for xfer request (in seconds)" msgstr "" "tiempo máximo de espera para una petición de transferencia (en segundos)" diff --git a/po/fr.po b/po/fr.po index 6a2207dd0..f4f8629b1 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" -"PO-Revision-Date: 2019-03-31 16:30+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" +"PO-Revision-Date: 2019-04-06 14:04+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" "Language: fr\n" @@ -14417,6 +14417,12 @@ msgstr "" "limitation de vitesse pour l'envoi des fichiers, en kilo-octets par seconde " "(0 signifie pas de limite)" +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"limitation de vitesse pour la réception de fichiers, en kilo-octets par " +"seconde (0 signifie pas de limite)" + msgid "timeout for xfer request (in seconds)" msgstr "délai d'attente pour la requête xfer (en secondes)" diff --git a/po/hu.po b/po/hu.po index 11506f32b..ec2954a23 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-02-28 20:18+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -11861,6 +11861,10 @@ msgid "" "speed limit for sending files, in kilo-bytes by second (0 means no limit)" msgstr "" +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "timeout for xfer request (in seconds)" msgstr "dcc kérések időkorlátja (másodpercben)" diff --git a/po/it.po b/po/it.po index e6cc88005..671fe9fdd 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-17 16:04+0100\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -13093,6 +13093,13 @@ msgstr "" "limite di velocità per l'invio dei file, in kb per secondo (0 vuol dire " "senza limite)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"limite di velocità per l'invio dei file, in kb per secondo (0 vuol dire " +"senza limite)" + msgid "timeout for xfer request (in seconds)" msgstr "timeout per la richiesta xfer (in secondi)" diff --git a/po/ja.po b/po/ja.po index 919ddda83..5cc5710dd 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-04-01 09:00+0900\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" "Language-Team: Polish \n" @@ -14098,6 +14098,13 @@ msgstr "" "limit prędkości wysyłania plików, w kilobajtach na sekundę (0 oznacza brak " "limitu)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"limit prędkości wysyłania plików, w kilobajtach na sekundę (0 oznacza brak " +"limitu)" + msgid "timeout for xfer request (in seconds)" msgstr "czas oczekiwania na żądanie xfer (w sekundach)" diff --git a/po/pt.po b/po/pt.po index 723f31fa7..37a091b35 100644 --- a/po/pt.po +++ b/po/pt.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-21 23:33+0100\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese <>\n" @@ -13743,6 +13743,13 @@ msgstr "" "limite de velocidade ao enviar ficheiros, em kilo-bytes por segundo (0 " "significa sem limite)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"limite de velocidade ao enviar ficheiros, em kilo-bytes por segundo (0 " +"significa sem limite)" + msgid "timeout for xfer request (in seconds)" msgstr "tempo limite para um pedido xfer (em segundos)" diff --git a/po/pt_BR.po b/po/pt_BR.po index 6a3627e08..21b610f30 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-11 21:10+0100\n" "Last-Translator: Eduardo Elias \n" "Language-Team: weechat-dev \n" @@ -12329,6 +12329,13 @@ msgstr "" "taxa máxima de transferência para enviar arquivos, em kilo-bytes por segundo " "(0 significa ilimitado)" +#, fuzzy +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" +"taxa máxima de transferência para enviar arquivos, em kilo-bytes por segundo " +"(0 significa ilimitado)" + msgid "timeout for xfer request (in seconds)" msgstr "limite de tempo para requisição de transferência (em segundos)" diff --git a/po/ru.po b/po/ru.po index b327bf392..57ae718ff 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-11 21:10+0100\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -11893,6 +11893,10 @@ msgid "" "speed limit for sending files, in kilo-bytes by second (0 means no limit)" msgstr "" +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" + #, fuzzy msgid "timeout for xfer request (in seconds)" msgstr "таймаут запросов dcc-соединений (в секундах)" diff --git a/po/tr.po b/po/tr.po index f28a92387..fe6964b27 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2019-03-17 16:04+0100\n" "Last-Translator: Hasan Kiran \n" "Language-Team: weechat-dev \n" @@ -10860,6 +10860,10 @@ msgid "" "speed limit for sending files, in kilo-bytes by second (0 means no limit)" msgstr "" +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" + msgid "timeout for xfer request (in seconds)" msgstr "" diff --git a/po/weechat.pot b/po/weechat.pot index fbfe4e382..8fdea6c30 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-03-31 23:52+0200\n" +"POT-Creation-Date: 2019-04-06 14:03+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -10690,6 +10690,10 @@ msgid "" "speed limit for sending files, in kilo-bytes by second (0 means no limit)" msgstr "" +msgid "" +"speed limit for receiving files, in kilo-bytes by second (0 means no limit)" +msgstr "" + msgid "timeout for xfer request (in seconds)" msgstr "" diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c index 9624dd61f..ddab21d82 100644 --- a/src/plugins/xfer/xfer-config.c +++ b/src/plugins/xfer/xfer-config.c @@ -50,7 +50,8 @@ struct t_config_option *xfer_config_network_fast_send; struct t_config_option *xfer_config_network_own_ip; struct t_config_option *xfer_config_network_port_range; struct t_config_option *xfer_config_network_send_ack; -struct t_config_option *xfer_config_network_speed_limit; +struct t_config_option *xfer_config_network_speed_limit_send; +struct t_config_option *xfer_config_network_speed_limit_recv; struct t_config_option *xfer_config_network_timeout; /* xfer config, file section */ @@ -294,13 +295,20 @@ xfer_config_init () "the acks are not sent immediately to the sender"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - xfer_config_network_speed_limit = weechat_config_new_option ( + xfer_config_network_speed_limit_send = weechat_config_new_option ( xfer_config_file, ptr_section, - "speed_limit", "integer", + "speed_limit_send", "integer", N_("speed limit for sending files, in kilo-bytes by second (0 means " "no limit)"), NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + xfer_config_network_speed_limit_recv = weechat_config_new_option ( + xfer_config_file, ptr_section, + "speed_limit_recv", "integer", + N_("speed limit for receiving files, in kilo-bytes by second (0 means " + "no limit)"), + NULL, 0, INT_MAX, "0", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_network_timeout = weechat_config_new_option ( xfer_config_file, ptr_section, "timeout", "integer", diff --git a/src/plugins/xfer/xfer-config.h b/src/plugins/xfer/xfer-config.h index f8f224a5a..2a31f0408 100644 --- a/src/plugins/xfer/xfer-config.h +++ b/src/plugins/xfer/xfer-config.h @@ -40,7 +40,8 @@ extern struct t_config_option *xfer_config_network_fast_send; extern struct t_config_option *xfer_config_network_own_ip; extern struct t_config_option *xfer_config_network_port_range; extern struct t_config_option *xfer_config_network_send_ack; -extern struct t_config_option *xfer_config_network_speed_limit; +extern struct t_config_option *xfer_config_network_speed_limit_send; +extern struct t_config_option *xfer_config_network_speed_limit_recv; extern struct t_config_option *xfer_config_network_timeout; extern struct t_config_option *xfer_config_file_auto_accept_chats; diff --git a/src/plugins/xfer/xfer-dcc.c b/src/plugins/xfer/xfer-dcc.c index 7b6f74033..13306c96d 100644 --- a/src/plugins/xfer/xfer-dcc.c +++ b/src/plugins/xfer/xfer-dcc.c @@ -49,11 +49,11 @@ void xfer_dcc_send_file_child (struct t_xfer *xfer) { - int num_read, num_sent, blocksize; + int num_read, num_sent; static char buffer[XFER_BLOCKSIZE_MAX]; uint32_t ack; time_t last_sent, new_time, last_second, sent_ok; - unsigned long long sent_last_second; + unsigned long long blocksize, speed_limit, sent_last_second; /* empty file? just return immediately */ if (xfer->pos >= xfer->size) @@ -63,15 +63,15 @@ xfer_dcc_send_file_child (struct t_xfer *xfer) return; } - 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; - } + speed_limit = (unsigned long long)weechat_config_integer ( + xfer_config_network_speed_limit_send); + + blocksize = (unsigned long long)(xfer->blocksize); + if ((speed_limit > 0) && (blocksize > speed_limit * 1024)) + blocksize = speed_limit * 1024; last_sent = time (NULL); - last_second = time (NULL); + last_second = last_sent; sent_ok = 0; sent_last_second = 0; while (1) @@ -113,8 +113,7 @@ xfer_dcc_send_file_child (struct t_xfer *xfer) if ((xfer->pos < xfer->size) && (xfer->fast_send || (xfer->pos <= xfer->ack))) { - if ((weechat_config_integer (xfer_config_network_speed_limit) > 0) - && (sent_last_second >= (unsigned long long)weechat_config_integer (xfer_config_network_speed_limit) * 1024)) + if ((speed_limit > 0) && (sent_last_second >= speed_limit * 1024)) { /* we're sending too fast (according to speed limit set by user) */ usleep (100); @@ -311,13 +310,20 @@ xfer_dcc_recv_file_child (struct t_xfer *xfer) { int flags, num_read, ready; static char buffer[XFER_BLOCKSIZE_MAX]; - time_t last_sent, new_time; - unsigned long long pos_last_ack; + time_t last_sent, last_second, new_time; + unsigned long long blocksize, pos_last_ack, speed_limit, recv_last_second; struct pollfd poll_fd; ssize_t written, total_written; unsigned char *bin_hash; char hash[9]; + speed_limit = (unsigned long long)weechat_config_integer ( + xfer_config_network_speed_limit_recv); + + blocksize = sizeof (buffer); + if ((speed_limit > 0) && (blocksize > speed_limit * 1024)) + blocksize = speed_limit * 1024; + /* if resuming, hash the portion of the file we have */ if ((xfer->start_resume > 0) && xfer->hash_handle) { @@ -361,6 +367,8 @@ xfer_dcc_recv_file_child (struct t_xfer *xfer) fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK); last_sent = time (NULL); + last_second = last_sent; + recv_last_second = 0; pos_last_ack = 0; while (1) @@ -385,113 +393,132 @@ xfer_dcc_recv_file_child (struct t_xfer *xfer) /* read maximum data on socket (until nothing is available) */ while (1) { - num_read = recv (xfer->sock, buffer, sizeof (buffer), 0); - if (num_read == -1) + if ((speed_limit > 0) && (recv_last_second >= speed_limit * 1024)) { - if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR)) - { - xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, - XFER_ERROR_RECV_BLOCK); - return; - } /* - * no more data available on socket: exit loop, send ACK, and - * wait for new data on socket + * we're receiving too fast + * (according to speed limit set by user) */ - break; + usleep (100); } else { - if ((num_read == 0) && (xfer->pos < xfer->size)) + num_read = recv (xfer->sock, buffer, blocksize, 0); + if (num_read == -1) { - xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, - XFER_ERROR_RECV_BLOCK); - return; - } - - /* bytes received, write to disk */ - total_written = 0; - while (total_written < num_read) - { - written = write (xfer->file, - buffer + total_written, - num_read - total_written); - if (written < 0) + if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR)) { - if (errno == EINTR) - continue; xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, - XFER_ERROR_WRITE_LOCAL); + XFER_ERROR_RECV_BLOCK); return; } - else + /* + * no more data available on socket: exit loop, send ACK, and + * wait for new data on socket + */ + break; + } + else + { + if ((num_read == 0) && (xfer->pos < xfer->size)) { + xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, + XFER_ERROR_RECV_BLOCK); + return; + } + + /* bytes received, write to disk */ + total_written = 0; + while (total_written < num_read) + { + written = write (xfer->file, + buffer + total_written, + num_read - total_written); + if (written < 0) + { + if (errno == EINTR) + continue; + xfer_network_write_pipe (xfer, XFER_STATUS_FAILED, + XFER_ERROR_WRITE_LOCAL); + return; + } + else + { + if (xfer->hash_handle) + { + gcry_md_write (*xfer->hash_handle, + buffer + total_written, + written); + } + total_written += written; + } + } + + xfer->pos += (unsigned long long) num_read; + recv_last_second += (unsigned long long) num_read; + + /* file received OK? */ + if (xfer->pos >= xfer->size) + { + /* check hash and report result to pipe */ if (xfer->hash_handle) { - gcry_md_write (*xfer->hash_handle, - buffer + total_written, - written); + gcry_md_final (*xfer->hash_handle); + bin_hash = gcry_md_read (*xfer->hash_handle, 0); + if (bin_hash) + { + snprintf (hash, sizeof (hash), "%.2X%.2X%.2X%.2X", + bin_hash[0], bin_hash[1], bin_hash[2], + bin_hash[3]); + if (weechat_strcasecmp (hash, + xfer->hash_target) == 0) + { + xfer_network_write_pipe (xfer, + XFER_STATUS_HASHED, + XFER_NO_ERROR); + } + else + { + xfer_network_write_pipe (xfer, + XFER_STATUS_HASHED, + XFER_ERROR_HASH_MISMATCH); + } + } } - total_written += written; + + fsync (xfer->file); + + /* + * extra delay before sending ACK, otherwise the send of ACK + * may fail + */ + usleep (100000); + + /* send ACK to sender without checking return code (file OK) */ + xfer_dcc_recv_file_send_ack (xfer); + + /* set status done and return */ + xfer_network_write_pipe (xfer, XFER_STATUS_DONE, + XFER_NO_ERROR); + return; } - } - xfer->pos += (unsigned long long) num_read; - - /* file received OK? */ - if (xfer->pos >= xfer->size) - { - /* check hash and report result to pipe */ - if (xfer->hash_handle) + /* update status of DCC (parent process) */ + new_time = time (NULL); + if (last_sent != new_time) { - gcry_md_final (*xfer->hash_handle); - bin_hash = gcry_md_read (*xfer->hash_handle, 0); - if (bin_hash) - { - snprintf (hash, sizeof (hash), "%.2X%.2X%.2X%.2X", - bin_hash[0], bin_hash[1], bin_hash[2], - bin_hash[3]); - if (weechat_strcasecmp (hash, - xfer->hash_target) == 0) - { - xfer_network_write_pipe (xfer, - XFER_STATUS_HASHED, - XFER_NO_ERROR); - } - else - { - xfer_network_write_pipe (xfer, - XFER_STATUS_HASHED, - XFER_ERROR_HASH_MISMATCH); - } - } + last_sent = new_time; + xfer_network_write_pipe (xfer, XFER_STATUS_ACTIVE, + XFER_NO_ERROR); } - - fsync (xfer->file); - - /* - * extra delay before sending ACK, otherwise the send of ACK - * may fail - */ - usleep (100000); - - /* send ACK to sender without checking return code (file OK) */ - xfer_dcc_recv_file_send_ack (xfer); - - /* set status done and return */ - xfer_network_write_pipe (xfer, XFER_STATUS_DONE, - XFER_NO_ERROR); - return; } + } - /* update status of DCC (parent process) */ - new_time = time (NULL); - if (last_sent != new_time) - { - last_sent = new_time; - xfer_network_write_pipe (xfer, XFER_STATUS_ACTIVE, - XFER_NO_ERROR); - } + new_time = time (NULL); + if (new_time > last_second) + { + last_second = new_time; + recv_last_second = 0; } }