You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by KIKUCHI Takeyoshi <ta...@gmail.com> on 2023/02/16 23:44:31 UTC

Maximum file descriptor number in select()?

currently porting the Nim language to NuttX.
(It has been merged into the Nim devel branch)

When using select/epoll, it is necessary to determine the maximum value 
of file descriptor in order to assign a structure to store the fd to be 
waited in advance.

It is used in this way.

---------
proc newSelector*[T](): Selector[T] =
   # Retrieve the maximum fd count (for current OS) via getrlimit()
   var maxFD = maxDescriptors() <---
# Start with a reasonable size, checkFd() will grow this on demand
   const numFD = 1024
...
for i in 0 ... < numFD:
     result.fds[i].ident = InvalidIdent
---------
(Now I realize that numFD also needs to be switched for NuttX...)

Since the available memory capacity varies from device to device,
Is there any way to find the best value for each build config?

Porting to FreeRTOS in the Nim language uses the maximum number of 
sockets available, set by the user at build time.

---------
var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header: 
"<lwipopts.h>".} : cint
---------

best regards,
KIKUCHI Takeyoshi


Re: Maximum file descriptor number in select()?

Posted by Gregory Nutt <sp...@gmail.com>.
> >..l.  I could not find where
> > select() or poll() are implemented in the nuttx repository.  Is there
> some
> > kind of magic going on with that?
> >
> >
> They hare here:
> https://github.com/apache/nuttx/blob/master/fs/vfs/fs_select.c
> https://github.com/apache/nuttx/blob/master/fs/vfs/fs_poll.c


Thanks.  That is where I expected them to be but they are missing on my
laptop.  I lost the disk on this laptop and just got it back from the
repaire shop today.  It looks like my restore from backup was bad.  I guess
I need to re-clone all of the repositories on my laptop.

That really had me confused!

Re: Maximum file descriptor number in select()?

Posted by Xiang Xiao <xi...@gmail.com>.
On Sun, Feb 19, 2023 at 10:21 AM Gregory Nutt <sp...@gmail.com> wrote:

>  > fd_set is a 32bit array, the max fd number is hardcode to 256:
> >https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91
> <https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91>
>
> I just found that and was sending an email.  I could not find where
> select() or poll() are implemented in the nuttx repository.  Is there some
> kind of magic going on with that?
>
>
They hare here:
https://github.com/apache/nuttx/blob/master/fs/vfs/fs_select.c
https://github.com/apache/nuttx/blob/master/fs/vfs/fs_poll.c



> > it's better to define FD_SETSIZE to OPEN_MAX.
>
> That was my suggestion too..
>
>
Here is the patch:
https://github.com/apache/nuttx/pull/8581


>
>
> On Sat, Feb 18, 2023 at 8:12 PM Xiang Xiao <xi...@gmail.com>
> wrote:
>
> > fd_set is a 32bit array, the max fd number is hardcode to 256:
> > https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91
> > it's better to define FD_SETSIZE to OPEN_MAX.
> >
> >
> > On Sun, Feb 19, 2023 at 9:53 AM Gregory Nutt <sp...@gmail.com>
> wrote:
> >
> > > That is okay.  My answer is possibly wrong anyway.  OPEN_MAX is the
> > maximum
> > > number of open files.  For the select, the file descriptor set was held
> > in
> > > a 32-bit bit set so the maximum was 31.  But that logic has been
> > redesigned
> > > and I don’t know how it works now.
> > >
> > >
> > >
> > > Hopefully, it supports up to OPEN_MAX – 1, otherwise that would be a
> bug.
> > >
> > >
> > >
> > > On Sat, Feb 18, 2023 at 7:37 PM KIKUCHI Takeyoshi <
> > > kikuchi@centurysys.co.jp>
> > > wrote:
> > >
> > > > Hi Greg,
> > > >
> > > > Sorry, it seems that the same one was delivered late, probably
> because
> > I
> > > > sent it with the wrong email source account (not the one I subscribed
> > to
> > > > the list).
> > > >
> > > > best regards,
> > > > KIKUCHI Takeyoshi
> > > >
> > > >
> > > > On 2023/02/19 9:20, Gregory Nutt wrote:
> > > > > The maximum number of file descriptors is a constant value provided
> > by
> > > > > the preprocessor definition OPEN_MAX.
> > > > >
> > > > > On 2/16/2023 5:44 PM, KIKUCHI Takeyoshi wrote:
> > > > >> currently porting the Nim language to NuttX.
> > > > >> (It has been merged into the Nim devel branch)
> > > > >>
> > > > >> When using select/epoll, it is necessary to determine the maximum
> > > > >> value of file descriptor in order to assign a structure to store
> the
> > > > >> fd to be waited in advance.
> > > > >>
> > > > >> It is used in this way.
> > > > >>
> > > > >> ---------
> > > > >> proc newSelector*[T](): Selector[T] =
> > > > >>   # Retrieve the maximum fd count (for current OS) via getrlimit()
> > > > >>   var maxFD = maxDescriptors() <---
> > > > >> # Start with a reasonable size, checkFd() will grow this on demand
> > > > >>   const numFD = 1024
> > > > >> ...
> > > > >> for i in 0 ... < numFD:
> > > > >>     result.fds[i].ident = InvalidIdent
> > > > >> ---------
> > > > >> (Now I realize that numFD also needs to be switched for NuttX...)
> > > > >>
> > > > >> Since the available memory capacity varies from device to device,
> > > > >> Is there any way to find the best value for each build config?
> > > > >>
> > > > >> Porting to FreeRTOS in the Nim language uses the maximum number of
> > > > >> sockets available, set by the user at build time.
> > > > >>
> > > > >> ---------
> > > > >> var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header:
> > > > >> "<lwipopts.h>".} : cint
> > > > >> ---------
> > > > >>
> > > > >> best regards,
> > > > >> KIKUCHI Takeyoshi
> > > > >>
> > > > >
> > > >
> > > > --
> > > > kikuchi@centurysys.co.jp
> > > >
> > >
> >
>

