|
Re: file: module and character special files: msg#00338lang.erlang.general
Hello, They say I should comment on this, so I'll do it. The interesting part is last, so read from the end if you're only interested in that :-) Richard A. O'Keefe wrote: I asked why file: doesn't handle /dev/null correctly.As I originally said, the return value is misleading. The return value is one issue, the fact that device files cannot be opened is another. My post was aimed at explaining the reason, not the exact return value. As you focus the argumentation on the return value in itself, I'll try to explain that as well... Someone decided, a long time ago, that EISDIR was a good return value here, when something on the line of "this is not a regular file" would have been better. That may have been a bad choise. However, changing return values isn't all that popular among people having miljons of lines of code slushing around in systems supposed to have an ISP of 99.999 or better. Therefore the prio of such a change isn't all that high. It's not really a big deal either, honestly. I think most users think there are larger issues we should work on, but I might be wrong :-) I get your point, but obviously the suggested patch would not solve any real problem. With your patch applied: ---------------------- Erlang (BEAM) emulator version 5.4 [source] [threads:0] Eshell V5.4 (abort with ^G) 1> file:open("/dev/null",[read]). {ok,<0.31.0>} 2> cd("/dev"). /dev ok 3> file:open("null",[read]). {error,eisdir} 4> --------------------------- This is of course easy to fix, but it indicates that the string-matching-magic-filename approach is no good. In fact the approach works even worse for other obvious cases, i.e. with a hard link to /dev/null, opening /dev/zero (which is bleeding fast as well) etc. Whoever wrote the original file driver draw the line at regular files, as that can be determined. Whoever that person was, I think he or she was right in doing this. However, with a different implementation than the original, the line could be drawn somewhere else, see below. It is true that NFS can make reading from regular files block. We cannot handle that and we cannot "see" if a file is on local or remote filesystem from the driver. The OS'es don't provide sufficient interfaces to del with such things. We do not recommend people writing real-time systems relying on NFS over unstable network connections either, but that's beside the point. Still, it would not help to use select or poll. File handles for NFS files behave like file handles for any other file system, they are always available for reading and writing. It's not unsolvable, but looking for the unix-dialect where select/poll can be used to se if the nfs server is accessible is not a feasible solution. I wrote "lots of u*x'es" in the four year old letter, I should have written "any unix system we know of" instead. If things have changed during the last years, that might have been interesting if we hadn't found a more general solution to the problem. Note that select/poll does indeed "work" on regular files in the sense that they don't result in an error return, they simply always signal that data is writable to and readable from the file descriptor regardless of the actual facts. ***************************************************************** End of implementation discussion. Now comes the interesting part: Tony Rogvall (together with others) has made a remarkable *real, working, and portable* implementation of a threaded file driver, submitted it to us, and that is the one nowdays present in the emulator. That driver, to some extent, solves the NFS problem. It's working well for all unixes that haven't failed to implement threads properly in the kernel (maybe those without kernel threads are the one that really have disgraced themselves :-). Among platforms where this work well are Solaris, Linux, Windows and many others. This obviously means that given a large enough thread pool, opening device files like /dev/null with this driver would be a much better idea than it was in the single threaded case. So, what *should* be changed in the file driver, is more on the lines of If the file is regular then open else If the file is not a directory and you have more than one I/O thread and you have chosen to explicitly enable the feature by some means then open the thing anyway else return some error endif endif Were "return some error" actually still might mean "eisdir", especially if one wants the fix done in time for the next release... So, allowing device files to be opened from within the file driver could be done. Is there really anyone needing this? Speak up in that case and someone will add it. The return value is another issue though, that needs confirmation from the ones actually paying for all this... Nice idea, with the change suggested above and a bunch of I/O-threads, nothing in Erlang stops you from writing such a thing. Ftp is already there, http is a piece of cake, file I/O with threads is non-blocking... A simple wrapper and some HTTP stuff. Best regards, /Patrik |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Megaco and controlling processes: 00338, Samuel Tardieu |
|---|---|
| Next by Date: | Re: Distribution problems: 00338, Rocio Lopez |
| Previous by Thread: | RE: file: module and character special filesi: 00338, Richard A. O'Keefe |
| Next by Thread: | Re: file: module and character special files: 00338, Scott Lystig Fritchie |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |