Program Fragment:
int sock_fd; File *sock_fpo, *sock_fpi, *pipe_fp;sock_fd = accept (Sock_id, NULL, NULL); if (sock_fd == -1 ) oops ("accept"); if (Sock_fpi = fdopen (sock_fd, "R") == null) oops ("fdopen reading"); if (fgets (DIRNAME, BUFSIZ - 5, SOCK_FPI) == null) oops ("Reading dirname"); if ((Sock_fpo = fdopen (sock_fd, "w")) == null) oops ("fdopen writing") ; if ((Pipe_fp = popen (command, "R")) == NULL) oops ("Popen"); while ((C = getc (PIPE_FP)) != eof)        PUTC (C, SOCK_FPO); pclose (PIPE_FP); pclose (SOCK_FPO); pclose (SOCK_FPI);
This program fragment is a server socket fragment that was found during debugging. When I will:
Pclose (SOCK_FPO); Pclose (SOCK_FPI);
Change the order to:
Pclose (SOCK_FPI); Pclose (SOCK_FPO);
The data cannot be written to the socket correctly and passed to the client.
Summarize:
because: PIPE_FP, Sock_fpo, SOCK_FPI's open order is SOCK_FPI,SOCK_FPO,PIPE_FP.
Be sure to close the descriptor in reverse order, opening it first and then closing it. namely: PIPE_FP, Sock_fpo, SOCK_FPI.
Stream file shutdown sequence issues during socket programming