Re: Maximum file descriptor number in select()?

Posted by Gregory Nutt <sp...@gmail.com>.
 > fd_set is a 32bit array, the max fd number is hardcode to 256:
>https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91
<https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91>

I just found that and was sending an email.  I could not find where
select() or poll() are implemented in the nuttx repository.  Is there some
kind of magic going on with that?

> it's better to define FD_SETSIZE to OPEN_MAX.

That was my suggestion too..



On Sat, Feb 18, 2023 at 8:12 PM Xiang Xiao <xi...@gmail.com>
wrote:

> fd_set is a 32bit array, the max fd number is hardcode to 256:
> https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91
> it's better to define FD_SETSIZE to OPEN_MAX.
>
>
> On Sun, Feb 19, 2023 at 9:53 AM Gregory Nutt <sp...@gmail.com> wrote:
>
> > That is okay.  My answer is possibly wrong anyway.  OPEN_MAX is the
> maximum
> > number of open files.  For the select, the file descriptor set was held
> in
> > a 32-bit bit set so the maximum was 31.  But that logic has been
> redesigned
> > and I don’t know how it works now.
> >
> >
> >
> > Hopefully, it supports up to OPEN_MAX – 1, otherwise that would be a bug.
> >
> >
> >
> > On Sat, Feb 18, 2023 at 7:37 PM KIKUCHI Takeyoshi <
> > kikuchi@centurysys.co.jp>
> > wrote:
> >
> > > Hi Greg,
> > >
> > > Sorry, it seems that the same one was delivered late, probably because
> I
> > > sent it with the wrong email source account (not the one I subscribed
> to
> > > the list).
> > >
> > > best regards,
> > > KIKUCHI Takeyoshi
> > >
> > >
> > > On 2023/02/19 9:20, Gregory Nutt wrote:
> > > > The maximum number of file descriptors is a constant value provided
> by
> > > > the preprocessor definition OPEN_MAX.
> > > >
> > > > On 2/16/2023 5:44 PM, KIKUCHI Takeyoshi wrote:
> > > >> currently porting the Nim language to NuttX.
> > > >> (It has been merged into the Nim devel branch)
> > > >>
> > > >> When using select/epoll, it is necessary to determine the maximum
> > > >> value of file descriptor in order to assign a structure to store the
> > > >> fd to be waited in advance.
> > > >>
> > > >> It is used in this way.
> > > >>
> > > >> ---------
> > > >> proc newSelector*[T](): Selector[T] =
> > > >>   # Retrieve the maximum fd count (for current OS) via getrlimit()
> > > >>   var maxFD = maxDescriptors() <---
> > > >> # Start with a reasonable size, checkFd() will grow this on demand
> > > >>   const numFD = 1024
> > > >> ...
> > > >> for i in 0 ... < numFD:
> > > >>     result.fds[i].ident = InvalidIdent
> > > >> ---------
> > > >> (Now I realize that numFD also needs to be switched for NuttX...)
> > > >>
> > > >> Since the available memory capacity varies from device to device,
> > > >> Is there any way to find the best value for each build config?
> > > >>
> > > >> Porting to FreeRTOS in the Nim language uses the maximum number of
> > > >> sockets available, set by the user at build time.
> > > >>
> > > >> ---------
> > > >> var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header:
> > > >> "<lwipopts.h>".} : cint
> > > >> ---------
> > > >>
> > > >> best regards,
> > > >> KIKUCHI Takeyoshi
> > > >>
> > > >
> > >
> > > --
> > > kikuchi@centurysys.co.jp
> > >
> >
>

