RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

posix: fd_t struct require redundant information

Open OlegHahm opened this issue 12 years ago • 9 comments

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?

OlegHahm avatar Oct 02 '14 08:10 OlegHahm

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::fd stores 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

miri64 avatar Oct 02 '14 11:10 miri64

  • fd_t::fd stores 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().

OlegHahm avatar Oct 07 '14 09:10 OlegHahm

Please elaborate it a little bit further ,

  1. Do you want an open() to be added ?
  2. What parts do you need the documentation for , from what I see fd_t:fd is one of them , what are the other ones' ?

kushalsingh007 avatar Mar 05 '15 20:03 kushalsingh007

  1. 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).

  1. 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.

miri64 avatar Mar 08 '15 16:03 miri64

That fd_t::fd is seperate from the int fd referenced in read, write, and close in the following lines correct?

BigDaddyD avatar Mar 09 '15 04:03 BigDaddyD

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.

kushalsingh007 avatar Mar 09 '15 05:03 kushalsingh007

I had already begun working on it as well. It seemed like an great task to just get used to RIOT's process

BigDaddyD avatar Mar 09 '15 14:03 BigDaddyD

@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().

OlegHahm avatar Mar 11 '15 16:03 OlegHahm

@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.

miri64 avatar Mar 11 '15 18:03 miri64