X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgasynchelper.c;h=7cf86f1b7d7b372fce7efde3a537672be40a0dab;hb=174ebaefcc2b1b94f4a628e60f150b7209230dbf;hp=fa63dfee97df50230806f684e49fc530362820ad;hpb=8a7d33024a377c99ca17b37ff5f02854bb71463b;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gasynchelper.c b/gio/gasynchelper.c index fa63dfe..7cf86f1 100644 --- a/gio/gasynchelper.c +++ b/gio/gasynchelper.c @@ -13,9 +13,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Author: Alexander Larsson */ @@ -29,142 +27,57 @@ * SECTION:gasynchelper * @short_description: Asynchronous Helper Functions * @include: gio/gio.h - * @see_also: #GAsyncReady + * @see_also: #GAsyncResult * * Provides helper functions for asynchronous operations. * **/ -/************************************************************************* - * fd source * - ************************************************************************/ - -typedef struct -{ - GSource source; - GPollFD pollfd; -} FDSource; - -static gboolean -fd_source_prepare (GSource *source, - gint *timeout) -{ - *timeout = -1; - return FALSE; -} - -static gboolean -fd_source_check (GSource *source) -{ - FDSource *fd_source = (FDSource *)source; - - return fd_source->pollfd.revents != 0; -} - -static gboolean -fd_source_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data) - -{ - GFDSourceFunc func = (GFDSourceFunc)callback; - FDSource *fd_source = (FDSource *)source; - - g_warn_if_fail (func != NULL); - - return (*func) (fd_source->pollfd.fd, fd_source->pollfd.revents, user_data); -} - -static void -fd_source_finalize (GSource *source) +#ifdef G_OS_WIN32 +gboolean +_g_win32_overlap_wait_result (HANDLE hfile, + OVERLAPPED *overlap, + DWORD *transferred, + GCancellable *cancellable) { -} + GPollFD pollfd[2]; + gboolean result = FALSE; + gint num, npoll; -static gboolean -fd_source_closure_callback (int fd, - GIOCondition condition, - gpointer data) -{ - GClosure *closure = data; + pollfd[0].fd = (gint)overlap->hEvent; + pollfd[0].events = G_IO_IN; + num = 1; - GValue params[2] = { { 0, }, { 0, } }; - GValue result_value = { 0, }; - gboolean result; + if (g_cancellable_make_pollfd (cancellable, &pollfd[1])) + num++; - g_value_init (&result_value, G_TYPE_BOOLEAN); +loop: + npoll = g_poll (pollfd, num, -1); + if (npoll <= 0) + /* error out, should never happen */ + goto end; - g_value_init (¶ms[0], G_TYPE_INT); - g_value_set_int (¶ms[0], fd); - - g_value_init (¶ms[1], G_TYPE_IO_CONDITION); - g_value_set_flags (¶ms[1], condition); + 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 + * operaton on this thread, we can just use: */ + result = CancelIo (hfile); + g_warn_if_fail (result); + } - g_closure_invoke (closure, &result_value, 2, params, NULL); + result = GetOverlappedResult (overlap->hEvent, overlap, transferred, FALSE); + if (result == FALSE && + GetLastError () == ERROR_IO_INCOMPLETE && + !g_cancellable_is_cancelled (cancellable)) + goto loop; - result = g_value_get_boolean (&result_value); - g_value_unset (&result_value); - g_value_unset (¶ms[0]); - g_value_unset (¶ms[1]); +end: + if (num > 1) + g_cancellable_release_fd (cancellable); return result; } - -static void -fd_source_closure_marshal (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - GFDSourceFunc callback; - GCClosure *cc = (GCClosure*) closure; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 0); - - callback = (GFDSourceFunc) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (g_value_get_int (param_values), - g_value_get_flags (param_values + 1), - closure->data); - - g_value_set_boolean (return_value, v_return); -} - -static GSourceFuncs fd_source_funcs = { - fd_source_prepare, - fd_source_check, - fd_source_dispatch, - fd_source_finalize, - (GSourceFunc)fd_source_closure_callback, - (GSourceDummyMarshal)fd_source_closure_marshal, -}; - -GSource * -_g_fd_source_new (int fd, - gushort events, - GCancellable *cancellable) -{ - GSource *source; - FDSource *fd_source; - - source = g_source_new (&fd_source_funcs, sizeof (FDSource)); - fd_source = (FDSource *)source; - - fd_source->pollfd.fd = fd; - fd_source->pollfd.events = events; - g_source_add_poll (source, &fd_source->pollfd); - - if (cancellable) - { - GSource *cancellable_source = g_cancellable_source_new (cancellable); - - g_source_set_dummy_callback (cancellable_source); - g_source_add_child_source (source, cancellable_source); - g_source_unref (cancellable_source); - } - - return source; -} +#endif