title: Using Auto and Lambda to handle Signal?
body: <p>I have written this program that has a main function, inside which, I am creating two sockets, like this:</p>
  
  <pre><code>int sockfd1 = socket(AF_INET, SOCK_STREAM, 0);
  int sockfd2 = socket(AF_INET, SOCK_STREAM, 0);
  </code></pre>
  
  <p>Now I do some stuff with them, and when the user presses Ctrl+C to terminate the process, I want to make sure the sockets close properly, so I do this:</p>
  
  <pre><code>auto sigTermHandler = [&amp;] (int param) { close(sockfd1); close(sockfd2); };
  signal(SIGTERM, sigTermHandler);
  </code></pre>
  
  <p>But this throws the following compilation error when compiled as <code>g++ -std=gnu++0x &lt;filename&gt;.cpp</code>:</p>
  
  <pre><code>error: cannot convert ‘main(int, char**)::&lt;lambda(int)&gt;’ to ‘__sighandler_t {aka void (*)(int)}’ for argument ‘2’ to ‘void (* signal(int, __sighandler_t))(int)’
  </code></pre>
  
  <p>Is it not possible to use lambda this way to handle signals? Please advise.</p>
  
  <p>P.S. I know I could put that in a destructor, if I did proper OOP, but I am curious to see if this works.</p>