简体   繁体   English

通过Socket的C信号(信号管,叹气)

[英]C signal (sigpipe, sighup) via Socket

I've to handle the SIGHUP and the SIGPIPE signal in order to avoid that a CLIENT, connected via Socket TCP, closing the terminal (The [X] of the GUI) hadn't to close or crash the SERVER. 我必须处理SIGHUP和SIGPIPE信号,以避免通过套接字TCP连接的CLIENT关闭终端(GUI的[X])不会关闭或使SERVER崩溃。

I've set on the client a sigup handler like this 我已经在客户端设置了像这样的sigup处理程序

void sighup()
{
  signal(SIGHUP, SIG_IGN);
  system("echo SIGHUP received>>log.txt");
  close(socket);
  exit(0);
}

On the server I've set a SIGPIPE handler like this 在服务器上,我已经像这样设置了SIGPIPE处理程序

signal(SIGPIPE,SIG_IGN); 

but, if the client close the windows of the terminal, the server loops. 但是,如果客户端关闭终端窗口,则服务器会循环运行。

Any idea? 任何想法? Thank you anyway for support 还是谢谢你的支持

I did a mistake and I will put all check all write and read istructions with perror. 我犯了一个错误,我将全部检查所有带有读写的指令。 But, anyway, is that the right way to handle the situation? 但是,无论如何,这是处理情况的正确方法吗?

Ignoring SIGPIPE is viable. 忽略SIGPIPE是可行的。 Alternatively you could prevent the generation of SIGPIPE by giving the MSG_NOSIGNAL flag to send() . 另外,您可以通过将MSG_NOSIGNAL标志赋予send()来阻止SIGPIPE的生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM