1

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.

I've set on the client a sigup handler like this

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

signal(SIGPIPE,SIG_IGN); 

but, if the client close the windows of the terminal, the server loops.

Any idea? Thank you anyway for support

  • 1
    Loops why/how? You haven't really provided enough information here. I'd have to guess that once the socket gets trashed the read or write calls being made on the socket are always returning immediately, because it's now an error to read/write. You need to detect that and discard the socket or take whatever action is appropriate... IF that's what's happening... – Michael Dec 16 '15 at 18:33
  • If you ignore SIGPIPE, the write operations will return an error setting `errno` to `EINTR`. This is useful as long as you consistently and carefully test that your write operations succeed (and take appropriate action when they don't succeed — which means stop trying to write). Otherwise, it is a recipe for disaster. – Jonathan Leffler Dec 16 '15 at 18:47
  • 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? Client close the terminal Server need to go ahead Have you got any idea to suggest to me? Thank you – Maria de gregorio Dec 16 '15 at 20:04

1 Answers1

0

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. Alternatively you could prevent the generation of SIGPIPE by giving the MSG_NOSIGNAL flag to send().

Armali
  • 18,255
  • 14
  • 57
  • 171