summaryrefslogtreecommitdiff
path: root/Kernel/Net/LocalSocket.cpp
AgeCommit message (Collapse)Author
2019-11-09Kernel+SystemMonitor: Publish can_read/write state for open filesAndreas Kling
The can_read() and can_write() states for file descriptions are now published in /proc, allowing SystemMonitor to display it.
2019-11-04Kernel: Make File's can_read/can_write take a const FileDescription&Andreas Kling
Asking a File if we could possibly read or write it will never mutate the asking FileDescription&, so it should be const.
2019-10-18Net: Put a bunch of socket debug logging behind FOO_DEBUGAndreas Kling
Also remove an unused Socket::listen() implementation.
2019-10-18Revert "Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing"Andreas Kling
This reverts commit 1cca5142afbd76833deedfdb238230ac53424855. This appears to be causing intermittent triple-faults and I don't know why yet, so I'll just revert it to keep the tree in decent shape.
2019-10-18Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ingAndreas Kling
Background: DoubleBuffer is a handy buffer class in the kernel that allows you to keep writing to it from the "outside" while the "inside" reads from it. It's used for things like LocalSocket and PTY's. Internally, it has a read buffer and a write buffer, but the two will swap places when the read buffer is exhausted (by reading from it.) Before this patch, it was internally implemented as two Vector<u8> that we would swap between when the reader side had exhausted the data in the read buffer. Now instead we preallocate a large KBuffer (64KB*2) on DoubleBuffer construction and use that throughout its lifetime. This removes all the kmalloc heap traffic caused by DoubleBuffers :^)
2019-10-08Kernel: Don't put LocalSocket in SetupState::Completed in bind()Andreas Kling
This was causing connect() to unblock immediately for local sockets, since that's exactly what ConnectBlocker checks for. Instead, just move to SetupState::Completed when it's accept()ed.
2019-09-22LocalSocket: Teach recvfrom() how to block if needed, and simplify itAndreas Kling
If we can't already read when we enter recvfrom() on a LocalSocket, we'll now block the current thread until we can. Also added a buffer_for(FileDescription&) helper so that the client and server can share some of the code. :^)
2019-08-17LocalSocket: Make recvfrom() return 0 to signal EOF when peer is goneAndreas Kling
Once the peer has disconnected, recvfrom() should always return 0 once the socket buffer has been drained.
2019-08-11Kernel: Customize absolute_path() for more file typesSergey Bugaev
2019-08-11Net: Store all the LocalSockets in an InlineLinkedListSergey Bugaev
2019-08-11Net: Add LocalSocket::socket_path()Sergey Bugaev
This is a little utility function to safely extract the path without manually dealing with sun_path and null-termination.
2019-08-11Net: Fix initializing sockaddr_un.sun_path copy buffersSergey Bugaev
The whole point of allocating an extra byte for the null terminator is to initialize it to zero.
2019-08-11Kernel: Move socket role tracking to the Socket class itselfSergey Bugaev
This is more logical and allows us to solve the problem of non-blocking TCP sockets getting stuck in SocketRole::None. The only complication is that a single LocalSocket may be shared between two file descriptions (on the connect and accept sides), and should have two different roles depending from which side you look at it. To deal with it, Socket::role() is made a virtual method that accepts a file description, and LocalSocket internally tracks which FileDescription is the which one and returns a correct role.
2019-08-11Net: Simplify how LocalSocket tracks open fdsSergey Bugaev
Now that there can't be multiple clones of the same fd, we only need to track whether or not an fd exists on each side. Also there's no point in tracking connecting fds.
2019-08-10Kernel: Use a more detailed state machine for socket setupConrad Pankoff
2019-08-06Kernel: Refactor TCP/IP stackConrad Pankoff
This has several significant changes to the networking stack. * Significant refactoring of the TCP state machine. Right now it's probably more fragile than it used to be, but handles quite a lot more of the handshake process. * `TCPSocket` holds a `NetworkAdapter*`, assigned during `connect()` or `bind()`, whichever comes first. * `listen()` is now virtual in `Socket` and intended to be implemented in its child classes * `listen()` no longer works without `bind()` - this is a bit of a regression, but listening sockets didn't work at all before, so it's not possible to observe the regression. * A file is exposed at `/proc/net_tcp`, which is a JSON document listing the current TCP sockets with a bit of metadata. * There's an `ETHERNET_VERY_DEBUG` flag for dumping packet's content out to `kprintf`. It is, indeed, _very debug_.
2019-08-05Net: Let Socket have read/write wrappers around sendto/recvfromAndreas Kling
The situations in IPv4Socket and LocalSocket were mirrors of each other where one had implemented read/write as wrappers and the other had sendto/recvfrom as wrappers. Instead of this silliness, move read and write up to the Socket base. Then mark them final, so subclasses have no choice but to implement sendto and recvfrom.
2019-07-20Net: Merge Thread::wait_for_connect into LocalSocket (as the only place that ↵Robin Burchell
uses it) Also do this more like other blockers, don't call yield ourselves, as block will do that for us.
2019-07-03AK: Rename the common integer typedefs to make it obvious what they are.Andreas Kling
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
2019-06-21AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.Andreas Kling
2019-06-13Kernel: Rename "descriptor" to "description" where appropriate.Andreas Kling
Now that FileDescription is called that, variables of that type should not be called "descriptor". This is kinda wordy but we'll get used to it.
2019-06-07Kernel: Run clang-format on everything.Andreas Kling
2019-06-07Kernel: Rename FileDescriptor to FileDescription.Andreas Kling
After reading a bunch of POSIX specs, I've learned that a file descriptor is the number that refers to a file description, not the description itself. So this patch renames FileDescriptor to FileDescription, and Process now has FileDescription* file_description(int fd).
2019-05-30Kernel: Rename Process::cwd_custody() to Process::current_directory().Andreas Kling
...and executable_custody() to just executable().
2019-05-30FileSystem: Port most of the code over to using custodies.Andreas Kling
The current working directory is now stored as a custody. Likewise for a process executable file. This unbreaks /proc/PID/fd which has not been working since we made the filesystem bigger. This still needs a bunch of work, for instance when renaming or removing a file somewhere, we have to update the relevant custody links.
2019-05-20Kernel: Add getpeername() syscall, and fix getsockname() behavior.Andreas Kling
We were copying the raw IPv4 addresses into the wrong part of sockaddr_in, and we didn't set sa_family or sa_port.
2019-05-20LocalSocket: Make send() and sendto() work, too.Andreas Kling
2019-05-20LocalSocket: Bump internal buffer sizes to 16KB.Andreas Kling
This gives us some leeway for WindowServer to queue up a bunch of messages for one of its clients. Longer-term we should improve DoubleBuffer to be able to grow dynamically in a way that gets billed to some reasonable place.
2019-05-20Kernel: Add support for recv() with MSG_DONTWAIT.Andreas Kling
Passing this flag to recv() temporarily puts the file descriptor into non-blocking mode. Also implement LocalSocket::recv() as a simple forwarding to read().
2019-05-20LocalSocket: Fix mismatch between can_write() and write() logic.Andreas Kling
can_write() was saying yes in situations where write() would overflow the internal buffer. This patch adds a has_attached_peer() helper to make it easier to understand what's going on in these functions.
2019-05-20Kernel: Report EAGAIN from read() on a non-blocking socket if the buffer is ↵Robin Burchell
empty This is not EOF, and never should have been so -- can trip up other code when porting. Also updates LibGUI and WindowServer which both relied on the old behaviour (and didn't work without changes). There may be others, but I didn't run into them with a quick inspection.
2019-05-03Kernel: Make Socket inherit from File.Andreas Kling
2019-05-03Kernel: Prepare Socket for becoming a File.Andreas Kling
Make the Socket functions take a FileDescriptor& rather than a socket role throughout the code. Also change threads to block on a FileDescriptor, rather than either an fd index or a Socket.
2019-04-29Kernel: Make FIFO inherit from File.Andreas Kling
2019-04-08Kernel: Support non-blocking connect().Andreas Kling
If connect() is called on a non-blocking socket, it will "fail" immediately with -EINPROGRESS. After that, you select() on the socket and wait for it to become writable.
2019-04-06Kernel: Move FIFO into FileSystem/ and Socket+LocalSocket into Net/.Andreas Kling