Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Meaning
In Networking
IPC
IPC
blocking I/O
nonblocking I/O
I/O multiplexing (select and poll)
signal driven I/O (SIGIO)
asynchronous I/O (the POSIX
aio_functions)
First step
Involves waiting for data to arrive on the network
When the packet arrives, it is copied into a buffer
within the kernel
Second step
1. Blocking I/O
Blocking I/O
3. I/O Multiplexing
I/O Multiplexing
5. Asynchronous I/O
Asynchronous I/O
Select Function
Select
#include <sys/select.h>
#include <sys/time.h>
int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set
*exceptset, const struct timeval *timeout);
Returns: positive count of ready descriptors, 0 on timeout, 1 on
error
Select
Select can deal with how long the kernel has to wait
1) Wait forever Return only when one of the
specified descriptors is ready for I/O timeout
argument as a null pointer.
2) Wait up to a fixed amount of time time out
argument is the number of seconds and
microseconds
3) Do not wait at all Return immediately after
checking the descriptors. This is called polling
Select
1.
2.
reading,
writing, or
an exception condition
Select
For example
2.
4.
Summary of conditions
that cause a socket to be
ready for select
Maximum Number of
Descriptors for select
1)
2)
3)
Shutdown Function
Shutdown Function
#include <sys/socket.h>
int shutdown(int sockfd, int howto);
Returns: 0 if OK, 1 on error
howto argument:
1. SHUT_RD - The read half of the connection is
closed
2. SHUT_WR - The write half of the connection
is closed
3. SHUT_RDWR - The read half and the write
half of the connection are both closed
close function
1. In this case of close
function decrement the
reference count and
closes the socket only if
the count reaches 0.
2.
Close
function
terminates
both
directions
of
data
transfer reading and
writing.
Data structures
for TCP server
with just a
listening socket,
server maintains
a read descriptor
set.
Poll Function
All regular TCP data and all UDP data is considered normal
TCP's out-of-band data is considered priority band.
When the read half of a TCP connection is closed (e.g., a
FIN is received), this is also considered normal data and a
subsequent read operation will return 0.
The presence of an error for a TCP connection can be
considered either normal data or an error (POLLERR).
The availability of a new connection on a listening socket
can be considered either normal data or priority data. Most
implementations consider this normal data.
The completion of a nonblocking connect is considered to
make a socket writable.
Poll Function
#include <poll.h>
int poll (struct pollfd *fdarray, unsigned long nfds, int timeout);
Returns: count of ready descriptors, 0 on timeout, 1 on error
Poll Function
timeout values for poll
constant INFTIM is defined
to be a negative value.
return value from poll is 1 if an error occurred, 0 if no descriptors are ready before the timer expires, otherwise it is the number of descriptors that have a nonzero revents member.