2007-11-26 17:13:05 +01:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
*
|
2022-05-18 10:12:45 +02:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2017-05-27 18:21:30 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
2014-01-23 12:58:29 +01:00
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
#include "gasynchelper.h"
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
|
2011-09-06 06:12:12 +02:00
|
|
|
/*< private >
|
2023-10-23 01:08:51 +02:00
|
|
|
* GAsyncHelper:
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* Provides helper functions for asynchronous operations.
|
2023-10-23 01:08:51 +02:00
|
|
|
*/
|
2007-11-27 15:00:13 +01:00
|
|
|
|
2012-07-02 21:45:41 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
gboolean
|
|
|
|
_g_win32_overlap_wait_result (HANDLE hfile,
|
|
|
|
OVERLAPPED *overlap,
|
|
|
|
DWORD *transferred,
|
2012-07-06 00:46:32 +02:00
|
|
|
GCancellable *cancellable)
|
2012-07-02 21:45:41 +02:00
|
|
|
{
|
2012-07-06 00:46:32 +02:00
|
|
|
GPollFD pollfd[2];
|
2012-07-02 21:45:41 +02:00
|
|
|
gboolean result = FALSE;
|
|
|
|
gint num, npoll;
|
|
|
|
|
2017-01-16 09:50:01 +01:00
|
|
|
#if GLIB_SIZEOF_VOID_P == 8
|
|
|
|
pollfd[0].fd = (gint64)overlap->hEvent;
|
|
|
|
#else
|
2012-07-02 21:45:41 +02:00
|
|
|
pollfd[0].fd = (gint)overlap->hEvent;
|
2017-01-16 09:50:01 +01:00
|
|
|
#endif
|
2012-07-02 21:45:41 +02:00
|
|
|
pollfd[0].events = G_IO_IN;
|
|
|
|
num = 1;
|
|
|
|
|
2012-07-06 00:46:32 +02:00
|
|
|
if (g_cancellable_make_pollfd (cancellable, &pollfd[1]))
|
|
|
|
num++;
|
|
|
|
|
|
|
|
loop:
|
2012-07-02 21:45:41 +02:00
|
|
|
npoll = g_poll (pollfd, num, -1);
|
|
|
|
if (npoll <= 0)
|
|
|
|
/* error out, should never happen */
|
|
|
|
goto end;
|
|
|
|
|
2012-07-06 00:46:32 +02:00
|
|
|
if (g_cancellable_is_cancelled (cancellable))
|
|
|
|
{
|
|
|
|
/* CancelIO only cancels pending operations issued by the
|
|
|
|
* current thread and since we're doing only sync operations,
|
|
|
|
* this is safe.... */
|
|
|
|
/* CancelIoEx is only Vista+. Since we have only one overlap
|
2020-06-12 15:02:30 +02:00
|
|
|
* operation on this thread, we can just use: */
|
2012-07-06 00:46:32 +02:00
|
|
|
result = CancelIo (hfile);
|
|
|
|
g_warn_if_fail (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = GetOverlappedResult (overlap->hEvent, overlap, transferred, FALSE);
|
|
|
|
if (result == FALSE &&
|
|
|
|
GetLastError () == ERROR_IO_INCOMPLETE &&
|
|
|
|
!g_cancellable_is_cancelled (cancellable))
|
|
|
|
goto loop;
|
2012-07-02 21:45:41 +02:00
|
|
|
|
|
|
|
end:
|
2012-07-06 00:46:32 +02:00
|
|
|
if (num > 1)
|
|
|
|
g_cancellable_release_fd (cancellable);
|
|
|
|
|
2012-07-02 21:45:41 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|