serenity icon indicating copy to clipboard operation
serenity copied to clipboard

LibCore: Add fd() and address() accessors to Core::TCPSocket

Open pdelagrave opened this issue 1 year ago • 0 comments

It wasn't possible to obtain the SocketAddress or fd used by a TCPSocket. Accessing these values makes it possible to use non-blocking sockets with the class. Non-blocking use cases at the moment require direct usage of syscalls and knowledge of the fd. Mixing this with a TCPSocket is only convenient if we have TCPSocket::fd().

TCPSocket::adopt_fd() allowed the class to be instantiated with a non-connected fd; this was inconsistent because the class offers no way to initiate a connection once instantiated.

A TCPSocket without a SocketAddress wouldn't make sense, so it's safe and very convenient to have it as a member and make it accessible.

The need for these changes was brought forward by an upcoming SerenityOS BitTorrent client implementation PR making heavy use of non-blocking TCPSocket.

pdelagrave avatar Jun 29 '23 14:06 pdelagrave