1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include "gasynchelper.h"
31 * Provides helper functions for asynchronous operations.
36 _g_win32_overlap_wait_result (HANDLE hfile,
39 GCancellable *cancellable)
42 gboolean result = FALSE;
45 #if GLIB_SIZEOF_VOID_P == 8
46 pollfd[0].fd = (gint64)overlap->hEvent;
48 pollfd[0].fd = (gint)overlap->hEvent;
50 pollfd[0].events = G_IO_IN;
53 if (g_cancellable_make_pollfd (cancellable, &pollfd[1]))
57 npoll = g_poll (pollfd, num, -1);
59 /* error out, should never happen */
62 if (g_cancellable_is_cancelled (cancellable))
64 /* CancelIO only cancels pending operations issued by the
65 * current thread and since we're doing only sync operations,
67 /* CancelIoEx is only Vista+. Since we have only one overlap
68 * operation on this thread, we can just use: */
69 result = CancelIo (hfile);
70 g_warn_if_fail (result);
73 result = GetOverlappedResult (overlap->hEvent, overlap, transferred, FALSE);
74 if (result == FALSE &&
75 GetLastError () == ERROR_IO_INCOMPLETE &&
76 !g_cancellable_is_cancelled (cancellable))
81 g_cancellable_release_fd (cancellable);