summaryrefslogtreecommitdiffstats
path: root/src/device.c
diff options
context:
space:
mode:
authorGravatar Satoshi Ohgoh2014-07-29 12:04:18 +0900
committerGravatar Martin Szulecki2014-09-19 19:02:55 +0200
commit2f6d9d5f7047d4dd5ea9970721ba902301621ab2 (patch)
tree3b007b0c73ef9cd1159c2a2c1e3acd1296b3e6e4 /src/device.c
parent4da0a2f6f5e9634dd1dd99a8faf3374e8cfc6b1c (diff)
downloadusbmuxd-2f6d9d5f7047d4dd5ea9970721ba902301621ab2.tar.gz
usbmuxd-2f6d9d5f7047d4dd5ea9970721ba902301621ab2.tar.bz2
Flush input buffer for a client connection when calling connection_teardown().
Signed-off-by: Martin Szulecki <m.szulecki@libimobiledevice.org>
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c
index 9f45ea9..ec0c9f2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -300,6 +300,7 @@ static int send_tcp(struct mux_connection *conn, uint8_t flags, const unsigned c
static void connection_teardown(struct mux_connection *conn)
{
int res;
+ int size;
if(conn->state == CONN_DEAD)
return;
usbmuxd_log(LL_DEBUG, "connection_teardown dev %d sport %d dport %d", conn->dev->id, conn->sport, conn->dport);
@@ -313,6 +314,21 @@ static void connection_teardown(struct mux_connection *conn)
client_notify_connect(conn->client, RESULT_CONNREFUSED);
} else {
conn->state = CONN_DEAD;
+ if((conn->events & POLLOUT) && conn->ib_size > 0){
+ while(1){
+ size = client_write(conn->client, conn->ib_buf, conn->ib_size);
+ if(size <= 0) {
+ break;
+ }
+ if(size == (int)conn->ib_size) {
+ conn->ib_size = 0;
+ break;
+ } else {
+ conn->ib_size -= size;
+ memmove(conn->ib_buf, conn->ib_buf + size, conn->ib_size);
+ }
+ }
+ }
client_close(conn->client);
}
}