2
我用c-unix语言创建了一个多进程客户端服务器。 与客户端的每个连接均作为子进程进行管理。 当发生错误时,我只需调用函数出口(EXIT_FAILURE),因为我读到此函数关闭所有打开的流。 问题是:我必须关闭客户端套接字描述符还是关闭是自动的?套接字描述符是否由函数exit(退出代码)关闭?
我的代码的一个例子是:
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?
}