Skip to content

Commit

Permalink
Merge branch 'bmk/erts/esock/socket_close_and_error_codes/OTP-18669' …
Browse files Browse the repository at this point in the history
…into maint
  • Loading branch information
bmk committed Jul 6, 2023
2 parents f1c2037 + 19dbabb commit 2b5726e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
12 changes: 12 additions & 0 deletions erts/emulator/nifs/common/socket_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,18 @@ ERL_NIF_TERM esock_errno_to_term(ErlNifEnv* env, int err)
break;
#endif

#if defined(ERROR_NOT_FOUND)
case ERROR_NOT_FOUND:
return MKA(env, "not_found");
break;
#endif

#if defined(ERROR_NETWORK_UNREACHABLE)
case ERROR_NETWORK_UNREACHABLE:
return MKA(env, "network_unreachable");
break;
#endif

#if defined(ERROR_PORT_UNREACHABLE)
case ERROR_PORT_UNREACHABLE:
return MKA(env, "port_unreachable");
Expand Down
28 changes: 19 additions & 9 deletions erts/emulator/nifs/win32/win_socket_asyncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -4828,7 +4828,12 @@ extern
ERL_NIF_TERM esaio_close(ErlNifEnv* env,
ESockDescriptor* descP)
{
if (! IS_OPEN(descP->readState)) {
SSDBG( descP,
("WIN-ESAIO",
"esaio_close(%d) -> begin closing\r\n",
descP->sock) );

if (! IS_OPEN(descP->readState)) {
/* A bit of cheeting; maybe not closed yet - do we need a queue? */
return esock_make_error_closed(env);
}
Expand Down Expand Up @@ -4902,12 +4907,14 @@ BOOLEAN_T do_stop(ErlNifEnv* env,
* (will result in OPERATION_ABORTED for the threads).
*/
if (! CancelIoEx((HANDLE) descP->sock, NULL) ) {
int save_errno = sock_errno();
int save_errno = sock_errno();
ERL_NIF_TERM ereason = ENO2T(env, save_errno);

SSDBG( descP,
("WIN-ESAIO",
"do_stop {%d} -> cancel I/O failed: %s (%d)\r\n",
descP->sock, erl_errno_id(save_errno), save_errno) );
"do_stop {%d} -> cancel I/O failed: "
"\r\n %T\r\n",
descP->sock, ereason) );

/* Only issue an error message for errors *other* than
* 'not found' (since 'not found' means there is no active
Expand All @@ -4917,10 +4924,9 @@ BOOLEAN_T do_stop(ErlNifEnv* env,
if (save_errno != ERROR_NOT_FOUND)
esock_error_msg("Failed cancel outstanding I/O operations:"
"\r\n Socket: " SOCKET_FORMAT_STR
"\r\n Reason: %s (%d)"
"\r\n Reason: %T"
"\r\n",
descP->sock,
erl_errno_id(save_errno), save_errno);
descP->sock, ereason);

ret = FALSE;

Expand Down Expand Up @@ -9777,8 +9783,12 @@ void esaio_stop(ErlNifEnv* env,
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/

if (! IS_PID_UNDEF(&descP->closerPid)) {
/* We have a waiting closer process after nif_close()
if ( !IS_PID_UNDEF(&descP->closerPid) &&
(descP->closeEnv != NULL) ) {

/* We will only send this message if the user was made to
* wait (async close). In that case we have en env!
* We have a waiting closer process after nif_close()
* - send message to trigger nif_finalize_close()
*/

Expand Down

0 comments on commit 2b5726e

Please sign in to comment.