inode: socket hooks
authorAlan Cox <alan@linux.intel.com>
Fri, 2 Jan 2015 12:09:08 +0000 (12:09 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 2 Jan 2015 12:09:08 +0000 (12:09 +0000)
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
Kernel/inode.c

index ade811d..cbaaecd 100644 (file)
@@ -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
 
index 15f19c0..d4481b2 100644 (file)
@@ -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);