From 02252aab183200d9660685b1233e7e60405d6da0 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2015 12:09:08 +0000 Subject: [PATCH] inode: socket hooks On read we use the pipe logic for sockets, on write they work rather like a device. This slightly odd set up means that we can buffer incoming packets through the disk cache and thus onto disk if needed. It's also very cheap from a code size point of view. --- Kernel/include/kernel.h | 1 + Kernel/inode.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index ade811de..cbaaecd5 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -170,6 +170,7 @@ struct hd_geometry { #define F_PIPE 010000 #define F_BDEV 060000 // important that F_BDEV & F_CDEV != 0 (see isdevice() function) #define F_CDEV 020000 +#define F_SOCK 0140000 #define F_MASK 0170000 diff --git a/Kernel/inode.c b/Kernel/inode.c index 15f19c0e..d4481b2c 100644 --- a/Kernel/inode.c +++ b/Kernel/inode.c @@ -25,6 +25,7 @@ void readi(inoptr ino, uint8_t flag) toread = udata.u_count; goto loop; + case F_SOCK: case F_PIPE: ispipe = true; while (ino->c_node.i_size == 0 && !(flag & O_NDELAY)) { @@ -177,7 +178,11 @@ void writei(inoptr ino, uint8_t flag) if (udata.u_count != -1) udata.u_offset += udata.u_count; break; - +#ifdef CONFIG_NET + case F_SOCK: + udata.u_count = sock_write(ino, flag); + break; +#endif default: udata.u_error = ENODEV; } @@ -193,10 +198,14 @@ int16_t doclose(uint8_t uindex) oftindex = udata.u_files[uindex]; - if (isdevice(ino) - && ino->c_refs == 1 && of_tab[oftindex].o_refs == 1) - d_close((int) (ino->c_node.i_addr[0])); - + if (ino->c_refs == 1 && of_tab[oftindex].o_refs == 1) { + if (isdevice(ino)) + d_close((int) (ino->c_node.i_addr[0])); +#ifdef CONFIG_NET + if (issocket(ino) + sock_close(ino); +#endif + } udata.u_files[uindex] = NO_FILE; udata.u_cloexec &= ~(1 << uindex); oft_deref(oftindex); -- 2.34.1