When I try to call a RPC function, which generated from an IDL file by midl tool, it blocks around 20 seconds (at the NdrGetBuffer function) if the IP bound in its RPC_BINDING_HANDLE is unreachable.
I tried to call RpcMgmtSetComTimeout function with RPC_C_BINDING_MIN_TIMEOUT value on its RPC_BINDING_HANDLE before calling that RPC function, but no help, still need to wait ~20 seconds.
Is there any way to shorten the timeout wait time on this case? Thanks a lot!
Elliott
I haven't tried this, but this link suggests that RpcSetBindingOption with RPC_C_OPT_CALL_TIMEOUT should allow you to set the callout.
However, there's still a 20 second timeout on the first call (so the server can start).
Related
Tell me please, i just can't figure out what the CURLMOPT_TIMERFUNCTION parameter is used for.
Yes, of course I read the entire description about CURLMOPT_TIMERFUNCTION:
CURLMOPT_TIMERFUNCTION
timer_callback
hiperfifo
And I still don't understand what he does and why he is wanted.
For example:
Certain features, such as timeouts and retries, require you to call
libcurl even when there is no activity on the file descriptors.
Your callback function timer_callback should install a non-repeating
timer with an expire time of timeout_ms milliseconds. When that timer
fires, call either curl_multi_socket_action or curl_multi_perform,
depending on which interface you use.
I don't understand why I should call curl_multi_socket_action() from the CURLMOPT_TIMERFUNCTION callback and not from the event callback?
This is for curl to take action when requests were not answered in time. You need to call curl back periodically so it does its own internal housekeeping.
Imagine you made a request to curl and curl took action on it but could not connect at that time. Curl cannot hang the process waiting for the connect so it returns the control to you and relies on you returning the control back to curl for checking if it can connect periodically.
I have a client/server program written in C++. I want to check the client response (an attribute of a C++ object) through a command send by the server, with a timeout if no response.
I am waiting for an expected value during some seconds. If the expected value is not observed, I need to return with a timeout. I was thinking about a thread and a poll to check the expected value in an specific time interval.
I wonder if C++11/14 features - std::promise, std::future, std::condition_variable or something else - can do it more easily for this case. The inconvenient i see about it is that i have to notice each changing value with a notify.
Well, i need some advice.
None of the C++ language features you mentioned can help in your scenario, because they are intended for interaction within a single running program - which may be multi-threaded, but not separated into two completely independent processes.
However, the networking library you are using (on the server side) might possibly have convenience facilities for doing this.
I realize this is a general and somewhat vague answer, but your question was also not very specific.
How to wait for a value with timeout
Within a process, one would typically use a condition variable.
I want to check the client response ... through a command send by the server
There is no standard way to communicate between processes in C++ (unless you count interaction with filesystem). As such, there is also no standard way to enforce a timeout on such communication.
Before you can know how to implement the timeout, you must figure out how you are going to communicate between the client and the server. That choice will be affected by what system you are targeting, so you should first figure that out.
If you are on a Linux environment you can try rpcgen and play with .x flies but you’ll have to study it a bit. Not sure for Windows env. Also you can use Dbus which is more intuitive.
[edit] Dbus or probably libdbus for you is an IPC cross platform toolkit or library that can fit your need. RPCGEN is an old tool that does the same thing but more complicated. I don’t have a snippet, I apologize but you can search for “qt dbus example”.
About the first requirement, server waits for a response with a timeout.
Have you tried select() or poll(). They can help us to monitor the socket connection between server and client in a period.
Or we can use signal() and alarm(), to check the response after a few seconds.
In Bekerley API, combine setsockopt() with SO_RCVTIMEO, SO_SNDTIMEO can also set the timeout for the request.
I'm not sure about the library you are implementing, but I hope it has any similar functions.
The second requirement, you are waiting for expected value for a duration.
I think condition variable is a good solution for this.
Why not using boost::thread with a timed_join?
boost::thread server_thread(::server_checker_method, arg1, arg2, arg3);
if (server_thread.timed_join(boost::posix_time::milliseconds(1000))) // wait for 1s
{
// Expected value found in the server in less than 1s
}
else
{
// Checking expected value took more than 1s, timeout !!!
}
You can put your checking mechanism in the server_checker_method and return if the expected values are OK. Otherwise, iterate over the loop until the timeout reaches.
I am now trying to write a program that waits two minutes and 25 seconds in C++. I use the Sleep function of like that:
Sleep(145000);
Now, my laptop heats up every time I run this function, and the fan starts working.
Now to the question - is this function known for being wasteful? Should I even use it? do I have a better option?
The Windows Sleep() function puts the current thread to sleep. It doesn't run a busy-waiting while-loop or anything like that, it just re-schedules the thread to start up again after the sleep period specified as the function parameter. If your fan is starting up, I suggest looking at the currently running processes using Task Manager.
Is there an easy way to determine if a file on a remote system exists without a 20-25 second hang if it doesn't?
Functions like...
PathFileExists();
GetFileAttributes();
...don't allow you to set a timeout duration, so when the file doesn't exist you end up waiting for a long time. I think it might be possible to put one of these calls into a thread and set the thread to expire after 1 second (or whatever), but I'd prefer to use a lightweight native Windows function or boost function rather than an inelegant threading solution.
It's a bit hard to prove a negative, but I will argue that no such method exists.
The normal Windows asynchronous I/O method uses the OVERLAPPED structure, and in its documentation it references the ReadFile and WriteFile methods. From the other side, no variant of GetFileAttributes mentions OVERLAPPED or asynchronous I/O. Hence, it seems safe to assume it is always synchronous.
AFAIK no, generally there’s no easy way.
If your server is configured to responds to pings, you can use IcmpSendEcho API to ping the server before accessing it’s shared files, the API’s quite simple and it accepts the timeout.
If your server doesn’t respond to pings (by default modern versions of Windows don’t), you can write a function that tries to connect to TCP port 135 or 445, if connected closes the connection and returns success, if failed returns error. This will allow you to implement shorter timeout than the default.
In both methods, you’ll need to resolve the network drive path into the name of the server, see e.g. GetVolumePathName API.
My application(A) in c++ makes curl call to another machine to start another application(B). When curl call is made by A then it waits till B finishes it's job. So I just want to ask that what is the default timeout for application A or it is by default disables i.e infinite timeout ?
From http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
CURLOPT_CONNECTTIMEOUT
Pass a long. It should contain the maximum time
in seconds that you allow the connection to the server to take. This
only limits the connection phase, once it has connected, this option
is of no more use. Set to zero to switch to the default built-in
connection timeout - 300 seconds. See also the CURLOPT_TIMEOUT option.
.
CURLOPT_TIMEOUT
Pass a long as parameter containing the maximum time in seconds that
you allow the libcurl transfer operation to take. Normally, name
lookups can take a considerable time and limiting operations to less
than a few minutes risk aborting perfectly normal operations. This
option will cause curl to use the SIGALRM to enable time-outing system
calls.
In unix-like systems, this might cause signals to be used unless
CURLOPT_NOSIGNAL is set.
Default timeout is 0 (zero) which means it never times out.