summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2014-04-13 12:52:25 +0200
committerSébastien Helleu <flashcode@flashtux.org>2014-04-13 12:52:25 +0200
commitdb912ded26f15ff64e34a4667a34d1a882d82ad9 (patch)
tree2648da96b4a287d5321f91cc2ac91924f0cee502 /src
parent417811ba018f02ec0110f1b9899e17dcd2b394f7 (diff)
downloadweechat-db912ded26f15ff64e34a4667a34d1a882d82ad9.zip
xfer: fix freeze/problems when sending empty files with DCC (closes #53)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/xfer/xfer-dcc.c13
-rw-r--r--src/plugins/xfer/xfer-network.c12
2 files changed, 14 insertions, 11 deletions
diff --git a/src/plugins/xfer/xfer-dcc.c b/src/plugins/xfer/xfer-dcc.c
index fa26f9f42..015b692be 100644
--- a/src/plugins/xfer/xfer-dcc.c
+++ b/src/plugins/xfer/xfer-dcc.c
@@ -54,6 +54,14 @@ xfer_dcc_send_file_child (struct t_xfer *xfer)
time_t last_sent, new_time, last_second, sent_ok;
unsigned long long sent_last_second;
+ /* empty file? just return immediately */
+ if (xfer->pos >= xfer->size)
+ {
+ xfer_network_write_pipe (xfer, XFER_STATUS_DONE,
+ XFER_NO_ERROR);
+ return;
+ }
+
blocksize = xfer->blocksize;
if (weechat_config_integer (xfer_config_network_speed_limit) > 0)
{
@@ -386,9 +394,7 @@ xfer_dcc_recv_file_child (struct t_xfer *xfer)
}
else
{
- total_written = 0;
-
- if (num_read == 0)
+ if ((num_read == 0) && (xfer->pos < xfer->size))
{
xfer_network_write_pipe (xfer, XFER_STATUS_FAILED,
XFER_ERROR_RECV_BLOCK);
@@ -396,6 +402,7 @@ xfer_dcc_recv_file_child (struct t_xfer *xfer)
}
/* bytes received, write to disk */
+ total_written = 0;
while (total_written < num_read)
{
written = write (xfer->file,
diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c
index d0ff2dd62..a2f06764f 100644
--- a/src/plugins/xfer/xfer-network.c
+++ b/src/plugins/xfer/xfer-network.c
@@ -225,16 +225,14 @@ xfer_network_send_file_fork (struct t_xfer *xfer)
switch (pid = fork ())
{
- /* fork failed */
- case -1:
+ case -1: /* fork failed */
weechat_printf (NULL,
_("%s%s: unable to fork"),
weechat_prefix ("error"), XFER_PLUGIN_NAME);
xfer_close (xfer, XFER_STATUS_FAILED);
xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE);
return;
- /* child process */
- case 0:
+ case 0: /* child process */
rc = setuid (getuid ());
(void) rc;
close (xfer->child_read);
@@ -298,16 +296,14 @@ xfer_network_recv_file_fork (struct t_xfer *xfer)
switch (pid = fork ())
{
- /* fork failed */
- case -1:
+ case -1: /* fork failed */
weechat_printf (NULL,
_("%s%s: unable to fork"),
weechat_prefix ("error"), XFER_PLUGIN_NAME);
xfer_close (xfer, XFER_STATUS_FAILED);
xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE);
return;
- /* child process */
- case 0:
+ case 0: /* child process */
rc = setuid (getuid ());
(void) rc;
close (xfer->child_read);