Add a version of dhcpctl_wait_completion() that accepts a timeout
Per support ticket:
https://support.isc.org/Ticket/Display.html?id=15842
Calling dhcpctl_wait_completion() has two shortcomings:
- First, it does not provide a timeout parameter and thus may effectively hang
- Underneath the covers the way the logic is structured in omapi/dispatch.c, we end up effectively using the select() calls to poll in a tight loop eating CPU.
The first issue is simply address. The latter is a bit more sticky. The select calls are with omapi_dispatch_one(). They monitor the read and write sides of OMAPI connections. However, once the basic socket connection is made, the write side virtually ALWAYS tests as ready to write, thus even passing in a timeout value as shown in the second call below:
isc_result_t omapi_one_dispatch (omapi_object_t *wo,
struct timeval *t)
{
:
/* poll once */
count = select(max + 1, &r, &w, &x, &now);
if (!count) {
/* We are dry now */
trigger_event(&rw_queue_empty);
/* Wait for a packet or a timeout... XXX */
r = rr;
w = ww;
x = xx;
count = select(max + 1, &r, &w, &x, t ? &to : NULL);
}
:
results in an immediate return from select. Thus we should only test the write side of the socket for readiness to write if we are connected AND we have data to write.