mirror of https://github.com/mkerrisk/man-pages
ffix
This commit is contained in:
parent
218dfacd71
commit
7670ac9d8e
|
@ -365,8 +365,8 @@ subtle errors that will remove the advantage of using
|
||||||
hence I will present a list of essentials to watch for when using the
|
hence I will present a list of essentials to watch for when using the
|
||||||
.BR select ()
|
.BR select ()
|
||||||
call.
|
call.
|
||||||
.TP
|
.TP 4
|
||||||
\fB1.\fP
|
1.
|
||||||
You should always try to use
|
You should always try to use
|
||||||
.BR select ()
|
.BR select ()
|
||||||
without a timeout.
|
without a timeout.
|
||||||
|
@ -375,11 +375,11 @@ should have nothing to do if there is no data available.
|
||||||
Code that
|
Code that
|
||||||
depends on timeouts is not usually portable and is difficult to debug.
|
depends on timeouts is not usually portable and is difficult to debug.
|
||||||
.TP
|
.TP
|
||||||
\fB2.\fP
|
2.
|
||||||
The value \fInfds\fP must be properly calculated for efficiency as
|
The value \fInfds\fP must be properly calculated for efficiency as
|
||||||
explained above.
|
explained above.
|
||||||
.TP
|
.TP
|
||||||
\fB3.\fP
|
3.
|
||||||
No file descriptor must be added to any set if you do not intend
|
No file descriptor must be added to any set if you do not intend
|
||||||
to check its result after the
|
to check its result after the
|
||||||
.BR select ()
|
.BR select ()
|
||||||
|
@ -387,7 +387,7 @@ call, and respond
|
||||||
appropriately.
|
appropriately.
|
||||||
See next rule.
|
See next rule.
|
||||||
.TP
|
.TP
|
||||||
\fB4.\fP
|
4.
|
||||||
After
|
After
|
||||||
.BR select ()
|
.BR select ()
|
||||||
returns, all file descriptors in all sets
|
returns, all file descriptors in all sets
|
||||||
|
@ -397,7 +397,7 @@ should be checked to see if they are ready.
|
||||||
.\" for writing \fImust\fP be written to, and any file descriptor
|
.\" for writing \fImust\fP be written to, and any file descriptor
|
||||||
.\" available for reading \fImust\fP be read, etc.
|
.\" available for reading \fImust\fP be read, etc.
|
||||||
.TP
|
.TP
|
||||||
\fB5.\fP
|
5.
|
||||||
The functions
|
The functions
|
||||||
.BR read (2),
|
.BR read (2),
|
||||||
.BR recv (2),
|
.BR recv (2),
|
||||||
|
@ -413,7 +413,7 @@ always going to be the case.
|
||||||
You should cope with the case of your
|
You should cope with the case of your
|
||||||
functions only managing to send or receive a single byte.
|
functions only managing to send or receive a single byte.
|
||||||
.TP
|
.TP
|
||||||
\fB6.\fP
|
6.
|
||||||
Never read/write only in single bytes at a time unless your are really
|
Never read/write only in single bytes at a time unless your are really
|
||||||
sure that you have a small amount of data to process.
|
sure that you have a small amount of data to process.
|
||||||
It is extremely
|
It is extremely
|
||||||
|
@ -421,7 +421,7 @@ inefficient not to read/write as much data as you can buffer each time.
|
||||||
The buffers in the example above are 1024 bytes although they could
|
The buffers in the example above are 1024 bytes although they could
|
||||||
easily be made larger.
|
easily be made larger.
|
||||||
.TP
|
.TP
|
||||||
\fB7.\fP
|
7.
|
||||||
The functions
|
The functions
|
||||||
.BR read (2),
|
.BR read (2),
|
||||||
.BR recv (2),
|
.BR recv (2),
|
||||||
|
@ -445,7 +445,7 @@ set non-blocking I/O, you will not get \fBEAGAIN\fP.
|
||||||
Nonetheless
|
Nonetheless
|
||||||
you should still cope with these errors for completeness.
|
you should still cope with these errors for completeness.
|
||||||
.TP
|
.TP
|
||||||
\fB8.\fP
|
8.
|
||||||
Never call
|
Never call
|
||||||
.BR read (2),
|
.BR read (2),
|
||||||
.BR recv (2),
|
.BR recv (2),
|
||||||
|
@ -454,7 +454,7 @@ or
|
||||||
.BR send (2)
|
.BR send (2)
|
||||||
with a buffer length of zero.
|
with a buffer length of zero.
|
||||||
.TP
|
.TP
|
||||||
\fB9.\fP
|
9.
|
||||||
If the functions
|
If the functions
|
||||||
.BR read (2),
|
.BR read (2),
|
||||||
.BR recv (2),
|
.BR recv (2),
|
||||||
|
@ -471,14 +471,14 @@ In the above example,
|
||||||
I close the descriptor immediately, and then set it to \-1
|
I close the descriptor immediately, and then set it to \-1
|
||||||
to prevent it being included in a set.
|
to prevent it being included in a set.
|
||||||
.TP
|
.TP
|
||||||
\fB10.\fP
|
10.
|
||||||
The timeout value must be initialized with each new call to
|
The timeout value must be initialized with each new call to
|
||||||
.BR select (),
|
.BR select (),
|
||||||
since some operating systems modify the structure.
|
since some operating systems modify the structure.
|
||||||
.BR pselect ()
|
.BR pselect ()
|
||||||
however does not modify its timeout structure.
|
however does not modify its timeout structure.
|
||||||
.TP
|
.TP
|
||||||
\fB11.\fP
|
11.
|
||||||
I have heard that the Windows socket layer does not cope with OOB data
|
I have heard that the Windows socket layer does not cope with OOB data
|
||||||
properly.
|
properly.
|
||||||
It also does not cope with
|
It also does not cope with
|
||||||
|
@ -583,6 +583,7 @@ listen_socket(int listen_port)
|
||||||
struct sockaddr_in a;
|
struct sockaddr_in a;
|
||||||
int s;
|
int s;
|
||||||
int yes;
|
int yes;
|
||||||
|
|
||||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
return \-1;
|
return \-1;
|
||||||
|
@ -612,6 +613,7 @@ connect_socket(int connect_port, char *address)
|
||||||
{
|
{
|
||||||
struct sockaddr_in a;
|
struct sockaddr_in a;
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
close(s);
|
close(s);
|
||||||
|
|
|
@ -156,7 +156,7 @@ Otherwise
|
||||||
(the count of processes waiting until this semaphore's value becomes zero)
|
(the count of processes waiting until this semaphore's value becomes zero)
|
||||||
is incremented by one and the process sleeps until
|
is incremented by one and the process sleeps until
|
||||||
one of the following occurs:
|
one of the following occurs:
|
||||||
.IP \(bu
|
.IP \(bu 3
|
||||||
.I semval
|
.I semval
|
||||||
becomes 0, at which time the value of
|
becomes 0, at which time the value of
|
||||||
.I semzcnt
|
.I semzcnt
|
||||||
|
@ -230,7 +230,7 @@ Otherwise
|
||||||
(the counter of processes waiting for this semaphore's value to increase)
|
(the counter of processes waiting for this semaphore's value to increase)
|
||||||
is incremented by one and the process sleeps until
|
is incremented by one and the process sleeps until
|
||||||
one of the following occurs:
|
one of the following occurs:
|
||||||
.IP \(bu
|
.IP \(bu 3
|
||||||
.I semval
|
.I semval
|
||||||
becomes greater than or equal to the absolute value of
|
becomes greater than or equal to the absolute value of
|
||||||
.IR sem_op ,
|
.IR sem_op ,
|
||||||
|
|
Loading…
Reference in New Issue