Changeset 14652


Ignore:
Timestamp:
Jan 2, 2016, 3:23:38 PM (6 years ago)
Author:
mikedld
Message:

#5663: Emulate GetOverlappedResultEx on Windows Vista/7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/watchdir-win32.c

    r14651 r14652  
    6262***/
    6363
     64static BOOL
     65tr_get_overlapped_result_ex (HANDLE       handle,
     66                             LPOVERLAPPED overlapped,
     67                             LPDWORD      bytes_transferred,
     68                             DWORD        timeout,
     69                             BOOL         alertable)
     70{
     71  typedef BOOL (WINAPI * impl_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
     72
     73  static impl_t real_impl = NULL;
     74  static bool is_real_impl_valid = false;
     75
     76  if (!is_real_impl_valid)
     77    {
     78      real_impl = (impl_t) GetProcAddress (GetModuleHandleW (L"kernel32.dll"),
     79                                           "GetOverlappedResultEx");
     80      is_real_impl_valid = true;
     81    }
     82
     83  if (real_impl != NULL)
     84    return real_impl (handle, overlapped, bytes_transferred, timeout, alertable);
     85
     86  const DWORD wait_result = WaitForSingleObjectEx (handle, timeout, alertable);
     87  if (wait_result == WAIT_FAILED)
     88    return FALSE;
     89  if (wait_result == WAIT_IO_COMPLETION || wait_result == WAIT_TIMEOUT)
     90    {
     91      SetLastError (wait_result);
     92      return FALSE;
     93    }
     94
     95  assert (wait_result == WAIT_OBJECT_0);
     96
     97  return GetOverlappedResult (handle, overlapped, bytes_transferred, FALSE);
     98}
     99
    64100static unsigned int __stdcall
    65101tr_watchdir_win32_thread (void * context)
     
    69105  DWORD bytes_transferred;
    70106
    71   while (GetOverlappedResultEx (backend->fd, &backend->overlapped, &bytes_transferred,
    72                                 INFINITE, FALSE))
     107  while (tr_get_overlapped_result_ex (backend->fd, &backend->overlapped, &bytes_transferred,
     108                                      INFINITE, FALSE))
    73109    {
    74110      PFILE_NOTIFY_INFORMATION info = (PFILE_NOTIFY_INFORMATION) backend->buffer;
Note: See TracChangeset for help on using the changeset viewer.