Blame gio/gasynchelper.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "gasynchelper.h"
Packit ae235b
Packit ae235b
Packit ae235b
/*< private >
Packit ae235b
 * SECTION:gasynchelper
Packit ae235b
 * @short_description: Asynchronous Helper Functions
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 * @see_also: #GAsyncResult
Packit ae235b
 * 
Packit ae235b
 * Provides helper functions for asynchronous operations.
Packit ae235b
 *
Packit ae235b
 **/
Packit ae235b
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
gboolean
Packit ae235b
_g_win32_overlap_wait_result (HANDLE           hfile,
Packit ae235b
                              OVERLAPPED      *overlap,
Packit ae235b
                              DWORD           *transferred,
Packit ae235b
                              GCancellable    *cancellable)
Packit ae235b
{
Packit ae235b
  GPollFD pollfd[2];
Packit ae235b
  gboolean result = FALSE;
Packit ae235b
  gint num, npoll;
Packit ae235b
Packit ae235b
#if GLIB_SIZEOF_VOID_P == 8
Packit ae235b
  pollfd[0].fd = (gint64)overlap->hEvent;
Packit ae235b
#else
Packit ae235b
  pollfd[0].fd = (gint)overlap->hEvent;
Packit ae235b
#endif
Packit ae235b
  pollfd[0].events = G_IO_IN;
Packit ae235b
  num = 1;
Packit ae235b
Packit ae235b
  if (g_cancellable_make_pollfd (cancellable, &pollfd[1]))
Packit ae235b
    num++;
Packit ae235b
Packit ae235b
loop:
Packit ae235b
  npoll = g_poll (pollfd, num, -1);
Packit ae235b
  if (npoll <= 0)
Packit ae235b
    /* error out, should never happen */
Packit ae235b
    goto end;
Packit ae235b
Packit ae235b
  if (g_cancellable_is_cancelled (cancellable))
Packit ae235b
    {
Packit ae235b
      /* CancelIO only cancels pending operations issued by the
Packit ae235b
       * current thread and since we're doing only sync operations,
Packit ae235b
       * this is safe.... */
Packit ae235b
      /* CancelIoEx is only Vista+. Since we have only one overlap
Packit ae235b
       * operaton on this thread, we can just use: */
Packit ae235b
      result = CancelIo (hfile);
Packit ae235b
      g_warn_if_fail (result);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  result = GetOverlappedResult (overlap->hEvent, overlap, transferred, FALSE);
Packit ae235b
  if (result == FALSE &&
Packit ae235b
      GetLastError () == ERROR_IO_INCOMPLETE &&
Packit ae235b
      !g_cancellable_is_cancelled (cancellable))
Packit ae235b
    goto loop;
Packit ae235b
Packit ae235b
end:
Packit ae235b
  if (num > 1)
Packit ae235b
    g_cancellable_release_fd (cancellable);
Packit ae235b
Packit ae235b
  return result;
Packit ae235b
}
Packit ae235b
#endif