-
Notifications
You must be signed in to change notification settings - Fork 25
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
Reads with deadline #22
Comments
This works:
What I found really confusing is that setDeadline() wants a time interval when, in fact, it wants a time point. But it still begs the question: why expect a time interval since the epoch, rather than a point in time? Also, wouldn't it be better to reject the operation at the time it is initiated when it has a deadline that is eons in the past? In other words, a deadline that is < current time is likely to be a bug. Requiring an absolute time point here might not be the right thing. For example, my thread might get suspended in between getting the current time and initiating the async call,; by the time the thread is resumed, the deadline can have expired already. Would it make sense to add a way to set the deadline such that I can say "n milliseconds after the call is initiated"? |
It is an unfortunate reality that timer APIs are a mix of absolute and relative times, with some supporting one but not the other, and some supporting both. For example In designing semantics for timeouts, I favor absolute times for imperative, executed code, and relative times for something like declarative configuration files (absolute timeouts are non-sensical there). There are some exceptions; the connection retry interval is in relative time because it applies a timeout relative to the start of the connection attempt. Relative timeouts in high-level function signatures feel less useful to me because you lose control of any sort of precise understanding when the timeout might actually fire: the thread may be preempted or otherwise "wait" for an indeterminate time before the effective timeout becomes applied. That being said, programmers may favor relative timeouts and there is no major reason for this library to only support absolute timeouts in its APIs. You raise two legitimate issues:
C++ has a nice tradition of using types to communicate semantics and using function overloads to separate intent. I would have vastly preferred to use some other type than I think we should tackle this issue by acknowledging another one: users should be able to use standard time types (from We add overloads for |
I agree with you. I raised this issue mainly because of the cognitive dissonance. I'm sure I won't be the only one to assume that a duration is needed rather than an absolute point in time. |
I have a client written with NTF. The client connects to an existing server. Immediately after connecting, it sends a 64-byte message to the server, and the server immediately responds with a 64-byte reply. Client and server run on the same machine and talk over the backplane. (The server is pre-existing code, not written using NTF.)
The client socket is created like so:
After establishing the connection and sending its 64-byte message, the client reads the server's reply like so:
This works just fine. The callback pops without error, and the client gets the expected response from the server.
Now I want to add a timeout of 500 ms to the client. If the reply from the server does not arrive in that time, the client can take some error action. So, I change the receive like so:
The only change here is to add the timeout to the receive options. Now things do not work. The server gets the message as usual and responds to it, but the callback in the client pops immediately with e_WOULD_BLOCK. If I run the client many times, after about 30 or 50 attempts, it successfully get the response from the server. The whole thing behaves like the timeout is zero or near zero. Every now and then, the response from the server arrives quickly enough, but most of the time, the timeout prevents things from working.
I played around with the timeout value:
This still fails. But once I add another zero, things work on the first try every time:
What gives?
The text was updated successfully, but these errors were encountered: