Boost logo

Boost Users :

Subject: [Boost-users] Deadlock with boost::asio::ip::tcp::iostreamþ
From: Jeff Pai (irishbam_at_[hidden])
Date: 2010-06-30 20:15:51


Hi everyone,
I took the daytime example and add a request this iostream, and
it starts deadlocking in windows environment. Is this the wrong way to do
it?

int main(int argc, char* argv[])
{
  try
  {
    if (argc != 2)
    {
      std::cerr << "Usage: daytime_client <host>" << std::endl;
      return 1;
    }

    tcp::iostream s(argv[1], "daytime");
    s << "request";
    std::string line;
    std::getline(s, line);
    std::cout << line << std::endl;
  }
  catch (std::exception& e)
  {
    std::cout << "Exception: " << e.what() << std::endl;
  }

  return 0;
}

void
server()
{
  try
  {
    boost::asio::io_service
io_service;

    tcp::endpoint endpoint(tcp::v4(), 13);
    
tcp::acceptor acceptor(io_service, endpoint);

    for (;;)
    
{
      tcp::iostream stream;
      
acceptor.accept(*stream.rdbuf());
      std::string req;
      stream
>> req;
      stream << make_daytime_string();
    }
  
}
  catch (std::exception& e)
  {
    std::cerr << e.what()
<< std::endl;
  }
}
                                               
_________________________________________________________________
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net