summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-05-05 00:36:34 +0200
committerGravatar Hector Martin2009-05-05 00:36:34 +0200
commitbcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6 (patch)
tree12aacaf09d16b5ce0768dc12d4c1a39d259fc661
parentad2e0ee9e0dc6750514c009a93dcf925f996baeb (diff)
downloadusbmuxd-bcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6.tar.gz
usbmuxd-bcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6.tar.bz2
Fix connection refused handling
-rw-r--r--device.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/device.c b/device.c
index ead8b9e..c6ef75b 100644
--- a/device.c
+++ b/device.c
@@ -59,6 +59,7 @@ enum mux_dev_state {
enum mux_conn_state {
CONN_CONNECTING, // SYN
CONN_CONNECTED, // SYN/SYNACK/ACK -> active
+ CONN_REFUSED, // RST received during SYN
CONN_DYING, // RST received
CONN_DEAD // being freed; used to prevent infinite recursion between client<->device freeing
};
@@ -227,13 +228,13 @@ static void connection_teardown(struct mux_connection *conn)
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);
- if(conn->dev->state != MUXDEV_DEAD && conn->state != CONN_DYING) {
+ if(conn->dev->state != MUXDEV_DEAD && conn->state != CONN_DYING && conn->state != CONN_REFUSED) {
res = send_tcp(conn, TH_RST, NULL, 0);
if(res < 0)
usbmuxd_log(LL_ERROR, "Error sending TCP RST to device %d (%d->%d)", conn->dev->id, conn->sport, conn->dport);
}
if(conn->client) {
- if(conn->state == CONN_CONNECTING) {
+ if(conn->state == CONN_REFUSED || conn->state == CONN_CONNECTING) {
client_notify_connect(conn->client, RESULT_CONNREFUSED);
} else {
conn->state = CONN_DEAD;
@@ -479,7 +480,7 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned
if(conn->state == CONN_CONNECTING) {
if(th->th_flags != (TH_SYN|TH_ACK)) {
if(th->th_flags & TH_RST)
- conn->state = CONN_DYING;
+ conn->state = CONN_REFUSED;
usbmuxd_log(LL_INFO, "Connection refused by device %d (%d->%d)", dev->id, sport, dport);
connection_teardown(conn); //this also sends the notification to the client
} else {