Skip to content

Commit

Permalink
CHANGE: refined the port state handle initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Oct 21, 2024
1 parent 03d349e commit 38f47f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/core/c-port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/p-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 38f47f5

Please sign in to comment.