static void gst_net_client_internal_clock_stop (GstNetClientInternalClock * self) { if (self->thread == NULL) return; GST_INFO_OBJECT (self, "stopping..."); g_cancellable_cancel (self->cancel); g_thread_join (self->thread); self->thread = NULL; if (self->made_cancel_fd) g_cancellable_release_fd (self->cancel); g_object_unref (self->cancel); self->cancel = NULL; g_object_unref (self->servaddr); self->servaddr = NULL; g_object_unref (self->socket); self->socket = NULL; GST_INFO_OBJECT (self, "stopped"); }
static gssize g_unix_output_stream_write (GOutputStream *stream, const void *buffer, gsize count, GCancellable *cancellable, GError **error) { GUnixOutputStream *unix_stream; gssize res; GPollFD poll_fds[2]; int poll_ret; unix_stream = G_UNIX_OUTPUT_STREAM (stream); if (g_cancellable_make_pollfd (cancellable, &poll_fds[1])) { poll_fds[0].fd = unix_stream->priv->fd; poll_fds[0].events = G_IO_OUT; do poll_ret = g_poll (poll_fds, 2, -1); while (poll_ret == -1 && errno == EINTR); g_cancellable_release_fd (cancellable); if (poll_ret == -1) { int errsv = errno; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Error writing to unix: %s"), g_strerror (errsv)); return -1; } } while (1) { if (g_cancellable_set_error_if_cancelled (cancellable, error)) return -1; res = write (unix_stream->priv->fd, buffer, count); if (res == -1) { int errsv = errno; if (errsv == EINTR) continue; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Error writing to unix: %s"), g_strerror (errsv)); } break; } return res; }
static void gst_udpsrc_free_cancellable (GstUDPSrc * src) { if (src->made_cancel_fd) { g_cancellable_release_fd (src->cancellable); src->made_cancel_fd = FALSE; } g_object_unref (src->cancellable); src->cancellable = NULL; }
static void soup_output_stream_done_io (GOutputStream *stream) { SoupOutputStreamPrivate *priv = SOUP_OUTPUT_STREAM_GET_PRIVATE (stream); if (priv->cancel_watch) { g_source_destroy (priv->cancel_watch); priv->cancel_watch = NULL; g_cancellable_release_fd (priv->cancellable); } priv->cancellable = NULL; }
gboolean wing_overlap_wait_result (HANDLE hfile, OVERLAPPED *overlap, DWORD *transferred, GCancellable *cancellable) { GPollFD pollfd[2]; gboolean result = FALSE; gint num, npoll; #if GLIB_SIZEOF_VOID_P == 8 pollfd[0].fd = (gint64)overlap->hEvent; #else pollfd[0].fd = (gint)overlap->hEvent; #endif pollfd[0].events = G_IO_IN; num = 1; if (g_cancellable_make_pollfd (cancellable, &pollfd[1])) num++; loop: npoll = g_poll (pollfd, num, -1); if (npoll <= 0) /* error out, should never happen */ goto end; 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); } result = GetOverlappedResult (overlap->hEvent, overlap, transferred, FALSE); if (result == FALSE && GetLastError () == ERROR_IO_INCOMPLETE && !g_cancellable_is_cancelled (cancellable)) goto loop; end: if (num > 1) g_cancellable_release_fd (cancellable); return result; }
static void soup_input_stream_done_io (GInputStream *stream) { SoupInputStreamPrivate *priv = SOUP_INPUT_STREAM_GET_PRIVATE (stream); if (priv->cancel_watch) { g_source_destroy (priv->cancel_watch); priv->cancel_watch = NULL; g_cancellable_release_fd (priv->cancellable); } priv->cancellable = NULL; priv->caller_buffer = NULL; priv->caller_bufsize = 0; }
/* * g_socket_condition_timed_wait: * * Provides g_socket_condition_timed_wait function for older * glib versions. It's a simplified version of the glib one * that should work with all glib version from glib-2.22. */ gboolean g_socket_condition_timed_wait(GSocket *socket,GIOCondition condition,gint64 timeout,GCancellable *cancellable,GError **error) { gint64 start_time; GPollFD poll_fd[2]; gint result; gint num; g_return_val_if_fail(G_IS_SOCKET(socket),FALSE); if(g_cancellable_set_error_if_cancelled(cancellable,error)) return FALSE; if(timeout != -1) timeout /= 1000; start_time = g_get_monotonic_time(); poll_fd[0].fd = g_socket_get_fd(socket); poll_fd[0].events = condition; num = 1; if(g_cancellable_make_pollfd(cancellable,&poll_fd[1])) num++; while(TRUE){ result = g_poll(poll_fd,num,timeout); if(result != -1 || errno != EINTR) break; if(timeout != -1){ timeout -= (g_get_monotonic_time () - start_time) * 1000; if(timeout < 0) timeout = 0; } } if(num > 1) g_cancellable_release_fd(cancellable); if(result == 0){ g_set_error_literal(error,G_IO_ERROR,G_IO_ERROR_TIMED_OUT, "Socket I/O timed out"); return FALSE; } return !g_cancellable_set_error_if_cancelled(cancellable,error); }
static gssize g_unix_input_stream_read (GInputStream *stream, void *buffer, gsize count, GCancellable *cancellable, GError **error) { GUnixInputStream *unix_stream; gssize res = -1; GPollFD poll_fds[2]; int nfds; int poll_ret; unix_stream = G_UNIX_INPUT_STREAM (stream); poll_fds[0].fd = unix_stream->priv->fd; poll_fds[0].events = G_IO_IN; if (unix_stream->priv->is_pipe_or_socket && g_cancellable_make_pollfd (cancellable, &poll_fds[1])) nfds = 2; else nfds = 1; while (1) { poll_fds[0].revents = poll_fds[1].revents = 0; do poll_ret = g_poll (poll_fds, nfds, -1); while (poll_ret == -1 && errno == EINTR); if (poll_ret == -1) { int errsv = errno; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Error reading from file descriptor: %s"), g_strerror (errsv)); break; } if (g_cancellable_set_error_if_cancelled (cancellable, error)) break; if (!poll_fds[0].revents) continue; res = read (unix_stream->priv->fd, buffer, count); if (res == -1) { int errsv = errno; if (errsv == EINTR || errsv == EAGAIN) continue; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Error reading from file descriptor: %s"), g_strerror (errsv)); } break; } if (nfds == 2) g_cancellable_release_fd (cancellable); return res; }
static gboolean claim_op (GTlsConnectionBase *tls, GTlsConnectionBaseOp op, gboolean blocking, GCancellable *cancellable, GError **error) { try_again: if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; g_mutex_lock (&tls->op_mutex); if (((op == G_TLS_CONNECTION_BASE_OP_HANDSHAKE || op == G_TLS_CONNECTION_BASE_OP_READ) && (tls->read_closing || tls->read_closed)) || ((op == G_TLS_CONNECTION_BASE_OP_HANDSHAKE || op == G_TLS_CONNECTION_BASE_OP_WRITE) && (tls->write_closing || tls->write_closed))) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED, _("Connection is closed")); g_mutex_unlock (&tls->op_mutex); return FALSE; } if (tls->handshake_error && op != G_TLS_CONNECTION_BASE_OP_CLOSE_BOTH && op != G_TLS_CONNECTION_BASE_OP_CLOSE_READ && op != G_TLS_CONNECTION_BASE_OP_CLOSE_WRITE) { if (error) *error = g_error_copy (tls->handshake_error); g_mutex_unlock (&tls->op_mutex); return FALSE; } if (op != G_TLS_CONNECTION_BASE_OP_HANDSHAKE) { if (op != G_TLS_CONNECTION_BASE_OP_CLOSE_BOTH && op != G_TLS_CONNECTION_BASE_OP_CLOSE_READ && op != G_TLS_CONNECTION_BASE_OP_CLOSE_WRITE && tls->need_handshake && !tls->handshaking) { tls->handshaking = TRUE; if (!do_implicit_handshake (tls, blocking, cancellable, error)) { g_cancellable_reset (tls->waiting_for_op); g_mutex_unlock (&tls->op_mutex); return FALSE; } } if (tls->need_finish_handshake && tls->implicit_handshake) { GError *my_error = NULL; gboolean success; tls->need_finish_handshake = FALSE; g_mutex_unlock (&tls->op_mutex); success = finish_handshake (tls, tls->implicit_handshake, &my_error); g_clear_object (&tls->implicit_handshake); g_mutex_lock (&tls->op_mutex); if (op != G_TLS_CONNECTION_BASE_OP_CLOSE_BOTH && op != G_TLS_CONNECTION_BASE_OP_CLOSE_READ && op != G_TLS_CONNECTION_BASE_OP_CLOSE_WRITE && (!success || g_cancellable_set_error_if_cancelled (cancellable, &my_error))) { g_propagate_error (error, my_error); g_mutex_unlock (&tls->op_mutex); return FALSE; } g_clear_error (&my_error); } } if ((op != G_TLS_CONNECTION_BASE_OP_WRITE && tls->reading) || (op != G_TLS_CONNECTION_BASE_OP_READ && tls->writing) || (op != G_TLS_CONNECTION_BASE_OP_HANDSHAKE && tls->handshaking)) { GPollFD fds[2]; int nfds; g_cancellable_reset (tls->waiting_for_op); g_mutex_unlock (&tls->op_mutex); if (!blocking) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK, _("Operation would block")); return FALSE; } g_cancellable_make_pollfd (tls->waiting_for_op, &fds[0]); if (g_cancellable_make_pollfd (cancellable, &fds[1])) nfds = 2; else nfds = 1; g_poll (fds, nfds, -1); if (nfds > 1) g_cancellable_release_fd (cancellable); goto try_again; } if (op == G_TLS_CONNECTION_BASE_OP_HANDSHAKE) tls->handshaking = TRUE; if (op == G_TLS_CONNECTION_BASE_OP_CLOSE_BOTH || op == G_TLS_CONNECTION_BASE_OP_CLOSE_READ) tls->read_closing = TRUE; if (op == G_TLS_CONNECTION_BASE_OP_CLOSE_BOTH || op == G_TLS_CONNECTION_BASE_OP_CLOSE_WRITE) tls->write_closing = TRUE; if (op != G_TLS_CONNECTION_BASE_OP_WRITE) tls->reading = TRUE; if (op != G_TLS_CONNECTION_BASE_OP_READ) tls->writing = TRUE; g_mutex_unlock (&tls->op_mutex); return TRUE; }
void InterfaceManagerImpl::updateDevices() { unique_lock(mMutex); GVariant* deviceList = nullptr; GError* error = nullptr; GCancellable* c = nullptr; try { if(mNetManagerProxy == nullptr){ throw std::runtime_error("Network Manager proxy not initialized"); } deviceList = g_dbus_proxy_call_sync(mNetManagerProxy, NM_METHOD_GET_DEVICES, NULL, G_DBUS_CALL_FLAGS_NONE, 1000, //timout of operation c, &error); if (deviceList == NULL && error != NULL){ throw std::runtime_error(error->message); } /**< iteration through the list */ GVariantIter deviceIter1, deviceIter2; GVariant *deviceNode1, *deviceNode2; g_variant_iter_init(&deviceIter1, deviceList); while ((deviceNode1 = g_variant_iter_next_value(&deviceIter1))) { g_variant_iter_init(&deviceIter2, deviceNode1); while ((deviceNode2 = g_variant_iter_next_value(&deviceIter2))) { gsize strlength = 256; const gchar* devicePath = g_variant_get_string(deviceNode2, &strlength); InterfaceInfo info = getDeviceInfo(devicePath); mInterfaces.insert(InterfaceInfoPair(devicePath, info)); } } } catch(const std::exception& e) { if(deviceList != nullptr){ g_variant_unref(deviceList); } if(error != nullptr){ g_error_free(error); } if(c != nullptr){ g_cancellable_release_fd(c); } std::cout<<e.what()<<std::endl; updateFailedSignal(); } }
static gboolean g_unix_output_stream_writev (GOutputStream *stream, const GOutputVector *vectors, gsize n_vectors, gsize *bytes_written, GCancellable *cancellable, GError **error) { GUnixOutputStream *unix_stream; gssize res = -1; GPollFD poll_fds[2]; int nfds = 0; int poll_ret; struct iovec *iov; if (bytes_written) *bytes_written = 0; /* Clamp to G_MAXINT as writev() takes an integer for the number of vectors. * We handle this like a short write in this case */ if (n_vectors > G_MAXINT) n_vectors = G_MAXINT; unix_stream = G_UNIX_OUTPUT_STREAM (stream); if (G_OUTPUT_VECTOR_IS_IOVEC) { /* ABI is compatible */ iov = (struct iovec *) vectors; } else { gsize i; /* ABI is incompatible */ iov = g_newa (struct iovec, n_vectors); for (i = 0; i < n_vectors; i++) { iov[i].iov_base = (void *)vectors[i].buffer; iov[i].iov_len = vectors[i].size; } } poll_fds[0].fd = unix_stream->priv->fd; poll_fds[0].events = G_IO_OUT; nfds++; if (unix_stream->priv->is_pipe_or_socket && g_cancellable_make_pollfd (cancellable, &poll_fds[1])) nfds++; while (1) { int errsv; poll_fds[0].revents = poll_fds[1].revents = 0; do { poll_ret = g_poll (poll_fds, nfds, -1); errsv = errno; } while (poll_ret == -1 && errsv == EINTR); if (poll_ret == -1) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Error writing to file descriptor: %s"), g_strerror (errsv)); break; } if (g_cancellable_set_error_if_cancelled (cancellable, error)) break; if (!poll_fds[0].revents) continue; res = writev (unix_stream->priv->fd, iov, n_vectors); errsv = errno; if (res == -1) { if (errsv == EINTR || errsv == EAGAIN) continue; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Error writing to file descriptor: %s"), g_strerror (errsv)); } if (bytes_written) *bytes_written = res; break; } if (nfds == 2) g_cancellable_release_fd (cancellable); return res != -1; }