posix: fd_t struct require redundant information
Looking at sys/include/fd.h it seems that fd_t stores the pid itself and requires it as a paramater for the function pointers. Is there a reasoning behind? And shouldn't this struct also include a close function pointer?
Looking at sys/include/fd.h it seems that fd_t stores the pid itself and requires it as a paramater for the function pointers. Is there a reasoning behind?
fd_t::fdstores the RIOT internal value (as stated in the documentation) for the file descriptor (this could be a PID, but e.g. in case of tl_sockets not).- the parameter expected by the function pointers is the result of
fd_new()(The POSIX-like file descriptor).
And shouldn't this struct also include a close function pointer?
It does: https://github.com/RIOT-OS/RIOT/blob/master/sys/include/fd.h#L48
fd_t::fdstores the RIOT internal value (as stated in the documentation) for the file descriptor (this could be a PID, but e.g. in case of tl_sockets not).- the parameter expected by the function pointers is the result of
fd_new()(The POSIX-like file descriptor).
I see. However, I think having the same variable name for both makes this a bit confusing. Do you mind, if I make PR to change this (and add some more verbose documentation to fd_t:fd)?
It does: https://github.com/RIOT-OS/RIOT/blob/master/sys/include/fd.h#L48
Sorry, I meant open().
Please elaborate it a little bit further ,
- Do you want an open() to be added ?
- What parts do you need the documentation for , from what I see fd_t:fd is one of them , what are the other ones' ?
- Do you want an open() to be added ?
no, open() on a filename would be a call to fd_new(), so it would be nonsensical to add an open function pointer to the struct (but maybe @OlegHahm can elaborate on his use-case, here).
- What parts do you need the documentation for , from what I see fd_t:fd is one of them , what are the other ones' ?
I guess it must become clear, that fd_t::fd is the RIOT internal file descriptor and not the POSIX one. So a rename to maybe fd_t::internal_fd + some documentation in the spirit of what I wrote in October would suffice.
That fd_t::fd is seperate from the int fd referenced in read, write, and close in the following lines correct?
I will start working on it now , just one last question fd_new function has an internal_fd field as a parameter to the function , so that's same as our fd::internal_fd, right ?
I will modify the changes if any due to open call later on.
I had already begun working on it as well. It seemed like an great task to just get used to RIOT's process
@authmillenon:
no, open() on a filename would be a call to fd_new(), so it would be nonsensical to add an open function pointer to the struct (but maybe @OlegHahm can elaborate on his use-case, here).
Rationale was POSIX compliance. Currently sys/posix/unistd.c implements close() but no open().
@authmillenon:
no, open() on a filename would be a call to fd_new(), so it would be nonsensical to add an open function pointer to the struct (but maybe @OlegHahm can elaborate on his use-case, here). Rationale was POSIX compliance. Currently sys/posix/unistd.c implements close() but no open().
open() is for files (as in things in a file system). As we currently do not have any file system support it would be kind of non-sensical to write an open() function. File descriptors on the other hand are used for sockets and pthreads too which we have implemented already.