int do_eventsel_loop(HANDLE other_event)
{
int n, nhandles, nallhandles, netindex, otherindex;
- long next, ticks;
+ unsigned long next, then;
+ long ticks;
HANDLE *handles;
SOCKET *sklist;
int skcount;
- long now = GETTICKCOUNT();
+ unsigned long now = GETTICKCOUNT();
- if (run_timers(now, &next)) {
- ticks = next - GETTICKCOUNT();
- if (ticks < 0) ticks = 0; /* just in case */
+ if (toplevel_callback_pending()) {
+ ticks = 0;
+ next = now;
+ } else if (run_timers(now, &next)) {
+ then = now;
+ now = GETTICKCOUNT();
+ if (now - then > next - then)
+ ticks = 0;
+ else
+ ticks = next - now;
} else {
ticks = INFINITE;
+ /* no need to initialise next here because we can never get
+ * WAIT_TIMEOUT */
}
handles = handle_get_events(&nhandles);
sfree(handles);
+ run_toplevel_callbacks();
+
if (n == WAIT_TIMEOUT) {
now = next;
} else {
if (p_WSAEventSelect == NULL) {
fd_set readfds;
int ret;
- long now = GETTICKCOUNT();
+ unsigned long now = GETTICKCOUNT(), then;
if (sftp_ssh_socket == INVALID_SOCKET)
return -1; /* doom */
select_result((WPARAM) sftp_ssh_socket, (LPARAM) FD_WRITE);
do {
- long next, ticks;
+ unsigned long next;
+ long ticks;
struct timeval tv, *ptv;
if (run_timers(now, &next)) {
- ticks = next - GETTICKCOUNT();
- if (ticks <= 0)
- ticks = 1; /* just in case */
+ then = now;
+ now = GETTICKCOUNT();
+ if (now - then > next - then)
+ ticks = 0;
+ else
+ ticks = next - now;
tv.tv_sec = ticks / 1000;
tv.tv_usec = ticks % 1000 * 1000;
ptv = &tv;
int ret;
struct command_read_ctx actx, *ctx = &actx;
DWORD threadid;
+ HANDLE hThread;
fputs(prompt, stdout);
fflush(stdout);
ctx->event = CreateEvent(NULL, FALSE, FALSE, NULL);
ctx->line = NULL;
- if (!CreateThread(NULL, 0, command_read_thread,
- ctx, 0, &threadid)) {
+ hThread = CreateThread(NULL, 0, command_read_thread, ctx, 0, &threadid);
+ if (!hThread) {
+ CloseHandle(ctx->event);
fprintf(stderr, "Unable to create command input thread\n");
cleanup_exit(1);
}
assert(ret >= 0);
} while (ret == 0);
+ CloseHandle(hThread);
+ CloseHandle(ctx->event);
+
return ctx->line;
}