pidgin/pidgin

Fix file transfers failing at 99% over IRC
release-2.x.y
2022-04-15, Belgin Știrbu
82f6b5267eac
Parents 0079467afee4
Children 056267447549
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/
--- 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);