我在c-unix语言中创建了一个多进程客户端服务器。每个与客户端的连接都作为子进程管理。
当出现错误时,我只需调用exit(EXIT_FAILURE)函数,因为我读到这个函数会关闭所有打开的流。
问题是:我需要关闭客户端套接字描述符吗?或者关闭是自动进行的?
我的代码示例如下:
我的代码示例如下:
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?
}