diff options
author | Anton Kling <anton@kling.gg> | 2024-07-04 20:09:51 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-07-04 20:10:47 +0200 |
commit | afc2b4d4766b0e4ee8519ac6fcd98353d3864322 (patch) | |
tree | 65094046734586e5f2da5d553305103ebb87a34f /kernel/socket.c | |
parent | f89eef4733b7905dbf362cbde9aebb2dd0dcfe7d (diff) |
TCP: Allow delay for sends
This is not at all optimal for applications that already buffer their
data but can have a huge impact on those that don't. Applications that
don't wish to use this should disable this for their socket.
Diffstat (limited to 'kernel/socket.c')
-rw-r--r-- | kernel/socket.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/kernel/socket.c b/kernel/socket.c index bab80c5..82e8140 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -69,6 +69,24 @@ struct TcpConnection *tcp_find_connection(ipv4_t src_ip, u16 src_port, return NULL; } +int tcp_sync_buffer(struct TcpConnection *con); +void tcp_flush_buffers(void) { + for (int i = 0;; i++) { + struct TcpConnection *c; + int end; + if (!relist_get(&open_tcp_connections, i, (void **)&c, &end)) { + if (end) { + break; + } + continue; + } + if (TCP_STATE_CLOSED == c->state) { + continue; + } + tcp_sync_buffer(c); + } +} + void tcp_flush_acks(void) { for (int i = 0;; i++) { struct TcpConnection *c; @@ -127,9 +145,7 @@ struct UdpConnection *udp_find_connection(ipv4_t src_ip, u16 src_port, return NULL; } -int tcp_sync_buffer(vfs_fd_t *fd) { - struct TcpConnection *con = fd->inode->internal_object; - assert(con); +int tcp_sync_buffer(struct TcpConnection *con) { if (TCP_STATE_CLOSED == con->state) { return 0; } @@ -156,7 +172,7 @@ int tcp_sync_buffer(vfs_fd_t *fd) { void tcp_close(vfs_fd_t *fd) { struct TcpConnection *con = fd->inode->internal_object; assert(con); - tcp_sync_buffer(fd); + tcp_sync_buffer(con); tcp_close_connection(con); } @@ -214,7 +230,7 @@ int tcp_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { struct ringbuffer *rb = &con->outgoing_buffer; if (ringbuffer_unused(rb) < len) { - if (!tcp_sync_buffer(fd)) { + if (!tcp_sync_buffer(con)) { return 0; } if (!send_tcp_packet(con, buffer, len)) { |