0

I'm writing a server application (my first one) and I've come across a problem. I would like to make sure that every destructor is called on shut-down (saving data,..) and so I'm handling process signals. However, when my thread enters the blocking accept call, it obviously won't exit until a connection is accepted.

How should I go about implementing this? I would prefer if I could simply indicate whether to enter blocking accept by a variable, but that is probably not possible (or desirable with regards to how the application should run). Is the best way to use select (creating a temporary file that will be writen to when a signal is caught)?

  • Isn't there a timeout on this blocking call? – Fiddling Bits Nov 21 '13 at 18:55
  • 1
    It's a little bit unclear what you're asking. If a signal comes during a blocking `accept()` call, the `accept()` call will return `EINTR`, so your program should be able to exit. I'm not quite sure how indicating whether or not you want `accept()` to block would help; were you planning on just polling it repeatedly in a loop? That would use a lot of CPU time; `select()` is definitely preferable to busy waiting. Can you show a snippet of what you're trying to do? It's a bit easier to discuss a concrete example. – Brian Campbell Nov 21 '13 at 19:07
  • It's actually a little more complex than that, I tried to make it simplier with my question, but I see now that I was being quite unclear. Either way, select on a temp fd will probably be the right answer to my problem, I just wasn't sure if there is anything better. Thanks for your answer. – user2524502 Nov 21 '13 at 19:27
  • possible duplicate of [Wake up thread blocked on accept() call](http://stackoverflow.com/questions/2486335/wake-up-thread-blocked-on-accept-call) and/or [Non-blocking socket accept without spinlock in C](http://stackoverflow.com/a/13323696/132382). The given answers are POSIXly implementable. – pilcrow Nov 21 '13 at 19:32

1 Answers1

0

What exactly do you want to deallocate? You could use free(pointer to the structure) to deallocate.

erbdex
  • 1,899
  • 3
  • 22
  • 40