mirror of https://github.com/mkerrisk/man-pages
select_tut.2: Clean up error checking in example program (no semantic changes)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
2472260fff
commit
0e888d6adb
|
@ -584,13 +584,13 @@ listen_socket(int listen_port)
|
|||
int s;
|
||||
int yes;
|
||||
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == \-1) {
|
||||
perror("socket");
|
||||
return \-1;
|
||||
}
|
||||
yes = 1;
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *) &yes, sizeof(yes)) < 0) {
|
||||
(char *) &yes, sizeof(yes)) == \-1) {
|
||||
perror("setsockopt");
|
||||
close(s);
|
||||
return \-1;
|
||||
|
@ -598,7 +598,7 @@ listen_socket(int listen_port)
|
|||
memset(&a, 0, sizeof(a));
|
||||
a.sin_port = htons(listen_port);
|
||||
a.sin_family = AF_INET;
|
||||
if (bind(s, (struct sockaddr *) &a, sizeof(a)) < 0) {
|
||||
if (bind(s, (struct sockaddr *) &a, sizeof(a)) == \-1) {
|
||||
perror("bind");
|
||||
close(s);
|
||||
return \-1;
|
||||
|
@ -614,7 +614,7 @@ connect_socket(int connect_port, char *address)
|
|||
struct sockaddr_in a;
|
||||
int s;
|
||||
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == \-1) {
|
||||
perror("socket");
|
||||
close(s);
|
||||
return \-1;
|
||||
|
@ -630,7 +630,7 @@ connect_socket(int connect_port, char *address)
|
|||
return \-1;
|
||||
}
|
||||
|
||||
if (connect(s, (struct sockaddr *) &a, sizeof(a)) < 0) {
|
||||
if (connect(s, (struct sockaddr *) &a, sizeof(a)) == \-1) {
|
||||
perror("connect()");
|
||||
shutdown(s, SHUT_RDWR);
|
||||
close(s);
|
||||
|
@ -677,7 +677,7 @@ main(int argc, char **argv)
|
|||
forward_port = atoi(argv[2]);
|
||||
|
||||
h = listen_socket(atoi(argv[1]));
|
||||
if (h < 0)
|
||||
if (h == \-1)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
for (;;) {
|
||||
|
@ -719,7 +719,7 @@ main(int argc, char **argv)
|
|||
|
||||
if (r == \-1 && errno == EINTR)
|
||||
continue;
|
||||
if (r < 0) {
|
||||
if (r == \-1) {
|
||||
perror("select()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -729,7 +729,7 @@ main(int argc, char **argv)
|
|||
|
||||
memset(&client_address, 0, l = sizeof(client_address));
|
||||
r = accept(h, (struct sockaddr *) &client_address, &l);
|
||||
if (r < 0) {
|
||||
if (r == \-1) {
|
||||
perror("accept()");
|
||||
} else {
|
||||
SHUT_FD1;
|
||||
|
@ -738,7 +738,7 @@ main(int argc, char **argv)
|
|||
buf2_avail = buf2_written = 0;
|
||||
fd1 = r;
|
||||
fd2 = connect_socket(forward_port, argv[3]);
|
||||
if (fd2 < 0)
|
||||
if (fd2 == \-1)
|
||||
SHUT_FD1;
|
||||
else
|
||||
printf("connect from %s\\n",
|
||||
|
|
Loading…
Reference in New Issue