Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:13:59+00:00 2026-05-29T05:13:59+00:00

Possible Duplicate: How to set a timeout on blocking sockets in boost asio? I

  • 0

Possible Duplicate:
How to set a timeout on blocking sockets in boost asio?

I read some of the entries before about the timeout but I don’t understand.

I want a defined timeout for the connection.
the connect code looks like:

try{
  boost::asio::ip::tcp::resolver              resolver(m_ioService);
  boost::asio::ip::tcp::resolver::query       query(link.get_host(), link.get_scheme());
  boost::asio::ip::tcp::resolver::iterator    endpoint_iterator = resolver.resolve(query);
  boost::asio::ip::tcp::resolver::iterator    end;
  boost::system::error_code                   error   =   boost::asio::error::host_not_found;

  while (error && endpoint_iterator != end)
   {
    m_socket.close();
    m_socket.connect(*endpoint_iterator++, error);
   }
}

also I want a read timeout.

I use boost::asio::read_until(m_socket, response, "\r\n"); for read the header.

is it possible to set SIMPLE a timeout?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:13:59+00:00Added an answer on May 29, 2026 at 5:13 am

    Fist of all I believe that you should ALWAYS use the async methods since they are better and your design will only benefit from a reactor pattern approach.
    In the bad case that you’re in a hurry and you’re kind of prototyping, the sync methods can be useful. In this case I do agree with you that without any timeout support, they cannot be used in the real world.

    What I did was very simple:

    void HttpClientImpl::configureSocketTimeouts(boost::asio::ip::tcp::socket& socket)
    {
    #if defined OS_WINDOWS
        int32_t timeout = 15000;
        setsockopt(socket.native(), SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout));
        setsockopt(socket.native(), SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout));
    #else
        struct timeval tv;
        tv.tv_sec  = 15; 
        tv.tv_usec = 0;         
        setsockopt(socket.native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
        setsockopt(socket.native(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
    #endif
    }
    

    The code above works both on windows and on Linux and on MAC OS, according to the OS_WINDOWS macro.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is it possible to read from a Java InputStream with a timeout?
Possible Duplicate: How to set this Layout in iPhone need Some help I draw
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
Possible Duplicate: Retrieving the last record in each group I have two tables set
Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up
Possible Duplicate: setTimeout and “this” in JavaScript I am trying to put a timeout
Possible Duplicate: How do I programmatically set the background color gradient on a Custom
Possible Duplicate: How do I set HTTP_REFERER when testing in Rails? I tried request.env[HTTP_REFERER]
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Why is it an error to use an empty set of brackets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.