Skip to content

Commit

Permalink
multi: inform about closed sockets before they are closed
Browse files Browse the repository at this point in the history
When the connection code decides to close a socket it informs the multi
system via the Curl_multi_closed function. The multi system may, in
turn, invoke the CURLMOPT_SOCKETFUNCTION function with
CURL_POLL_REMOVE. This happens after the socket has already been
closed. Reorder the code so that CURL_POLL_REMOVE is called before the
socket is closed.
  • Loading branch information
jhs67 authored and bagder committed Nov 19, 2014
1 parent cf510ad commit 2933698
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/connect.c
Expand Up @@ -1244,12 +1244,13 @@ int Curl_closesocket(struct connectdata *conn,
else
return conn->fclosesocket(conn->closesocket_client, sock);
}
sclose(sock);

if(conn)
/* tell the multi-socket code about this */
Curl_multi_closed(conn, sock);

sclose(sock);

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/multi.c
Expand Up @@ -2115,7 +2115,7 @@ static void singlesocket(struct Curl_multi *multi,
* Curl_multi_closed()
*
* Used by the connect code to tell the multi_socket code that one of the
* sockets we were using have just been closed. This function will then
* sockets we were using is about to be closed. This function will then
* remove it from the sockethash for this handle to make the multi_socket API
* behave properly, especially for the case when libcurl will create another
* socket again and it gets the same file descriptor number.
Expand Down
2 changes: 1 addition & 1 deletion lib/multiif.h
Expand Up @@ -82,7 +82,7 @@ size_t Curl_multi_max_total_connections(struct Curl_multi *multi);
* Curl_multi_closed()
*
* Used by the connect code to tell the multi_socket code that one of the
* sockets we were using have just been closed. This function will then
* sockets we were using is about to be closed. This function will then
* remove it from the sockethash for this handle to make the multi_socket API
* behave properly, especially for the case when libcurl will create another
* socket again and it gets the same file descriptor number.
Expand Down

0 comments on commit 2933698

Please sign in to comment.