title: boost::asio signal_set - goes in loop
body: <p>I am trying to write a simple client which will send a message to server. The number of messages to send will be based on input given from stdin. The program is expected to run continuously until it is terminated. For termination routine, I am using boost signal set. On running the program the process will wait for me to key in the number of iterations. Now if I issue a kill -SIGTERM , the process goes in loop and starts printing "Enter number of messages to pump:". Can you please tell me what is the mistake here?</p>
  
  <pre><code>    boost::asio::io_service io_service;
      int main(int argc, char* argv[])
      {
          // Hardcoded the server IP and port
          tcp::socket sock(io_service);
          boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5001);
          boost::asio::signal_set signals(io_service, SIGTERM);
          signals.async_wait(boost::bind(&amp;boost::asio::io_service::stop, &amp;io_service));
          sock.connect(endpoint);
  
          while (true)
          {
            char request[max_length] = "Message to be sent";
  
            int iter = 0;
            cout &lt;&lt; "Enter number of messages to pump:";
            cin &gt;&gt; iter;
  
            for(int i=0 ; i &lt; iter; i++)
            {
              size_t request_length = strlen(request);
              boost::asio::write(sock, boost::asio::buffer(request, request_length));
              cout &lt;&lt; "Message written [" &lt;&lt; request_length &lt;&lt; "]:" &lt;&lt; request &lt;&lt; "\n";
            }
          }
      }
  </code></pre>