aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-03-11 08:35:52 -0300
committerdequis <dx@dxzone.com.ar>2015-03-11 08:35:52 -0300
commit059b68626cba57a7c66d0257e97781cf2dfd9fca (patch)
tree181300ac47799bc334ac213db39dfb2f72511093
parentd7abbc9706e647b6e330fb2928e2b1957abdbc0c (diff)
downloadbitlbee-facebook-059b68626cba57a7c66d0257e97781cf2dfd9fca.tar.gz
bitlbee-facebook-059b68626cba57a7c66d0257e97781cf2dfd9fca.tar.bz2
bitlbee-facebook-059b68626cba57a7c66d0257e97781cf2dfd9fca.tar.xz
fb_mqtt_cb_read: change read size to be remz, hopefully fixing timeouts
It was mqtt->rbuf->len previously, the length of the bytearray, which doesn't make a lot of sense - it resulted in reading 2, 4, 8, 16, 32 bytes and when it reached a high enough number, ssl_read would either: 1. Stop because the socket buffer got empty (the main reason it kinda worked most of the time), or 2. Continue reading into the next packet And continuing to read means not just a desync but also that remz - rize (remaining bytes - read bytes) is negative, or more precisely, a huge number, since remz is unsigned. So it gets stuck reading ~2**64 bytes into that buffer, thinking it's a neverending packet, and that means not getting pongs. So it timeouts. The fix is trivial - just make it read exactly the amount of bytes it needs to read (remz), never more than that.
-rw-r--r--facebook/facebook-mqtt.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/facebook/facebook-mqtt.c b/facebook/facebook-mqtt.c
index a4dde5b..6e85b29 100644
--- a/facebook/facebook-mqtt.c
+++ b/facebook/facebook-mqtt.c
@@ -281,7 +281,7 @@ static gboolean fb_mqtt_cb_read(gpointer data, gint fd,
}
if (mqtt->remz > 0) {
- rize = ssl_read(mqtt->ssl, buf, MIN(mqtt->rbuf->len, sizeof buf));
+ rize = ssl_read(mqtt->ssl, buf, MIN(mqtt->remz, sizeof buf));
if (rize < 1)
goto error;