Commit graph

7 commits

Author SHA1 Message Date
sin-ack
92be52fd9f LibCore: Implement LocalSocket::adopt_fd
Similar to File::adopt_fd, this function creates a new LocalSocket with
an existing fd. The main use of this function is to create LocalSocket
objects from fds that have been passed to us by SystemServer to take
over.
2022-01-15 13:29:48 +03:30
sin-ack
27b49a60d0 LibCore: Implement LocalSocket::read_without_waiting
This uses recv with MSG_DONTWAIT to disable blocking operation for a
single call. LibIPC uses this to read in a non-blocking manner from an
otherwise blocking socket.
2022-01-15 13:29:48 +03:30
sin-ack
f9847372f3 LibCore: Implement LocalSocket::receive_fd and send_fd
These are just wrappers over the sendfd and recvfd syscalls.
2022-01-15 13:29:48 +03:30
sin-ack
5f645e84d8 LibCore: Use Error::from_errno in Stream APIs
This makes Stream APIs work with Lagom and is overall cleaner.
2022-01-13 15:16:12 +03:30
sin-ack
dbd25916a3 LibCore+Userland+Tests: Convert Stream APIs to construct on heap
As per previous discussion, it was decided that the Stream classes
should be constructed on the heap.

While I don't personally agree with this change, it does have the
benefit of avoiding Function object reconstructions due to the lambda
passed to Notifier pointing to a stale object reference. This also has
the benefit of not having to "box" objects for virtual usage, as the
objects come pre-boxed.

However, it means that we now hit the heap everytime we construct a
TCPSocket for instance, which might not be desirable.
2022-01-13 15:16:12 +03:30
sin-ack
eb389db92c LibCore: Remove the SocketError class
SocketError is a relic from the KResult days when we couldn't have a
string in the KResult type, only an errno. Now that we can use string
literals with Error, it's no longer necessary. gai_strerror is thread
safe, so we can use it here unlike strerror.
2022-01-13 15:16:12 +03:30
sin-ack
19e13117ad LibCore: Implement the Serenity Stream API classes
The Serenity Stream API is the name for the new set of classes intended
to replace IODevice and its descendants. It provides more flexibility
for subclasses by allowing each subclass to override all the possible
functionalities according to their wishes.

Stream is the base class which implements majority of the functionality
expected from a readable and writable stream. SeekableStream adds
seeking on top, and provides a couple utility methods which derive from
seek. Socket adds a couple of BSD socket utility functions such as
checking whether there is data available to read and checking the
pending bytes on the socket.

As for the concrete classes, there is File which is a SeekableStream and
is intended to operate on file-like objects; and TCPSocket, UDPSocket
and LocalSocket, which handle TCP, UDP and UNIX sockets respectively.

The concrete classes do not do buffering by default. For buffering
functionality, a set of augmentative classes named BufferedSeekable and
BufferedSocket have been implemented, intended to wrap a SeekableStream
and a Socket, respectively.
2021-12-16 22:21:35 +03:30