comparison src/channel.c @ 8757:4fb37555e814 v7.4.1667

commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 28 14:20:41 2016 +0200 patch 7.4.1667 Problem: Win32: waiting on a pipe with fixed sleep time. Solution: Start with a short delay and increase it when looping.
author Christian Brabandt <cb@256bit.org>
date Mon, 28 Mar 2016 14:30:05 +0200
parents 7038ec89d1fd
children cc2ef7367643
comparison
equal deleted inserted replaced
8756:72dbac4224b8 8757:4fb37555e814
2369 2369
2370 # ifdef WIN32 2370 # ifdef WIN32
2371 if (fd != channel->CH_SOCK_FD) 2371 if (fd != channel->CH_SOCK_FD)
2372 { 2372 {
2373 DWORD nread; 2373 DWORD nread;
2374 int diff; 2374 int sleep_time;
2375 DWORD deadline = GetTickCount() + timeout; 2375 DWORD deadline = GetTickCount() + timeout;
2376 int delay = 1;
2376 2377
2377 /* reading from a pipe, not a socket */ 2378 /* reading from a pipe, not a socket */
2378 while (TRUE) 2379 while (TRUE)
2379 { 2380 {
2380 if (PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL) 2381 if (PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL)
2381 && nread > 0) 2382 && nread > 0)
2382 return OK; 2383 return OK;
2383 diff = deadline - GetTickCount(); 2384 sleep_time = deadline - GetTickCount();
2384 if (diff <= 0) 2385 if (sleep_time <= 0)
2385 break; 2386 break;
2386 /* Wait for 5 msec. 2387 /* Wait for a little while. Very short at first, up to 10 msec
2387 * TODO: increase the sleep time when looping more often */ 2388 * after looping a few times. */
2388 Sleep(5); 2389 if (sleep_time > delay)
2390 sleep_time = delay;
2391 Sleep(sleep_time);
2392 delay = delay * 2;
2393 if (delay > 10)
2394 delay = 10;
2389 } 2395 }
2390 } 2396 }
2391 else 2397 else
2392 #endif 2398 #endif
2393 { 2399 {