summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Peter Wu2014-04-20 00:56:37 +0200
committerGravatar Nikias Bassen2014-05-07 01:46:33 +0200
commit1a57e4ad05fae295f2892e1aeae462cbaaded9a3 (patch)
tree0ed4c42ec65385fdfe8cfc11d1b67ca933754001 /src
parentb27e6ffe7233123fc99a26723443705595e925de (diff)
downloadusbmuxd-1a57e4ad05fae295f2892e1aeae462cbaaded9a3.tar.gz
usbmuxd-1a57e4ad05fae295f2892e1aeae462cbaaded9a3.tar.bz2
Fix connection abort if device buffer is full
When trying to upload a IPSW filesystem to an iPad, the process would randomly stop somewhere at 3% or 10%. It is possible that the receive buffer of the iPad is full. To prevent erroring out because size == conn->sendable == 0, skip reading from the client. There is a similar case where the clients is ready to accept data, but the device has no data to send. Apply a similar fix there. Hopefully the device is fast enough to reply in the next main loop iteration, otherwise the CPU usage of usbmux will spike because the client socket is ready while there is no data to process...
Diffstat (limited to 'src')
-rw-r--r--src/device.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/device.c b/src/device.c
index e36509e..1c8ec8c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -424,9 +424,9 @@ void device_client_process(int device_id, struct mux_client *client, short event
int res;
int size;
- if(events & POLLOUT) {
+ if((events & POLLOUT) && conn->ib_size > 0) {
// Client is ready to receive data, send what we have
- // in the client's connection buffer
+ // in the client's connection buffer (if there is any)
size = client_write(conn->client, conn->ib_buf, conn->ib_size);
if(size <= 0) {
usbmuxd_log(LL_DEBUG, "error writing to client (%d)", size);
@@ -441,9 +441,10 @@ void device_client_process(int device_id, struct mux_client *client, short event
memmove(conn->ib_buf, conn->ib_buf + size, conn->ib_size);
}
}
- if(events & POLLIN) {
+ if((events & POLLIN) && conn->sendable > 0) {
// There is inbound trafic on the client socket,
// convert it to tcp and send to the device
+ // (if the device's input buffer is not full)
size = client_read(conn->client, conn->ob_buf, conn->sendable);
if(size <= 0) {
if (size < 0) {