Ask about the purpose and meaning of some code
Opened this issue · 1 comments
This was the first project I studied, probably because of my limited ability, and I found that some places were not well understood. The following three points are some of my questions. Thank you for your guidance.
(1) Why isn't pid < 3
here? Is there any special meaning for pid
being 2
?
Lines 411 to 416 in b1acf3c
(2) Why does the bench()
function return i
? Isn't this the speed
value that the parent process successfully read the last time? Could I change the program to return 0
?
Line 435 in b1acf3c
(3) Add
close(sock);
is it more rigorous?Lines 54 to 55 in b1acf3c
This was the first project I studied, probably because of my limited ability, and I found that some places were not well understood. The following three points are some of my questions. Thank you for your guidance.
(1) Why isn't
pid < 3
here? Is there any special meaning forpid
being2
?
Lines 411 to 416 in b1acf3c
(2) Why does the
bench()
functionreturn i
? Isn't this thespeed
value that the parent process successfully read the last time? Could I change the program toreturn 0
?
Line 435 in b1acf3c
(3) Add
close(sock);
is it more rigorous?
Lines 54 to 55 in b1acf3c
My personal opinion:
(1): Because in common Linux operating systems, the PID of 0 and 1 have been occupied by the process operating system and the software which cooperates with the operating system.
(2): Currently, I'm facing the same problem with you, and I think you are true.
(3): Use man 3 connect
, and I have found this sentenceAPPLICATION USAGE: If connect() fails, the state of the socket is unspecified. Conforming applications should close the file descriptor and create a new socket before attempting to reconnect. So I agree with you.