-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting read timeout fails (Bad file descriptor) #69
Comments
I believe you need to connect or bind the socket first, then you can set the timeout. |
Actually, I would like to set the timeout of connect function itself, my app logic shouldn't wait for a long time to connect. I get the error message "Connection timeout" after 35-40 seconds which is too much for me and I need the waiting time for connection not to exceed 10 seconds at most. That's why I'm looking for a way to set the timeout to be around 10 seconds. I just found read_timeout and write_timeout in your library. Could you tell me if it is possible to set the timeout for connect function ? |
This library is just a very thin wrapper around the operating system's socket library. Our My understanding is that the timeout depends on the Operating System (Windows? Linux? Mac? etc) and the type of socket you're trying to connect (TCP v4? v6? etc). But I believe that for most systems, it can only be changed on a per-host or maybe per-process basis - not for individual connections. Do an internet search for the OS, socket type, and "connect timeout". That might get you the information you need. For example, this is a nice little writeup for Linux: |
I have used set_option function in the library to set tcp_syn_retries to lower number to speedup the connection timeout, and the function it returns 0 which means it succeeded. However, I still get the "connection timeout" error message after around 35 seconds.
this code is based on this answer: https://stackoverflow.com/questions/2597608/c-socket-connection-timeout#:~:text=The%20answers%20about%20using%20select()/poll()%20are%20right%20and%20code%20should%20be%20written%20this%20way%20to%20be%20portable. Do you have any idea why it is not working ? |
1: set socket nonblocking |
Wow! Buried in PR #17, there's a commit (3dd60e6) to add connect timeouts! I hadn't noticed that before. It's similar to what you describe. I haven't had time to pull in that PR and add finish TLS support the way I want it implemented, but I knew there was some good stuff in there that I might want to cherry pick. Apologies that I hadn't spotted it before. |
I cherry-picked that commit from PR #17 (and a few others). So now the connector class has a constructor and connect() method with a timeout. It was released in v0.8.1. If this doesn't work for you, please re-open with some details. |
I tried to set the read timeout using read_timeout function in stream_socket.h but it failed. I got "Bad file descriptor" error message.
Is there a way to set the timeout or changing the default timout if that's possible ?
The text was updated successfully, but these errors were encountered: