From: Matthias Kruk Date: Fri, 4 Oct 2019 06:40:10 +0000 (+0900) Subject: Call soclose() from sys_close() X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=a53d8ecc2ce40849e65c5d8e17198553cea01758;p=corax Call soclose() from sys_close() --- 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,