diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-12-05 12:34:27 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-12-05 12:34:27 +0100 |
commit | d5b5f64bce3a86ae39361248da6b3b207cff2cd2 (patch) | |
tree | d8b3f33e4d2fc2ca823ac34e337040c83dff4ae9 /lib | |
parent | 088ba97a2471c97e90fe7153dff0ce119faab4ef (diff) |
FTP: close callback fix
Keep track of which sockets that are the result of accept() calls and
refuse to call the closesocket callback for those sockets. Test case 596
now verifies that the open socket callback is called the same number of
times as the closed socket callback for active FTP connections.
Bug: http://curl.haxx.se/mail/lib-2011-12/0018.html
Reported by: Gokhan Sengun
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connect.c | 12 | ||||
-rw-r--r-- | lib/ftp.c | 1 | ||||
-rw-r--r-- | lib/urldata.h | 3 |
3 files changed, 11 insertions, 5 deletions
diff --git a/lib/connect.c b/lib/connect.c index 445261754..a560c4d3b 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -1110,10 +1110,14 @@ curl_socket_t Curl_getconnectinfo(struct SessionHandle *data, int Curl_closesocket(struct connectdata *conn, curl_socket_t sock) { - if(conn && conn->fclosesocket) - return conn->fclosesocket(conn->closesocket_client, sock); - else - return sclose(sock); + if(conn && conn->fclosesocket) { + if((sock != conn->sock[SECONDARYSOCKET]) || + !conn->sock_accepted[SECONDARYSOCKET]) + /* if this socket matches the second socket, and that was created with + accept, then we MUST NOT call the callback */ + return conn->fclosesocket(conn->closesocket_client, sock); + } + return sclose(sock); } /* @@ -368,6 +368,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn) conn->sock[SECONDARYSOCKET] = s; curlx_nonblock(s, TRUE); /* enable non-blocking */ + conn->sock_accepted[SECONDARYSOCKET] = TRUE; return CURLE_OK; } /* switch() */ } diff --git a/lib/urldata.h b/lib/urldata.h index 55f0a7b85..53df18cab 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -816,7 +816,8 @@ struct connectdata { struct timeval created; /* creation time */ curl_socket_t sock[2]; /* two sockets, the second is used for the data transfer when doing FTP */ - + bool sock_accepted[2]; /* TRUE if the socket on this index was created with + accept() */ Curl_recv *recv[2]; Curl_send *send[2]; |