Skip to content

Commit

Permalink
Flush input buffer for a client connection when calling connection_te…
Browse files Browse the repository at this point in the history
…ardown().

Signed-off-by: Martin Szulecki <[email protected]>
  • Loading branch information
sohgoh authored and FunkyM committed Sep 19, 2014
1 parent 4da0a2f commit 2f6d9d5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 2f6d9d5

Please sign in to comment.