From a53d8ecc2ce40849e65c5d8e17198553cea01758 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 4 Oct 2019 15:40:10 +0900 Subject: [PATCH] Call soclose() from sys_close() --- kernel/core/cxnet.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/kernel/core/cxnet.c b/kernel/core/cxnet.c index 4dca679..c369d58 100644 --- a/kernel/core/cxnet.c +++ b/kernel/core/cxnet.c @@ -9,6 +9,7 @@ #include #include #include "socket.h" +#include int sys_socket(int domain, int type, int protocol) { @@ -25,9 +26,34 @@ int sys_socket(int domain, int type, int protocol) return(ret_val); } -int sys_close(int sockfd) +int sys_close(int procfd) { - return(-ENOSYS); + process_t *cproc; + int ret_val; + + /* + * The fd that was passed is a per-process "procfd", but soclose() needs + * the global "sockfd" - so we have to look it up first. + */ + + cproc = process_get_current(); + ret_val = -EFAULT; + + if(cproc) { + ret_val = process_flookup(cproc, procfd); + + /* + * If ret_val is not negative, it holds the sockfd to be + * closed. Otherwise it holds an error number that we're + * going to return to the caller. + */ + if(ret_val >= 0) { + dbg_printf("soclose(0x%08x)\n", ret_val); + ret_val = soclose(ret_val); + } + } + + return(ret_val); } int sys_sendto(int sockfd, const void *buf, size_t len, int flags, -- 2.47.3