static void gdkevent_handle_focus (GdkEvent *event, GDBusConnection *channel) { #if 0 gchar buffer[128]; g_snprintf(buffer, sizeof(buffer), "%d|%p|%u\n", event->any.type, event->focus_change.window, event->focus_change.in); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); #endif }
void HttpClient::write_str(const char *str, GError **err) { int len = strlen(str); int left_byte = len; GIOStatus res; gsize bytes_written; while (left_byte) { res = g_io_channel_write_chars(channel_, str+(len - left_byte), left_byte, &bytes_written, err); if (res == G_IO_STATUS_ERROR) { return; } left_byte -= bytes_written; } res = g_io_channel_flush(channel_, err); }
static void dnotify_signal_handler(int sig, siginfo_t * si, void *sig_data) { if (changes->length > MAX_QUEUE_SIZE) { GAM_DEBUG(DEBUG_INFO, "Queue Full\n"); return; } g_queue_push_head(changes, GINT_TO_POINTER(si->si_fd)); g_io_channel_write_chars(pipe_write_ioc, "bogus", 5, NULL, NULL); g_io_channel_flush(pipe_write_ioc, NULL); GAM_DEBUG(DEBUG_INFO, "signal handler done\n"); }
static void gdkevent_handle_configure (GdkEvent *event, GIOChannel *channel) { gchar buffer[128]; g_snprintf(buffer, sizeof(buffer), "%d|%p|%d|%d|%d|%d\n", event->any.type, event->configure.window, event->configure.x, event->configure.y, event->configure.width, event->configure.height); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); }
static void gdkevent_handle_expose (GdkEvent *event, GIOChannel *channel) { gchar buffer[128]; g_snprintf(buffer, sizeof(buffer), "%d|%p|%d|%d|%d|%d\n", GDK_EXPOSE, event->expose.window, event->expose.area.x, event->expose.area.y, event->expose.area.width, event->expose.area.height); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); }
static void gdkevent_handle_button (GdkEvent *event, GIOChannel *channel) { gchar buffer[128]; g_snprintf(buffer, sizeof(buffer), "%d|%p|%u|%0.1f|%0.1f|%u\n", event->any.type, event->button.window, event->button.button, event->button.x, event->button.y, event->button.state); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); }
static void on_MOTOR_BENCH_STATIC(IvyClientPtr app, void *user_data, int argc, char *argv[]){ mb_state.av_rpm = atof(argv[0]); mb_state.av_thrust = atof(argv[1]); mb_state.av_amps = atof(argv[2]); mb_state.av_throttle = atof(argv[3]); if (mb_state.log_channel_static) { GString* str = g_string_sized_new(256); g_string_printf(str, "%0f %.3f %.2f %.1f\n", mb_state.av_throttle, mb_state.av_rpm, mb_state.av_amps, mb_state.av_thrust); gsize b_writen; GError* my_err = NULL; GIOStatus stat = g_io_channel_write_chars(mb_state.log_channel_static,str->str, str->len, &b_writen, &my_err); g_string_free(str, TRUE); } g_message("in_static %f %f %f %f", mb_state.av_throttle, mb_state.av_rpm, mb_state.av_amps, mb_state.av_thrust); }
void warlock_log (const char *str) { if (log_file != NULL) { GError *err; gsize size; err = NULL; (void)g_io_channel_write_chars (log_file, str, -1, &size, &err); print_error (err); err = NULL; (void)g_io_channel_flush (log_file, &err); print_error (err); } }
/** * paxos_peer_write - Write data reliably to a peer. */ int paxos_peer_write(GIOChannel *channel, GIOCondition condition, void *data) { struct paxos_peer *peer = (struct paxos_peer *)data; size_t bytes_written; GIOStatus status; GError *error = NULL; // If there's nothing to write, do nothing. if (peer->pp_write_buffer->len == 0) { return TRUE; } // Write to the channel. status = g_io_channel_write_chars(channel, peer->pp_write_buffer->str, peer->pp_write_buffer->len, &bytes_written, &error); if (status == G_IO_STATUS_ERROR) { g_warning("paxos_peer_write: Write to socket failed."); } g_string_erase(peer->pp_write_buffer, 0, bytes_written); if (peer->pp_write_buffer->len == 0) { // XXX: this is kind of hax while (g_source_remove_by_user_data(peer)); g_io_add_watch(peer->pp_channel, G_IO_IN, paxos_peer_read, peer); } // Flush the channel. error = NULL; if (g_io_channel_flush(peer->pp_channel, &error) == G_IO_STATUS_ERROR) { g_critical("paxos_peer_write: Could not flush channel."); } if (status == G_IO_STATUS_EOF) { // Flush the read buffer. We will also detect the EOF in paxos_peer_read, // which will destroy the peer for us. if (g_io_channel_get_buffer_condition(channel) & G_IO_IN) { paxos_peer_read(channel, G_IO_IN, data); } return FALSE; } return TRUE; }
static void gdkevent_handle_motion_notfiy (GdkEvent *event, GDBusConnection *channel) { #if 0 gchar buffer[128]; g_snprintf(buffer, sizeof(buffer), "%d|%p|%0.1f|%0.1f|%u\n", GDK_MOTION_NOTIFY, event->motion.window, event->motion.x, event->motion.y, event->motion.state); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); #endif }
static void _verve_history_cache_write (void) { if (verve_history_is_empty ()) return; const gchar *basename = _verve_history_cache_get_filename (); gchar *filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, basename, TRUE); if (G_UNLIKELY (filename == NULL)) return; GError *error = NULL; GIOChannel *handle = g_io_channel_new_file (filename, "w+", &error); if (error) g_error_free (error); if (G_LIKELY (handle != NULL)) { GList *current = verve_history_begin(); GIOStatus status; gsize bytes; int i; for (i=0; i<25, current != NULL; i++) /* Cache the last 25 commands */ { g_io_channel_write_chars (handle, g_strconcat ("", current->data, "\n", NULL), -1, &bytes, &error); if (error) break; current = verve_history_get_next (current); } g_io_channel_shutdown (handle, TRUE, &error); if (error) g_error_free (error); g_io_channel_unref (handle); } g_free (filename); }
static void gdkrecord_event_log (gpointer event, gdouble begin, gdouble end, const gchar *info) { gchar *buffer; buffer = g_strdup_printf ("%f|%f|%f|%d|%d|%s", begin, end, server_time_for_event (event), ((GdkEvent*)event)->type, (gint)strlen (info), info); g_io_channel_write_chars (channel, buffer, strlen (buffer), NULL, NULL); g_io_channel_flush (channel, NULL); g_free (buffer); }
/* Thread function */ static void thread_func(void *data) { struct databag *mydata = data; uint8_t buf[BUFSIZE]; uint64_t nb_to_send = 0; int bytes_written; double time_cur, time_last, time_diff; time_last = g_timer_elapsed(mydata->timer, NULL); while (thread_running) { /* Rate control */ time_cur = g_timer_elapsed(mydata->timer, NULL); time_diff = time_cur - time_last; time_last = time_cur; nb_to_send = cur_samplerate * time_diff; if (limit_samples) { nb_to_send = MIN(nb_to_send, limit_samples - mydata->samples_counter); } /* Make sure we don't overflow. */ nb_to_send = MIN(nb_to_send, BUFSIZE); if (nb_to_send) { samples_generator(buf, nb_to_send, data); mydata->samples_counter += nb_to_send; g_io_channel_write_chars(channels[1], (gchar *)&buf, nb_to_send, (gsize *)&bytes_written, NULL); } /* Check if we're done. */ if ((limit_msec && time_cur * 1000 > limit_msec) || (limit_samples && mydata->samples_counter >= limit_samples)) { close(mydata->pipe_fds[1]); thread_running = 0; } g_usleep(10); } }
static gboolean theora_enc_write_multipass_cache (GstTheoraEnc * enc, gboolean begin, gboolean eos) { GError *err = NULL; GIOStatus stat = G_IO_STATUS_NORMAL; gint bytes_read = 0; gsize bytes_written = 0; gchar *buf; if (begin) stat = g_io_channel_seek_position (enc->multipass_cache_fd, 0, G_SEEK_SET, &err); if (stat != G_IO_STATUS_ERROR) { do { bytes_read = th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_OUT, &buf, sizeof (buf)); if (bytes_read > 0) g_io_channel_write_chars (enc->multipass_cache_fd, buf, bytes_read, &bytes_written, NULL); } while (bytes_read > 0 && bytes_written > 0); } if (stat == G_IO_STATUS_ERROR || bytes_read < 0) { if (begin) { if (eos) GST_ELEMENT_WARNING (enc, RESOURCE, WRITE, (NULL), ("Failed to seek to beginning of multipass cache file: %s", err->message)); else GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL), ("Failed to seek to beginning of multipass cache file: %s", err->message)); } else { GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL), ("Failed to write multipass cache file")); } if (err) g_error_free (err); return FALSE; } return TRUE; }
/** * midgard_blob_write_content: * @self: #MidgardBlob self instance. * @content: content which should be written to file. * * Write given @content to a file. * * Returns: %TRUE if content has been written to file, %FALSE otherwise. */ gboolean midgard_blob_write_content(MidgardBlob *self, const gchar *content) { g_assert(self != NULL); g_assert(content != NULL); MidgardConnection *mgd = self->priv->mgd; MIDGARD_ERRNO_SET(mgd, MGD_ERR_OK); __get_filepath(self); if(!self->priv->filepath) { midgard_set_error(self->priv->mgd, MGD_GENERIC_ERROR, MGD_ERR_USER_DATA, "Invalid attachment. " "Can not read file from empty location"); return FALSE; } __get_channel(self, "w"); if(!self->priv->channel) return FALSE; GIOChannel *channel = self->priv->channel; GIOStatus status; GError *err = NULL; status = g_io_channel_write_chars(channel, content, strlen(content), NULL, &err); g_io_channel_flush(channel, NULL); if(status != G_IO_STATUS_NORMAL) { midgard_set_error(self->priv->mgd, MGD_GENERIC_ERROR, MGD_ERR_INTERNAL, " %s ", err->message); g_clear_error(&err); return FALSE; } return TRUE; }
gsize g_ril_io_write(GRilIO *io, const gchar *data, gsize count) { GIOStatus status; gsize bytes_written; status = g_io_channel_write_chars(io->channel, data, count, &bytes_written, NULL); if (status != G_IO_STATUS_NORMAL) { g_source_remove(io->read_watch); return 0; } g_ril_util_debug_hexdump(FALSE, (const unsigned char *)data, bytes_written, io->debugf, io->debug_data); return bytes_written; }
static gboolean gssapi_fail(struct pending_client *pc) { char header[2]; GIOStatus status; gsize read; header[0] = 1; /* SOCKS_GSSAPI_VERSION */ header[1] = 0xff; /* Message abort */ status = g_io_channel_write_chars(pc->connection, header, 2, &read, NULL); if (status != G_IO_STATUS_NORMAL) { return FALSE; } g_io_channel_flush(pc->connection, NULL); return FALSE; }
void main_window_pass_command_line_files(char **argv) { guint i; GError *error; gsize bytes_written; error = NULL; inter_gphpedit_io = g_io_channel_new_file("/tmp/gphpedit.sock","w",&error); if (argv) { i = 1; while (argv[i] != NULL) { //g_print("%s:%d\n", argv[i], strlen(argv[i])); g_io_channel_write_chars(inter_gphpedit_io, argv[i], strlen(argv[i]), &bytes_written, &error); ++i; } } }
static gchar* make_silence(void) { const gchar silentwave[] = {0x52, 0x49, 0x46, 0x46, 0x24, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x80, 0xBB, 0x00, 0x00, 0x00, 0xEE, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00}; GError *error = NULL; gchar *tmpfilename; GIOChannel *outfile; gsize bytes_written; g_clear_error (&error); gint fd = g_file_open_tmp (NULL, &tmpfilename, &error); if (-1 == fd) { g_print ("Unable to create tmp file: %s\n", error->message); g_error_free (error); return dummyuri(); } outfile = g_io_channel_unix_new (fd); /* make it a binary channel */ if (G_IO_STATUS_NORMAL != g_io_channel_set_encoding (outfile, NULL, NULL)) { g_print ("Unable to create tmpfile in binary mode\n"); return dummyuri(); } g_print ("File is %lu\n", sizeof(*silentwave)); g_clear_error (&error); if (G_IO_STATUS_NORMAL != g_io_channel_write_chars (outfile, &silentwave[0], sizeof(silentwave), &bytes_written, &error)) { g_print ("Unable to write to tmpfile: %s\n", error->message); g_error_free (error); return dummyuri(); } g_io_channel_shutdown (outfile, TRUE, NULL); g_io_channel_unref (outfile); close(fd); return g_filename_to_uri (tmpfilename, NULL, NULL); }
int test_prepare_dummy_file(const gchar *dirname, const gchar *filename, gsize size, const gchar *source) { GIOChannel *input, *output; GIOStatus status; gchar *path; input = g_io_channel_new_file(source, "r", NULL); g_assert_nonnull(input); status = g_io_channel_set_encoding(input, NULL, NULL); g_assert(status == G_IO_STATUS_NORMAL); path = g_build_filename(dirname, filename, NULL); g_assert_nonnull(path); output = g_io_channel_new_file(path, "w+", NULL); g_assert_nonnull(output); status = g_io_channel_set_encoding(output, NULL, NULL); g_assert(status == G_IO_STATUS_NORMAL); g_free(path); while (size) { gchar buf[4096]; gsize bytes_to_read = size < sizeof(buf) ? size : sizeof(buf); gsize bytes_read, bytes_written; GError *error = NULL; status = g_io_channel_read_chars(input, buf, bytes_to_read, &bytes_read, &error); g_assert_no_error(error); g_assert(status == G_IO_STATUS_NORMAL); status = g_io_channel_write_chars(output, buf, bytes_read, &bytes_written, &error); g_assert_no_error(error); g_assert(status == G_IO_STATUS_NORMAL); g_assert(bytes_read == bytes_written); size -= bytes_read; } g_io_channel_unref(input); g_io_channel_unref(output); return 0; }
void smartcard_cb (GObject *gobj, GAsyncResult *res, gpointer userdata) { DBG("smartcard callback"); GError *error; GVariant *result; error = NULL; result = g_dbus_proxy_call_finish (dbProxy, res, &error); const gchar * smartcard_response = g_variant_get_bytestring(result); DBG("received response %s", smartcard_response); //TODO: write back to the hw_channel struct ofono_modem *modem = userdata; struct telit_data *data = ofono_modem_get_data(modem); gsize bytes_written; g_io_channel_write_chars(data->bt_io, smartcard_response, strlen(smartcard_response), &bytes_written, NULL); }
void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet, gsize plen) { GIOStatus status; gsize bytes_written; guint16 len; if (plen < 4) return; /* find the length of the packet to transmit */ len = get_host_short(&packet[2]); status = g_io_channel_write_chars(net->channel, (gchar *) packet, MIN(len, plen), &bytes_written, NULL); if (status != G_IO_STATUS_NORMAL) return; }
/* Write the first element of queue through channel */ static void io_queue_pop (GQueue *queue, GIOChannel *channel) { gchar *buf; gsize bytes_written; GError *error = NULL; buf = g_queue_pop_head (queue); if (buf != NULL) { if (g_io_channel_write_chars (channel, buf, -1, &bytes_written, &error) != G_IO_STATUS_NORMAL) { g_warning ("Could not write queue element \"%s\" to channel: %s", buf, error->message); g_error_free (error); } g_free (buf); } }
/* Transmit data, return number of bytes sent, -1 = error */ int net_transmit(GIOChannel *handle, const char *data, int len) { gsize ret; GIOStatus status; GError *err = NULL; g_return_val_if_fail(handle != NULL, -1); g_return_val_if_fail(data != NULL, -1); status = g_io_channel_write_chars(handle, (char *) data, len, &ret, &err); if (err != NULL) { g_warning("%s", err->message); g_error_free(err); } if (status == G_IO_STATUS_ERROR) return -1; return ret; }
static GIOStatus write_to_io_channel (GIOChannel * io, const gchar * buf, gsize len) { GIOStatus status; gsize tot_written = 0; do { gsize written = 0; status = g_io_channel_write_chars (io, buf, len, &written, NULL); if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF) return status; tot_written += written; buf += written; } while (tot_written < len && status == G_IO_STATUS_AGAIN); return G_IO_STATUS_NORMAL; }
int _gpgme_io_write (int fd, const void *buffer, size_t count) { int saved_errno = 0; gsize nwritten; GIOChannel *chan; GIOStatus status; GError *err = NULL; TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_write", fd, "buffer=%p, count=%u", buffer, count); TRACE_LOGBUF (buffer, count); chan = find_channel (fd); if (!chan) { TRACE_LOG ("fd %d: no channel registered"); errno = EINVAL; return -1; } status = g_io_channel_write_chars (chan, (gchar *) buffer, count, &nwritten, &err); if (err) { TRACE_LOG1 ("write error: %s", err->message); g_error_free (err); } if (status == G_IO_STATUS_AGAIN) { nwritten = -1; saved_errno = EAGAIN; } else if (status != G_IO_STATUS_NORMAL) { nwritten = -1; saved_errno = EIO; } errno = saved_errno; return TRACE_SYSRES (nwritten); }
void DICT::Cmd::send(GIOChannel *channel, GError *&err) { g_assert(channel); GIOStatus res = g_io_channel_write_chars(channel, query().c_str(), -1, NULL, &err); if (res != G_IO_STATUS_NORMAL) return; /* force flushing of the write buffer */ res = g_io_channel_flush(channel, &err); if (res != G_IO_STATUS_NORMAL) return; state_ = DICT::Cmd::DATA; }
static void client_write_direct(struct client *client, const char *data, size_t length) { GError *error = NULL; GIOStatus status; gsize bytes_written; assert(client != NULL); assert(client->channel != NULL); assert(data != NULL); assert(length > 0); assert(g_queue_is_empty(client->deferred_send)); status = g_io_channel_write_chars(client->channel, data, length, &bytes_written, &error); switch (status) { case G_IO_STATUS_NORMAL: case G_IO_STATUS_AGAIN: break; case G_IO_STATUS_EOF: /* client has disconnected */ client_set_expired(client); return; case G_IO_STATUS_ERROR: /* I/O error */ client_set_expired(client); g_warning("failed to write to %i: %s", client->num, error->message); g_error_free(error); return; } if (bytes_written < length) client_defer_output(client, data + bytes_written, length - bytes_written); if (!g_queue_is_empty(client->deferred_send)) g_debug("[%u] buffer created", client->num); }
static gboolean write_to_char_dev(const gchar *cdev, GError **error, const gchar *format, ...) { GIOChannel *channel = g_io_channel_new_file(cdev, "w", error); GIOStatus rc; gchar *data = NULL; gsize data_len, bytes_written; va_list args; if (!channel) { g_prefix_error(error, "While opening %s: ", cdev); goto error; } va_start(args, format); data = g_strdup_vprintf(format, args); va_end(args); data_len = strlen(data); rc = g_io_channel_write_chars(channel, data, data_len, &bytes_written, error); if (rc != G_IO_STATUS_NORMAL) { g_prefix_error(error, "While writing to %s: ", cdev); goto error; } g_io_channel_unref(channel); g_free(data); return TRUE; error: if (channel) g_io_channel_unref(channel); g_free(data); return FALSE; }
static gboolean write_stream(GObex *obex, GError **err) { GIOStatus status; gsize bytes_written; gchar *buf; buf = (gchar *) &obex->tx_buf[obex->tx_sent]; status = g_io_channel_write_chars(obex->io, buf, obex->tx_data, &bytes_written, err); if (status != G_IO_STATUS_NORMAL) return FALSE; g_obex_dump(G_OBEX_DEBUG_DATA, "<", buf, bytes_written); obex->tx_sent += bytes_written; obex->tx_data -= bytes_written; return TRUE; }