From 38f47f58bf2736d87fa7bbc50f0a7eda26f52d02 Mon Sep 17 00:00:00 2001 From: Oldes Huhuman Date: Mon, 21 Oct 2024 09:55:45 +0200 Subject: [PATCH] CHANGE: refined the port state handle initialization --- src/core/c-port.c | 5 +++-- src/core/p-net.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/c-port.c b/src/core/c-port.c index 636efe92a9..ed02a0ceb4 100644 --- a/src/core/c-port.c +++ b/src/core/c-port.c @@ -54,7 +54,7 @@ /*********************************************************************** ** -*/ REBVAL *Use_Port_State_Handle(REBSER *port, REBCNT device, REBCNT type) +*/ REBVAL *Use_Port_State_Handle(REBSER *port, REBCNT device) /* ** Use private state area (handle) in a port. Create if necessary. ** Returns NULL if fails to allocate the state handle. @@ -63,6 +63,7 @@ { REBREQ *req; REBVAL *state = BLK_SKIP(port, STD_PORT_STATE); + REBCNT type = SYM_PORT_STATEX; //TODO: make it per-device type instead one state type for all devices // Validate if handle has correct type and is for the expected device if (IS_HANDLE(state) && VAL_HANDLE_TYPE(state) == type) { @@ -429,7 +430,7 @@ xx*/ REBINT Wait_Device(REBREQ *req, REBCNT timeout) ***********************************************************************/ { REBSER *port = Validate_Port_Value(port_value); - REBVAL *state = Use_Port_State_Handle(port, device, SYM_PORT_STATEX); + REBVAL *state = Use_Port_State_Handle(port, device); *req = (REBREQ *)VAL_HANDLE_CONTEXT_DATA(state); return port; } diff --git a/src/core/p-net.c b/src/core/p-net.c index 5dabe76db5..65a8d55179 100644 --- a/src/core/p-net.c +++ b/src/core/p-net.c @@ -164,7 +164,7 @@ enum Transport_Types { SET_NONE(OFV(port, STD_PORT_STATE)); // just to be sure. // Copy over the new sock data: - state = Use_Port_State_Handle(port, RDI_NET, SYM_PORT_STATEX); + state = Use_Port_State_Handle(port, RDI_NET); sock = (REBREQ *)VAL_HANDLE_CONTEXT_DATA(state); *sock = *nsock; //sock->clen = sizeof(*sock); @@ -361,6 +361,7 @@ enum Transport_Types { Trap_Port(RE_CANNOT_CLOSE, port, sock->error); } SET_CLOSED(sock); + // Don't release the state as there may be pending events (sock being signaled)! //Release_Port_State(port); // Crashes on POSIX with the unit test for issue-2445! } break;