aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-12-03 22:26:46 +0100
committerMarvin Borner2020-12-03 22:26:46 +0100
commitcd2dbb2e146562c9e37c614bb09a24f7fbf135e0 (patch)
tree12605be6b6dfe837f1a2ebefef3cfbc1ed8536e5 /kernel
parentd525526f52c76156c4b9ee5ee4f14ed0d06547bc (diff)
Quite important network stuff
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/net.c17
-rw-r--r--kernel/features/syscall.c4
2 files changed, 13 insertions, 8 deletions
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;
}