Add speed limit for DCC files sending (task #6178)
This commit is contained in:
parent
5f9763f4ad
commit
9e03812ed7
@ -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)
|
||||
|
6
po/cs.po
6
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 <golemj@gmail.com>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"
|
||||
|
6
po/de.po
6
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 <i18n@internet-villa.de>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"
|
||||
|
6
po/es.po
6
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 <robert.glez@gmail.com>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"
|
||||
|
8
po/fr.po
8
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 <flashcode@flashtux.org>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"
|
||||
|
||||
|
6
po/hu.po
6
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 <voroskoi@frugalware.org>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"
|
||||
|
6
po/ru.po
6
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 <stlwrt@gmail.com>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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 "путь для получаемых файлов"
|
||||
|
@ -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 <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\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 ""
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user