Comtrol eCos User Manual

Page 570

Advertising
background image

Chapter 38. TCP/IP Library Reference

imum number of descriptors supported by the system.

If timeout is a non-null pointer, it specifies a maximum interval to wait

for the selection to complete.

If timeout is a null pointer, the select

blocks indefinitely.

To effect a poll, the timeout argument should be

non-null, pointing to a zero-valued timeval structure.

timeout is not

changed by select(), and may be reused on subsequent calls; however, it

is good style to re-initialize it before each invocation of select().

Any of readfds, writefds, and exceptfds may be given as null pointers if

no descriptors are of interest.

RETURN VALUES

select() returns the number of ready descriptors that are contained in

the descriptor sets, or -1 is an error occurred.

If the time limit

expires, select() returns 0.

If select() returns with an error, includ-

ing one due to an interrupted call, the descriptor sets will be unmodi-

fied.

ERRORS

An error return from select() indicates:

[EFAULT]

One or more of readfds, writefds, or exceptfds points

outside the process’s allocated address space.

[EBADF]

One of the descriptor sets specified an invalid

descriptor.

[EINTR]

A signal was delivered before the time limit expired

and before any of the selected events occurred.

[EINVAL]

The specified time limit is invalid.

One of its com-

ponents is negative or too large.

SEE ALSO

accept(2), connect(2), gettimeofday(2), poll(2), read(2), recv(2),

send(2), write(2), getdtablesize(3)

BUGS

Although the provision of getdtablesize(3) was intended to allow user

programs to be written independent of the kernel limit on the number of

open files, the dimension of a sufficiently large bit field for select

remains a problem.

The default bit size of fd_set is based on the symbol

FD_SETSIZE (currently 256), but that is somewhat smaller than the current

kernel limit to the number of open files.

However, in order to accommo-

date programs which might potentially use a larger number of open files

with select, it is possible to increase this size within a program by

providing a larger definition of FD_SETSIZE before the inclusion of

<

sys/types.h>.

The kernel will cope, and the userland libraries provided

with the system are also ready for large numbers of file descriptors.

Alternatively, to be really safe, it is possible to allocate fd_set bit-

arrays dynamically.

The idea is to permit a program to work properly

even if it is execve(2)’d with 4000 file descriptors pre-allocated.

The

following illustrates the technique which is used by userland libraries:

466

Advertising