nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GIO - GLib Input, Output and Streaming Library |
2 | * |
||
3 | * Copyright (C) 2006-2007 Red Hat, Inc. |
||
4 | * |
||
5 | * This library is free software; you can redistribute it and/or |
||
6 | * modify it under the terms of the GNU Lesser General Public |
||
7 | * License as published by the Free Software Foundation; either |
||
8 | * version 2 of the License, or (at your option) any later version. |
||
9 | * |
||
10 | * This library is distributed in the hope that it will be useful, |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
13 | * Lesser General Public License for more details. |
||
14 | * |
||
15 | * You should have received a copy of the GNU Lesser General |
||
16 | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
||
17 | * |
||
18 | * Author: Alexander Larsson <alexl@redhat.com> |
||
19 | */ |
||
20 | |||
21 | #include "config.h" |
||
22 | |||
23 | #include "gasynchelper.h" |
||
24 | |||
25 | |||
26 | /*< private > |
||
27 | * SECTION:gasynchelper |
||
28 | * @short_description: Asynchronous Helper Functions |
||
29 | * @include: gio/gio.h |
||
30 | * @see_also: #GAsyncResult |
||
31 | * |
||
32 | * Provides helper functions for asynchronous operations. |
||
33 | * |
||
34 | **/ |
||
35 | |||
36 | #ifdef G_OS_WIN32 |
||
37 | gboolean |
||
38 | _g_win32_overlap_wait_result (HANDLE hfile, |
||
39 | OVERLAPPED *overlap, |
||
40 | DWORD *transferred, |
||
41 | GCancellable *cancellable) |
||
42 | { |
||
43 | GPollFD pollfd[2]; |
||
44 | gboolean result = FALSE; |
||
45 | gint num, npoll; |
||
46 | |||
47 | pollfd[0].fd = (gint)overlap->hEvent; |
||
48 | pollfd[0].events = G_IO_IN; |
||
49 | num = 1; |
||
50 | |||
51 | if (g_cancellable_make_pollfd (cancellable, &pollfd[1])) |
||
52 | num++; |
||
53 | |||
54 | loop: |
||
55 | npoll = g_poll (pollfd, num, -1); |
||
56 | if (npoll <= 0) |
||
57 | /* error out, should never happen */ |
||
58 | goto end; |
||
59 | |||
60 | if (g_cancellable_is_cancelled (cancellable)) |
||
61 | { |
||
62 | /* CancelIO only cancels pending operations issued by the |
||
63 | * current thread and since we're doing only sync operations, |
||
64 | * this is safe.... */ |
||
65 | /* CancelIoEx is only Vista+. Since we have only one overlap |
||
66 | * operaton on this thread, we can just use: */ |
||
67 | result = CancelIo (hfile); |
||
68 | g_warn_if_fail (result); |
||
69 | } |
||
70 | |||
71 | result = GetOverlappedResult (overlap->hEvent, overlap, transferred, FALSE); |
||
72 | if (result == FALSE && |
||
73 | GetLastError () == ERROR_IO_INCOMPLETE && |
||
74 | !g_cancellable_is_cancelled (cancellable)) |
||
75 | goto loop; |
||
76 | |||
77 | end: |
||
78 | if (num > 1) |
||
79 | g_cancellable_release_fd (cancellable); |
||
80 | |||
81 | return result; |
||
82 | } |
||
83 | #endif |