unix.7: Minor tweaks to Heinrich's patch

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2016-01-08 20:40:30 +01:00
parent 15545eb6d7
commit eb73e8ad50
1 changed files with 24 additions and 22 deletions

View File

@ -622,30 +622,29 @@ pathname sockets follow the rules outlined above under
.SH EXAMPLE
The following code demonstrates the usage of sockets for local interprocess
communication.
It comprises two programs.
It consists of two programs.
The server program waits for a connection from the client program.
The client sends all of its command line arguments.
The client sends all of its command-line arguments.
The server treats them as integers and adds them up.
The client sends the command string END.
The client sends the command string "END".
The server returns the result.
The client prints the sum of the received integers and exits.
The server waits for the next client to connect.
To stop the server the client is called with the command line argument
DOWN.
To stop the server the client is called with the command-line argument "DOWN".
.PP
The following output was recorded while running the server in the background
and repeatedly calling the client.
Execution of the server program ended when receiving the DOWN command.
Execution of the server program ended when receiving the "DOWN" command.
.SS Example output
.in +4n
.nf
$ ./server &
$ \fB./server &\fP
[1] 25887
$ ./client 3 4
$ \fB./client 3 4\fP
Result = 7
$ ./client 11 \-5
$ \fB./client 11 \-5\fP
Result = 6
$ ./client DOWN
$ \fB./client DOWN\fP
Result = 0
[1]+ Done ./server
$
@ -684,7 +683,7 @@ main(int argc, char *argv[])
char buffer[BUFFER_SIZE];
/*
* In case the program exited inadvertently on the last run
* In case the program exited inadvertently on the last run,
* remove the socket.
*/
@ -699,8 +698,9 @@ main(int argc, char *argv[])
}
/*
* For portability clear the whole structure, since some implementations
* have additional (nonstandard) fields in the structure.
* For portability clear the whole structure, since some
* implementations have additional (nonstandard) fields in
* the structure.
*/
memset(&name, 0, sizeof(struct sockaddr_un));
@ -718,8 +718,9 @@ main(int argc, char *argv[])
}
/*
* Prepare for accepting connections. The backlog size is set to 20. So
* while one request is being processed other requests can be waiting.
* Prepare for accepting connections. The backlog size is set
* to 20. So while one request is being processed other requests
* can be waiting.
*/
ret = listen(connection_socket, 20);
@ -748,7 +749,7 @@ main(int argc, char *argv[])
ret = read(data_socket, buffer, BUFFER_SIZE);
if (ret == \-1) {
perror("recv");
perror("read");
exit(EXIT_FAILURE);
}
@ -778,7 +779,7 @@ main(int argc, char *argv[])
ret = write(data_socket, buffer, BUFFER_SIZE);
if (ret == \-1) {
perror("send");
perror("write");
exit(EXIT_FAILURE);
}
@ -833,8 +834,9 @@ main(int argc, char *argv[])
}
/*
* For portability clear the whole structure, since some implementations
* have additional (nonstandard) fields in the structure.
* For portability clear the whole structure, since some
* implementations have additional (nonstandard) fields in
* the structure.
*/
memset(&name, 0, sizeof(struct sockaddr_un));
@ -856,7 +858,7 @@ main(int argc, char *argv[])
for (i = 1; i < argc; ++i) {
ret = write(data_socket, argv[i], strlen(argv[i]) + 1);
if (ret == \-1) {
perror("send");
perror("write");
break;
}
}
@ -866,7 +868,7 @@ main(int argc, char *argv[])
strcpy (buffer, "END");
ret = write(data_socket, buffer, strlen(buffer) + 1);
if (ret == \-1) {
perror("send");
perror("write");
exit(EXIT_FAILURE);
}
@ -875,7 +877,7 @@ main(int argc, char *argv[])
ret = read(data_socket, buffer, BUFFER_SIZE);
if (ret == \-1) {
perror("recv");
perror("read");
exit(EXIT_FAILURE);
}