From ada0029d11c33cef2b2aabc9ef2902a98f574ffb Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 22 Oct 2018 14:19:29 +0200 Subject: [socket-nif] Initiation of "current reader" missing for recvfrom When calling the recvfrom function when there is no data, we should be made wait (for the specified amount of time). But this did not work because the "current reader" structure was not initiated. OTP-14831 --- erts/emulator/nifs/common/socket_nif.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'erts') diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 45462ff772..f9eb041ad1 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -13377,21 +13377,24 @@ BOOLEAN_T recv_check_reader(ErlNifEnv* env, } if (!compare_pids(env, &descP->currentReader.pid, &caller)) { + ERL_NIF_TERM tmp; + /* Not the "current reader", so (maybe) push onto queue */ SSDBG( descP, ("SOCKET", "recv_check_reader -> not (current) reader\r\n") ); if (!reader_search4pid(env, descP, &caller)) - *checkResult = reader_push(env, descP, caller, ref); + tmp = reader_push(env, descP, caller, ref); else - *checkResult = esock_make_error(env, esock_atom_eagain); + tmp = esock_make_error(env, esock_atom_eagain); SSDBG( descP, ("SOCKET", - "recv_check_reader -> queue (push) result: %T\r\n", - checkResult) ); - + "recv_check_reader -> queue (push) result: %T\r\n", tmp) ); + + *checkResult = tmp; + return FALSE; } @@ -13769,6 +13772,7 @@ ERL_NIF_TERM recvfrom_check_result(ErlNifEnv* env, unsigned int fromAddrLen, ERL_NIF_TERM recvRef) { + char* xres; ERL_NIF_TERM data; SSDBG( descP, @@ -13818,6 +13822,9 @@ ERL_NIF_TERM recvfrom_check_result(ErlNifEnv* env, SSDBG( descP, ("SOCKET", "recvfrom_check_result -> eagain\r\n") ); + if ((xres = recv_init_current_reader(env, descP, recvRef)) != NULL) + return esock_make_error_str(env, xres); + SELECT(env, descP->sock, (ERL_NIF_SELECT_READ), descP, NULL, recvRef); -- cgit v1.2.3