3 ms·
open, read, write, seek, ioctl, etc are a weird interface to use for IPC. I would rather there be a proper API for remote objects rather then every remote obje
by charcircuit 3y ago
open, read, write, seek, ioctl, etc are a weird interface to use for IPC.
I would rather there be a proper API for remote objects rather then every remote object having to roll its own protocol for doing the same.
- kazinator 3y agoIt's fine for local IPC like Unix domain sockets. For remote IPC, obviously the machines don't share a common space they can just access as a file for rendezvous, and so we don't use that API. We have socket, connect|{bind, listen, accept}, read, write. For connectionless, send, recv. Sockets are not part of "everything is a file" but of "everything is a file descriptor".
- charcircuit 3y ago>It's fine for local IPC like Unix domain sockets. I disagree. I should be able to just call a function. I don't want to bother figuring out the network protocol that the process decided on. It's too low level to expose.
- duped 3y agoThat's why 9P was invented.
- mjb 3y agoYes! There are a lot of benefits to the 'everything is a file' philosophy, but files aren't very good APIs for a structured data. The perfect example is the stuff in /proc and /sys. Making it all 'just a file' is super nice and flexible at first, but either makes stuff very difficult to change (the file becomes a poorly-specified inconvenient ad-hoc API), or makes it very hard to build applications that work in the long term (because the application has to write a change-tolerant parser). It makes a very cool demo (look, I can do stuff to TCP sockets using bash!), and really convenient for ad-hoc stuff, but is inferior to a real API for applications that need to keep working year after year after year while still being able to patch the rest of the system.
- duped 3y agoThe file tree is just a way of discovering endpoints to the API. You still need an encoding to read/write to those endpoints. The same is true over a "real" API with one big difference: there's not a small set of syscalls to access the endpoints and read/write binary data to them. Thats more stable than any FFI or encoding scheme. I'll take "everything is a file" over "everything is an object that has a special mechanism for querying interfaces and dispatching to handlers" or "everything is RPC" or "everything is REST" because it has the smallest surface area.
- charcircuit 3y ago>The same is true over a "real" API with one big difference: there's not a small set of syscalls to access the endpoints and read/write binary data to them. What do you mean? Binder from Android uses just the ioctl syscall. >because it has the smallest surface area. I assure you the 1 syscalls for using binder (unless you count open and close of /dev/binder) is less syscalls than what it takes when everything is a file (read, write, ioctl, lseek, lstat, etc).
- DonHopkins 3y agoIt's the job of the operating system to provide a stable foreign function interface, and dynamically linked libraries to access common operating system apis that aren't covered by system calls. Smallest surface area??! There's no excuse for Unix forcing you to use the fractally complex sucking chest wound of ioctl and brittle binary raw pointerless C structures in memory, instead of simply calling functions and passing normal parameters and pointers and results in and out. Computers are great at and have a long history of calling functions, so why not just support that, huh? "Everything is a file" is pointlessly performative but hopelessly incomplete Bauhaus Minimalism that fails to reduce but instead multiplies and relocates all the complexity to the Brutalist Rawness of ioctl's uncanny leaky abstraction of a kitchen sink, which undermines the entire Unix presumptuous philosophy of simplicity and consistency.
- deathanatos 3y agoI think the big problem with objects is that they're just not the common denominator: e.g., image files/formats are going to be byte streams. That, and getting the world to agree on object formats is like pulling teeth, it seems. E.g., WASM just wanted to add a string type, which OUGHT TO¹ be simple (use UTF-8) … but alas. JSON? Not enough types. YAML? Doesn't matter if it's good, nobody likes YAML. Etc. And you have to serialize them to bytes somewhere along the line; either to transfer their memory representation to another process, or to put them on the network. I start thinking "Perhaps something could be built on top of byte streams" but that's YAML, JSON, CBOR, take your pick. ¹(this is an RFC 6919 OUGHT TO)
- charcircuit 3y agoI don't understand. Objects existing doesn't mean files can no longer exist. >getting the world to agree on object formats is like pulling teeth In Windows apps agree, Mac app agree, iOS app agree, Android apps agree, Java apps agree. Sending or receiving strings to a system API is common. >And you have to serialize them to bytes somewhere along the line; either to transfer their memory representation to another process, or to put them on the network. Yes, but I'd much prefer if there was the 1 true way an os chooses it to be than each thing inventing its own way.
- GoblinSlayer 3y agoWell, there's dbus. On the other hand if you want a function and not protocol, why would you care what protocol it uses? It might as well be a file. When you call getaddrinfo("localhost"), it reads /etc/hosts - a text file.