Fri, 15 Apr 2022 13:21:50 -0500
Fix file transfers failing at 99% over IRC
File transfers over IRC sometimes failed because the sender `close()`d the socket before reading everything from it, resulting in a TCP RST packet being sent, which was interpreted by the receiver as a problem with the connection, sometimes dropping the last few bytes of the file as a result.
This patch reads everything from the socket before closing, thus avoiding the RST packet issue.
Testing Done:
Tested on Windows, Linux, Windows-to-Linux and vice-versa IRC file transfers.
Bugs closed: PIDGIN-15893
Reviewed at https://reviews.imfreedom.org/r/1385/
| libpurple/ft.c | file | annotate | diff | comparison | revisions |
--- a/libpurple/ft.c Fri Apr 15 11:29:11 2022 -0500 +++ b/libpurple/ft.c Fri Apr 15 13:21:50 2022 -0500 @@ -1545,6 +1545,19 @@ begin_transfer(xfer, cond); } +static void +purple_xfer_drain_socket(int sock) +{ + int ret; + char buffer[64]; + + do { + ret = read(sock, buffer, sizeof(buffer)); + } while(ret > 0 || + (ret == -1 && + (errno == EAGAIN || errno == EWOULDBLOCK))); +} + void purple_xfer_end(PurpleXfer *xfer) { @@ -1565,8 +1578,10 @@ xfer->watcher = 0; } - if (xfer->fd != -1) + if (xfer->fd != -1) { + purple_xfer_drain_socket(xfer->fd); close(xfer->fd); + } if (xfer->dest_fp != NULL) { fclose(xfer->dest_fp);