Workaround for Windows limit in su_wait
Windows has a 64 descriptor limit in WSAWaitForMultipleEvents system call. Implemented some custom login in su_wait to work around this limitation. Changed SU_WAIT_MAX from 64 to 0x7fffffff, like on other plaftorms.
This commit is contained in:
parent
d9f51f556f
commit
4c9d9301b0
|
@ -129,7 +129,7 @@ SOFIA_BEGIN_DECLS
|
|||
|
||||
#define SU_WAIT_INIT NULL
|
||||
|
||||
#define SU_WAIT_MAX (64)
|
||||
#define SU_WAIT_MAX (0x7fffffff)
|
||||
|
||||
#else
|
||||
/* If nothing works, try these */
|
||||
|
|
|
@ -224,10 +224,37 @@ int su_wait(su_wait_t waits[], unsigned n, su_duration_t timeout)
|
|||
#if SU_HAVE_WINSOCK
|
||||
DWORD i;
|
||||
|
||||
if (n > 0)
|
||||
i = WSAWaitForMultipleEvents(n, waits, FALSE, timeout, FALSE);
|
||||
else
|
||||
if (n > 0) {
|
||||
#define WAIT_EVENT_BLOCK_SIZE WSA_MAXIMUM_WAIT_EVENTS
|
||||
|
||||
/* Handle at most WAIT_EVENT_BLOCK_SIZE wait objects at a time */
|
||||
int blocks = (n + WAIT_EVENT_BLOCK_SIZE - 1) / WAIT_EVENT_BLOCK_SIZE;
|
||||
int block_index = 0;
|
||||
int first_wait_index = 0;
|
||||
int millisec_per_block = timeout / blocks;
|
||||
|
||||
if (timeout > 0)
|
||||
millisec_per_block = max(1, millisec_per_block);
|
||||
|
||||
i = WSA_WAIT_TIMEOUT;
|
||||
for(block_index = 0; block_index < blocks; block_index++,first_wait_index+=WAIT_EVENT_BLOCK_SIZE)
|
||||
{
|
||||
int remaining_blocks = n - block_index * WAIT_EVENT_BLOCK_SIZE;
|
||||
int waits_in_current_block = min( WAIT_EVENT_BLOCK_SIZE, remaining_blocks );
|
||||
|
||||
i = WSAWaitForMultipleEvents(waits_in_current_block, waits + first_wait_index, FALSE, millisec_per_block, FALSE);
|
||||
if (i != WSA_WAIT_TIMEOUT) {
|
||||
/* Did not timeout, return something NOW, ignore remaining blocks */
|
||||
if (i != WSA_WAIT_FAILED) {
|
||||
/* Return the right index */
|
||||
i += first_wait_index;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Sleep(timeout), SU_WAIT_TIMEOUT;
|
||||
}
|
||||
|
||||
if (i == WSA_WAIT_TIMEOUT)
|
||||
return SU_WAIT_TIMEOUT;
|
||||
|
|
Loading…
Reference in New Issue