3 ms·
The difference is that the callee working on the fd it received need to check if fd's type is pipe or socket and call close() or shutdown(fd, 1) accordingly. T
by halayli 3y ago
The difference is that the callee working on the fd it received need to check if fd's type is pipe or socket and call close() or shutdown(fd, 1) accordingly.
This is not a pipe vs socket issue only but a penalty for having a vfs abstraction. Files, pipes, sockets, and more all have stream like behavior but they can vary widely and many cases demand leaking the vfs abstraction to check what's the fd type.
- vacuity 3y agoFor a new OS, would it be good to circumvent this with a rudimentary runtime type system managed by the kernel? It would probably cost a bit of memory and performance overhead on syscalls, and eat up the syscall space. It could be reflected in the standard OS types in programming languages.
- ATMLOTTOBEER 3y agoWhen I read beej’s guide to network programming I was confused when he said you have to call close() even after you call shutdown(). The way I understood it was that shutdown gave you granular control to shut down only the reading or writing part of the connection. Reading your comment I am even more lost lol
- halayli 3y agoah yes that's because close() closes the file descriptor but shutdown does not. You can have a socket that is shutdown on both ends that has a valid fd.