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.
#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
toread = udata.u_count;
goto loop;
+ case F_SOCK:
case F_PIPE:
ispipe = true;
while (ino->c_node.i_size == 0 && !(flag & O_NDELAY)) {
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;
}
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);