Re: Maximum file descriptor number in select()?

Posted by Xiang Xiao <xi...@gmail.com>.
fd_set is a 32bit array, the max fd number is hardcode to 256:
https://github.com/apache/nuttx/blob/master/include/sys/select.h#L38-L91
it's better to define FD_SETSIZE to OPEN_MAX.


On Sun, Feb 19, 2023 at 9:53 AM Gregory Nutt <sp...@gmail.com> wrote:

> That is okay.  My answer is possibly wrong anyway.  OPEN_MAX is the maximum
> number of open files.  For the select, the file descriptor set was held in
> a 32-bit bit set so the maximum was 31.  But that logic has been redesigned
> and I don’t know how it works now.
>
>
>
> Hopefully, it supports up to OPEN_MAX – 1, otherwise that would be a bug.
>
>
>
> On Sat, Feb 18, 2023 at 7:37 PM KIKUCHI Takeyoshi <
> kikuchi@centurysys.co.jp>
> wrote:
>
> > Hi Greg,
> >
> > Sorry, it seems that the same one was delivered late, probably because I
> > sent it with the wrong email source account (not the one I subscribed to
> > the list).
> >
> > best regards,
> > KIKUCHI Takeyoshi
> >
> >
> > On 2023/02/19 9:20, Gregory Nutt wrote:
> > > The maximum number of file descriptors is a constant value provided by
> > > the preprocessor definition OPEN_MAX.
> > >
> > > On 2/16/2023 5:44 PM, KIKUCHI Takeyoshi wrote:
> > >> currently porting the Nim language to NuttX.
> > >> (It has been merged into the Nim devel branch)
> > >>
> > >> When using select/epoll, it is necessary to determine the maximum
> > >> value of file descriptor in order to assign a structure to store the
> > >> fd to be waited in advance.
> > >>
> > >> It is used in this way.
> > >>
> > >> ---------
> > >> proc newSelector*[T](): Selector[T] =
> > >>   # Retrieve the maximum fd count (for current OS) via getrlimit()
> > >>   var maxFD = maxDescriptors() <---
> > >> # Start with a reasonable size, checkFd() will grow this on demand
> > >>   const numFD = 1024
> > >> ...
> > >> for i in 0 ... < numFD:
> > >>     result.fds[i].ident = InvalidIdent
> > >> ---------
> > >> (Now I realize that numFD also needs to be switched for NuttX...)
> > >>
> > >> Since the available memory capacity varies from device to device,
> > >> Is there any way to find the best value for each build config?
> > >>
> > >> Porting to FreeRTOS in the Nim language uses the maximum number of
> > >> sockets available, set by the user at build time.
> > >>
> > >> ---------
> > >> var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header:
> > >> "<lwipopts.h>".} : cint
> > >> ---------
> > >>
> > >> best regards,
> > >> KIKUCHI Takeyoshi
> > >>
> > >
> >
> > --
> > kikuchi@centurysys.co.jp
> >
>

Re: Maximum file descriptor number in select()?

Posted by Gregory Nutt <sp...@gmail.com>.
That is okay.  My answer is possibly wrong anyway.  OPEN_MAX is the maximum
number of open files.  For the select, the file descriptor set was held in
a 32-bit bit set so the maximum was 31.  But that logic has been redesigned
and I don’t know how it works now.



Hopefully, it supports up to OPEN_MAX – 1, otherwise that would be a bug.



On Sat, Feb 18, 2023 at 7:37 PM KIKUCHI Takeyoshi <ki...@centurysys.co.jp>
wrote:

> Hi Greg,
>
> Sorry, it seems that the same one was delivered late, probably because I
> sent it with the wrong email source account (not the one I subscribed to
> the list).
>
> best regards,
> KIKUCHI Takeyoshi
>
>
> On 2023/02/19 9:20, Gregory Nutt wrote:
> > The maximum number of file descriptors is a constant value provided by
> > the preprocessor definition OPEN_MAX.
> >
> > On 2/16/2023 5:44 PM, KIKUCHI Takeyoshi wrote:
> >> currently porting the Nim language to NuttX.
> >> (It has been merged into the Nim devel branch)
> >>
> >> When using select/epoll, it is necessary to determine the maximum
> >> value of file descriptor in order to assign a structure to store the
> >> fd to be waited in advance.
> >>
> >> It is used in this way.
> >>
> >> ---------
> >> proc newSelector*[T](): Selector[T] =
> >>   # Retrieve the maximum fd count (for current OS) via getrlimit()
> >>   var maxFD = maxDescriptors() <---
> >> # Start with a reasonable size, checkFd() will grow this on demand
> >>   const numFD = 1024
> >> ...
> >> for i in 0 ... < numFD:
> >>     result.fds[i].ident = InvalidIdent
> >> ---------
> >> (Now I realize that numFD also needs to be switched for NuttX...)
> >>
> >> Since the available memory capacity varies from device to device,
> >> Is there any way to find the best value for each build config?
> >>
> >> Porting to FreeRTOS in the Nim language uses the maximum number of
> >> sockets available, set by the user at build time.
> >>
> >> ---------
> >> var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header:
> >> "<lwipopts.h>".} : cint
> >> ---------
> >>
> >> best regards,
> >> KIKUCHI Takeyoshi
> >>
> >
>
> --
> kikuchi@centurysys.co.jp
>

Re: Maximum file descriptor number in select()?

Posted by KIKUCHI Takeyoshi <ki...@centurysys.co.jp>.
Hi Greg,

Sorry, it seems that the same one was delivered late, probably because I 
sent it with the wrong email source account (not the one I subscribed to 
the list).

best regards,
KIKUCHI Takeyoshi


On 2023/02/19 9:20, Gregory Nutt wrote:
> The maximum number of file descriptors is a constant value provided by 
> the preprocessor definition OPEN_MAX.
> 
> On 2/16/2023 5:44 PM, KIKUCHI Takeyoshi wrote:
>> currently porting the Nim language to NuttX.
>> (It has been merged into the Nim devel branch)
>>
>> When using select/epoll, it is necessary to determine the maximum 
>> value of file descriptor in order to assign a structure to store the 
>> fd to be waited in advance.
>>
>> It is used in this way.
>>
>> ---------
>> proc newSelector*[T](): Selector[T] =
>>   # Retrieve the maximum fd count (for current OS) via getrlimit()
>>   var maxFD = maxDescriptors() <---
>> # Start with a reasonable size, checkFd() will grow this on demand
>>   const numFD = 1024
>> ...
>> for i in 0 ... < numFD:
>>     result.fds[i].ident = InvalidIdent
>> ---------
>> (Now I realize that numFD also needs to be switched for NuttX...)
>>
>> Since the available memory capacity varies from device to device,
>> Is there any way to find the best value for each build config?
>>
>> Porting to FreeRTOS in the Nim language uses the maximum number of 
>> sockets available, set by the user at build time.
>>
>> ---------
>> var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header: 
>> "<lwipopts.h>".} : cint
>> ---------
>>
>> best regards,
>> KIKUCHI Takeyoshi
>>
> 

-- 
kikuchi@centurysys.co.jp

Re: Maximum file descriptor number in select()?

Posted by Gregory Nutt <sp...@gmail.com>.
The maximum number of file descriptors is a constant value provided by 
the preprocessor definition OPEN_MAX.

On 2/16/2023 5:44 PM, KIKUCHI Takeyoshi wrote:
> currently porting the Nim language to NuttX.
> (It has been merged into the Nim devel branch)
>
> When using select/epoll, it is necessary to determine the maximum 
> value of file descriptor in order to assign a structure to store the 
> fd to be waited in advance.
>
> It is used in this way.
>
> ---------
> proc newSelector*[T](): Selector[T] =
>   # Retrieve the maximum fd count (for current OS) via getrlimit()
>   var maxFD = maxDescriptors() <---
> # Start with a reasonable size, checkFd() will grow this on demand
>   const numFD = 1024
> ...
> for i in 0 ... < numFD:
>     result.fds[i].ident = InvalidIdent
> ---------
> (Now I realize that numFD also needs to be switched for NuttX...)
>
> Since the available memory capacity varies from device to device,
> Is there any way to find the best value for each build config?
>
> Porting to FreeRTOS in the Nim language uses the maximum number of 
> sockets available, set by the user at build time.
>
> ---------
> var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header: 
> "<lwipopts.h>".} : cint
> ---------
>
> best regards,
> KIKUCHI Takeyoshi
>