I created a multi-process client-server in c-unix language. Every connection with a client is managed as a child process. When an error occurs, i simply call the function exit(EXIT_FAILURE), because i read that this function closes all open streams. The question is: do I have to close the client socket descriptor or closing is automatic?
an example of my code is:
while(1){
if((client_sock=accept(ds_sock,&client,&s_client))==-1){
printf("Accept error\n");
exit(EXIT_FAILURE);
}
if(fork()==0){ //child
if((close(ds_sock)==-1)){
printf("Closing error\n");
exit(EXIT_FAILURE);
}
if((read(client_sock,&up,sizeof(userpass)))==-1){
printf("Error read\n");
exit(EXIT_FAILURE); //Does this instruction close the client_sock too?
}