Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/os/fdtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ int zvfs_close(int fd)

zvfs_free_fd(fd);

(void)sock_obj_core_dealloc(fd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called by zsock_close() so wondering why we would need to call it again here. What kind of socket is this, a TLS one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't think we should call socket specific API here in the generic code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a TCP socket.
sock_obj_core_dealloc is indeed called by zsock_close, however with POSIX_API enabled we never reach zsock_close, and comparing the two functions the only real difference is that zsock_close actually calls sock_obj_core_dealloc, which properly closes the socket.
zsock_close does the following: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/net/lib/sockets/sockets.c#L137

Copy link
Member

@jukkar jukkar Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is now wrong if socket close is not called. Either this function should not be called at all but zsock_close() should, or the system should be configured so that the fdtable[fd].vtable->close(fdtable[fd].obj); would call the network socket close. In all cases this function should not do anything socket specific as this is a generic function that just dispatches the call to correct subsystem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would agree - the vtable call should deallocate any fs-specific object associated with the generic fd.


return res;
}

Expand Down