From cd2dbb2e146562c9e37c614bb09a24f7fbf135e0 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 3 Dec 2020 22:26:46 +0100 Subject: Quite important network stuff --- kernel/features/net.c | 17 +++++++++++------ kernel/features/syscall.c | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'kernel') diff --git a/kernel/features/net.c b/kernel/features/net.c index 26bdc0f..ab747e4 100644 --- a/kernel/features/net.c +++ b/kernel/features/net.c @@ -521,12 +521,7 @@ static void tcp_handle_packet(struct tcp_packet *packet, u32 dst, int len) tcp->ack_no += data_length; tcp->seq_no = recv_ack; - // TODO: How many segments are going to be sent?! - if ((flags & 0xff) == (TCP_FLAG_ACK | TCP_FLAG_PSH)) { - tcp_send_packet(socket, TCP_FLAG_ACK, NULL, 0); - tcp_send_packet(socket, TCP_FLAG_FIN | TCP_FLAG_ACK, NULL, 0); - tcp->state++; - } + tcp_send_packet(socket, TCP_FLAG_ACK, NULL, 0); socket->state = S_CONNECTED; return; @@ -740,6 +735,16 @@ int net_close(struct socket *socket) if (!net_installed()) return 1; + if (socket->state == S_CLOSING) + return 0; + + if (socket->type == S_TCP && socket->state != S_CLOSED) { + tcp_send_packet(socket, TCP_FLAG_FIN | TCP_FLAG_ACK, NULL, 0); + socket->state = S_CLOSING; + socket->prot.tcp.state++; + return 0; + } + return socket_close(socket); } diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 01720c5..9eb9f4b 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -102,8 +102,8 @@ void syscall_handler(struct regs *r) } case SYS_NET_CLOSE: { struct socket *s = (void *)r->ebx; - if (s->type == S_TCP && s->state == S_CONNECTED) { - proc_current()->state = PROC_SLEEPING; + int status = net_close(s); + if (!status) { proc_yield(r); return; } -- cgit v1.2.3