void gtk_pipe_string_write(char *str) { #if GTK_MAJOR_VERSION == 2 int len, slen; #ifdef DEBUGPIPE int code=STRING_CODE; //fprintf(stderr, "Writing debug int %d\n", code); len = write(fpip_out,&code,sizeof(code)); if (len!=sizeof(code)) pipe_error("PIPE_STRING_WRITE"); #endif slen=strlen(str); //fprintf(stderr, "Writing int %d\n", slen); len = write(fpip_out,&slen,sizeof(slen)); if (len!=sizeof(slen)) pipe_error("PIPE_STRING_WRITE"); //fprintf(stderr, "Writing str %s\n", str); len = write(fpip_out,str,slen); if (len!=slen) pipe_error("PIPE_STRING_WRITE on string part"); #else // GTK 3 gsize len; int slen; GError *error = NULL; #ifdef DEBUGPIPE int code=STRING_CODE; //fprintf(stderr, "Writing gtk debug int %d\n", code); g_io_channel_write_chars(channel_out,(gchar *)&code, sizeof(code), &len, &error); if (len!=sizeof(code)) pipe_error("CHANNEL_STRING_WRITE"); g_io_channel_flush(channel_out, &error); #endif slen=strlen(str); //fprintf(stderr, "Writing gtk strlen int %d of size %ld\n", slen, sizeof(slen)); g_io_channel_write_chars(channel_out, (gchar *)&slen, sizeof(slen), &len, &error); if (len != sizeof(slen)) pipe_error("CHANNEL_STRING_WRITE"); g_io_channel_flush(channel_out, &error); //fprintf(stderr, "Writing gtk str %s\n", str); g_io_channel_write_chars(channel_out, str, slen, &len, &error); if (len!=slen) pipe_error("CHANNEL_STRING_WRITE on string part"); g_io_channel_flush(channel_out, &error); #endif }
static gboolean maki_dcc_send_in_read (GIOChannel* source, GIOCondition condition, gpointer data) { gchar buffer[1024]; gsize bytes_read; GIOStatus status; makiDCCSend* dcc = data; if (condition & (G_IO_HUP | G_IO_ERR)) { goto error; } while ((status = g_io_channel_read_chars(source, buffer, 1024, &bytes_read, NULL)) == G_IO_STATUS_NORMAL) { guint32 pos; dcc->position += bytes_read; pos = htonl(dcc->position); i_io_channel_write_chars(dcc->channel.file, buffer, bytes_read, NULL, NULL); g_io_channel_flush(dcc->channel.file, NULL); i_io_channel_write_chars(source, (gchar*)&pos, sizeof(pos), NULL, NULL); g_io_channel_flush(source, NULL); if (dcc->size > 0 && dcc->position >= dcc->size) { goto finish; } } if (status == G_IO_STATUS_ERROR) { goto error; } return TRUE; error: dcc->status |= s_error; finish: dcc->status &= ~s_running; maki_dcc_send_close(dcc); dcc->d.in.sources[s_in_read] = 0; maki_dcc_send_emit(dcc); return FALSE; }
static void FileLoggerLog(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer data) { FileLogger *logger = data; gsize written; g_static_mutex_lock(&logger->lock); if (logger->error) { goto exit; } if (logger->file == NULL) { if (logger->file == NULL) { logger->file = FileLoggerOpen(data); } if (logger->file == NULL) { logger->error = TRUE; goto exit; } } if (!FileLoggerIsValid(logger)) { logger->error = TRUE; goto exit; } /* Write the log file and do log rotation accounting. */ if (g_io_channel_write_chars(logger->file, message, -1, &written, NULL) == G_IO_STATUS_NORMAL) { if (logger->maxSize > 0) { logger->logSize += (gint) written; if (logger->logSize >= logger->maxSize) { g_io_channel_unref(logger->file); logger->append = FALSE; logger->file = FileLoggerOpen(logger); } else { g_io_channel_flush(logger->file, NULL); } } else { g_io_channel_flush(logger->file, NULL); } } exit: g_static_mutex_unlock(&logger->lock); }
static void log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user) { gsize n_written; GError *error = NULL; GIOChannel *channel = user; #if GLIB_CHECK_VERSION(2, 26, 0) GTimeZone *tz; GDateTime *date_time; gchar *new_message; tz = g_time_zone_new_local (); date_time = g_date_time_new_now (tz); new_message = g_strdup_printf ("[%s] %s\n", g_date_time_format (date_time, "%FT%H:%M:%S%z"), message); g_time_zone_unref (tz); g_date_time_unref (date_time); g_io_channel_write_chars (channel, new_message, strlen (new_message), &n_written, &error); g_assert_no_error (error); g_free (new_message); #else g_io_channel_write_chars (channel, message, strlen (message), &n_written, &error); g_assert_no_error (error); #endif g_io_channel_flush (channel, &error); g_assert_no_error (error); }
static gboolean write_child_stdin (GIOChannel *channel, GIOCondition condition, gpointer user_data) { UlSpawnedJob *self = UL_SPAWNED_JOB (user_data); gsize bytes_written; if (self->input_string_cursor == NULL || *self->input_string_cursor == '\0') { /* nothing left to write; close our end so the child will get EOF */ g_io_channel_unref (self->child_stdin_channel); g_source_destroy (self->child_stdin_source); g_warn_if_fail (close (self->child_stdin_fd) == 0); self->child_stdin_channel = NULL; self->child_stdin_source = NULL; self->child_stdin_fd = -1; return FALSE; } g_io_channel_write_chars (channel, self->input_string_cursor, strlen (self->input_string_cursor), &bytes_written, NULL); g_io_channel_flush (channel, NULL); self->input_string_cursor += bytes_written; /* keep writing */ return TRUE; }
gboolean listener_socks_reply(struct pending_client *pc, guint8 err, guint8 atyp, guint8 data_len, gchar *data, guint16 port) { gchar *header = g_new0(gchar, 7 + data_len); GIOStatus status; gsize read; header[0] = SOCKS_VERSION; header[1] = err; header[2] = 0x0; /* Reserved */ header[3] = atyp; memcpy(header+4, data, data_len); *((guint16 *)(header+4+data_len)) = htons(port); status = g_io_channel_write_chars(pc->connection, header, 6 + data_len, &read, NULL); g_free(header); if (status != G_IO_STATUS_NORMAL) { return FALSE; } g_io_channel_flush(pc->connection, NULL); return (err == REP_OK); }
void write_buffer_to_channel (GIOChannel *chan, gchar *buf, gint bufsize) { guint total_sent_bytes = 0; gsize sent_bytes; GIOStatus io_stat; GError *err = NULL; do { io_stat = g_io_channel_write_chars (chan, buf + total_sent_bytes, bufsize - total_sent_bytes, &sent_bytes, &err); if (io_stat == G_IO_STATUS_ERROR) { if (NULL != err) { XMMS_DBG ("Error writing to channel: %s\n", err->message); } break; } bufsize -= sent_bytes; total_sent_bytes += sent_bytes; } while (bufsize > 0); g_io_channel_flush (chan, &err); if (NULL != err) { XMMS_DBG ("warning: error flushing channel: %s\n", err->message); } }
static gboolean client_write (BtPlaybackControllerSocket * self, gchar * str) { gboolean res = FALSE; GError *error = NULL; gsize len; if (!self->priv->client_channel) return FALSE; GST_INFO ("sending reply : %s", str); g_io_channel_write_chars (self->priv->client_channel, str, -1, &len, &error); if (!error) { g_io_channel_write_chars (self->priv->client_channel, "\r\n", -1, &len, &error); if (!error) { g_io_channel_flush (self->priv->client_channel, &error); if (!error) { res = TRUE; } else { GST_WARNING ("iochannel error while flushing: %s", error->message); g_error_free (error); } } else { GST_WARNING ("iochannel error while writing: %s", error->message); g_error_free (error); } } else { GST_WARNING ("iochannel error while writing: %s", error->message); g_error_free (error); } return res; }
/** * catch_log_write_to_channel: * @channel: A #GIOChannel. * @message: A string log message. * * Writes @message to @channel and flushes the channel. */ static void catch_log_write_to_channel (GIOChannel *channel, const gchar *message) { g_io_channel_write_chars(channel, message, -1, NULL, NULL); g_io_channel_flush(channel, NULL); }
GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size) { GError *err = NULL; gsize written = 0; GIOStatus status = G_IO_STATUS_NORMAL; while (size) { g_debug("sending data, count: %d", (int)size); status = g_io_channel_write_chars(c->client_channel, buf, size, &written, &err); if (status == G_IO_STATUS_NORMAL) { size -= written; buf += written; } else if (status != G_IO_STATUS_AGAIN) { g_warning("error writing to channel: %s", err->message); return status; } } do { status = g_io_channel_flush(c->client_channel, &err); } while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) { g_warning("error flushing channel: %s", err->message); } return status; }
static void send_msg_to_controller(int fd, gint argc, gchar** argv) { /* Create a glib I/O channel. */ GIOChannel * gio = g_io_channel_unix_new(fd); g_io_channel_set_encoding(gio, NULL, NULL); /* Push current dir in case it is needed later */ gchar * cur_dir = g_get_current_dir(); g_io_channel_write_chars(gio, cur_dir, -1, NULL, NULL); /* Use "" as a pointer to '\0' since g_io_channel_write_chars() won't * accept NULL */ g_io_channel_write_chars(gio, "", 1, NULL, NULL); g_free(cur_dir); /* push all of argv. */ gint i; for (i = 0; i < argc; i ++) { g_io_channel_write_chars(gio, argv[i], -1, NULL, NULL); g_io_channel_write_chars(gio, "", 1, NULL, NULL); } g_io_channel_flush(gio, NULL); g_io_channel_unref(gio); close(fd); }
/* * write a command to a gdb channel and flush with a newlinw character */ void gdb_input_write_line(const gchar *line) { GIOStatus st; GError *err = NULL; gsize count; char command[1000]; sprintf(command, "%s\n", line); while (strlen(command)) { st = g_io_channel_write_chars(gdb_ch_in, command, strlen(command), &count, &err); strcpy(command, command + count); if (err || (st == G_IO_STATUS_ERROR) || (st == G_IO_STATUS_EOF)) { #ifdef DEBUG_OUTPUT dbg_cbs->send_message(err->message, "red"); #endif break; } } st = g_io_channel_flush(gdb_ch_in, &err); if (err || (st == G_IO_STATUS_ERROR) || (st == G_IO_STATUS_EOF)) { #ifdef DEBUG_OUTPUT dbg_cbs->send_message(err->message, "red"); #endif } }
gboolean interface_write(GIOChannel* chan, const gchar* str) { GIOStatus status; GError* err = NULL; int client = g_io_channel_unix_get_fd(chan); if (str && chan->is_writeable) { status = g_io_channel_write_chars(chan, str, -1, NULL, &err); if (status != G_IO_STATUS_NORMAL) { if (err) g_debug("[iw:%d] Can't write to IO channel (%d)", client, status); else g_debug("[iw:%d] Can't write to IO channel (%d): %s", client, status, err->message); return FALSE; } } status = g_io_channel_flush(chan, &err); if (status != G_IO_STATUS_NORMAL) { if (err) g_debug("[iw:%d] Can't flush IO channel (%d)", client, status); else g_debug("[iw:%d] Can't flush IO channel (%d): %s", client, status, err->message); return FALSE; } return TRUE; }
static int conn_channel_send_payload(GIOChannel *channel, QObject *payload) { int ret = 0; const char *buf; QString *payload_qstr; GError *err = NULL; g_assert(payload && channel); payload_qstr = qobject_to_json(payload); if (!payload_qstr) { return -EINVAL; } qstring_append_chr(payload_qstr, '\n'); buf = qstring_get_str(payload_qstr); ret = conn_channel_send_buf(channel, buf, strlen(buf)); if (ret) { goto out_free; } g_io_channel_flush(channel, &err); if (err != NULL) { g_warning("error flushing payload: %s", err->message); ret = err->code; goto out_free; } out_free: QDECREF(payload_qstr); if (err) { g_error_free(err); } return ret; }
gpointer client_reading_loop(Client* client) { size_t charsRead; char* message; gsize bytes_written; GError* error = NULL; while(message = connection_read_message(client->connection, &charsRead)) { g_print("recieved:%.*s", charsRead, message); #ifdef __UNIX__ if(client->isShellActive) { write_to_shell_in_if_active(client->shell_in_channel, message, charsRead, client); } else { #endif g_io_channel_write_chars(client->shell_in_channel, message, charsRead, &bytes_written, &error); #ifdef __UNIX__ } #endif g_io_channel_flush(client->shell_in_channel, &error); free(message); } printf("reading from client finished\n"); //g_io_channel_unref(shell_in_channel); return NULL; }
static void send_event_sockets(GPtrArray *sockets, GString *msg) { GError *error = NULL; GIOStatus ret; gsize len; guint i=0; while(i < sockets->len) { GIOChannel *gio = g_ptr_array_index(sockets, i++); if(gio && gio->is_writeable && msg) { ret = g_io_channel_write_chars (gio, msg->str, msg->len, &len, &error); if (ret == G_IO_STATUS_ERROR) { g_warning ("Error sending event to socket: %s", error->message); g_clear_error (&error); } else { if (g_io_channel_flush(gio, &error) == G_IO_STATUS_ERROR) { g_warning ("Error flushing: %s", error->message); g_clear_error (&error); } } } } }
gint send_request(Connection *con, Request *r) { if(con == NULL || r == NULL){ return -1; } GString *rq = request_tostring(r); // g_printf("\nMESSAGE: (%s, %d)Send reqeust : %s\n" // ,__FILE__, __LINE__, rq -> str); GIOStatus status; GError *err = NULL; gsize bytes_written = 0; gsize has_written = 0; while(has_written < rq -> len){ status = g_io_channel_write_chars(con -> channel , rq -> str + has_written , rq -> len - has_written , &bytes_written , &err); switch(status) { case G_IO_STATUS_NORMAL: //write success. has_written += bytes_written; //g_debug("Write %d bytes data.(%s, %d)" // , bytes_written, __FILE__ // , __LINE__); break; case G_IO_STATUS_EOF: g_warning("Write data EOF!! What's happenning?(%s, %d)" , __FILE__, __LINE__); return -1; case G_IO_STATUS_ERROR: g_warning("Write data ERROR!! code:%d msg:%s (%s, %d)" , err -> code, err -> message , __FILE__, __LINE__); g_error_free(err); return -1; case G_IO_STATUS_AGAIN: g_debug("Channel temporarily unavailable.(%s, %d)" , __FILE__, __LINE__); break; default: g_warning("Unknown io status!(%s, %d)" , __FILE__, __LINE__); return -1; } } status = g_io_channel_flush(con -> channel, &err); if(status != G_IO_STATUS_NORMAL){ g_warning("Flush io channel error! But don't warry...(%s, %d)" , __FILE__, __LINE__); } //g_debug("Write all date.(%s, %d)", __FILE__, __LINE__); g_string_free(rq, TRUE); return 0; }
/* nie jestem pewien czy ta funkcja powinna być w tym miejscu */ void zamknij_joystick() { /* conflicting types */ g_io_channel_flush(ioch, &jserror); g_io_channel_shutdown(ioch, TRUE, &jserror); g_io_channel_unref(ioch); /* FIXME: dodać zerowanie osi i wyłączanie przycisków */ close_rumble_fd(); }
static VALUE rg_flush(VALUE self) { GError* err = NULL; GIOStatus status = g_io_channel_flush(_SELF(self), &err); ioc_error(status, err); return self; }
void jb_log (const char *format, ...) { static gboolean logging = FALSE; static GIOChannel *log_channel = NULL; static char *current_log_file = NULL; va_list args; char *message; char *with_nl; GError *err = NULL; gsize bytes_written; g_return_if_fail(format != NULL); g_return_if_fail(log_file != NULL); if (logging) return; logging = TRUE; if (log_channel != NULL) { if (strcmp(current_log_file, log_file)) { if (g_io_channel_shutdown(log_channel, TRUE, &err) != G_IO_STATUS_NORMAL) jb_error("unable to write to %s: %s", current_log_file, err->message); g_io_channel_unref(log_channel); log_channel = NULL; g_free(current_log_file); } } if (log_channel == NULL) { current_log_file = g_strdup(log_file); log_channel = g_io_channel_new_file(log_file, "w", &err); if (log_channel == NULL) jb_error("unable to open %s for writing: %s", log_file, err->message); } va_start(args, format); message = g_strdup_vprintf(format, args); va_end(args); with_nl = g_strdup_printf("%s\n", message); g_free(message); if (g_io_channel_write_chars(log_channel, with_nl, -1, &bytes_written, &err) != G_IO_STATUS_NORMAL || g_io_channel_flush(log_channel, &err) != G_IO_STATUS_NORMAL) jb_error("unable to write to %s: %s", log_file, err->message); g_free(with_nl); logging = FALSE; }
/* * Blockingly receives a message from the ipc socket. Returns the status of the last read. */ static GIOStatus ipc_recv_message(GIOChannel *channel, uint32_t *message_type, uint32_t *reply_length, gchar **reply, GError **err) { /* Read the message header first */ GError *tmp_error = NULL; const uint32_t to_read = strlen(I3IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t); char msg[to_read]; char *walk = msg; GIOStatus status; status = g_io_channel_flush(channel, &tmp_error); if (tmp_error != NULL) { g_propagate_error(err, tmp_error); return status; } gsize read_bytes = 0; while (read_bytes < to_read) { status = g_io_channel_read_chars(channel, msg + read_bytes, to_read - read_bytes, &read_bytes, &tmp_error); if (tmp_error != NULL) { g_propagate_error(err, tmp_error); return status; } if (status == G_IO_STATUS_EOF) return status; } if (memcmp(walk, I3IPC_MAGIC, strlen(I3IPC_MAGIC)) != 0) { /* TODO i3ipc custom errors */ tmp_error = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid magic in reply"); g_propagate_error(err, tmp_error); return status; } walk += strlen(I3IPC_MAGIC); memcpy(reply_length, walk, sizeof(uint32_t)); walk += sizeof(uint32_t); if (message_type != NULL) memcpy(message_type, walk, sizeof(uint32_t)); *reply = malloc(*reply_length + 1); read_bytes = 0; while (read_bytes < *reply_length) { status = g_io_channel_read_chars(channel, *reply + read_bytes, *reply_length - read_bytes, &read_bytes, &tmp_error); if (tmp_error != NULL) { g_propagate_error(err, tmp_error); return status; } if (status == G_IO_STATUS_EOF) return status; } return status; }
static gboolean gst_avdtp_sink_unlock(GstBaseSink *basesink) { GstAvdtpSink *self = GST_AVDTP_SINK(basesink); if (self->stream != NULL) g_io_channel_flush(self->stream, NULL); return TRUE; }
static void write_command(GIOChannel *channel, gchar *cmd) { // Write command g_io_channel_write_chars(channel, cmd, (gssize) strlen(cmd), NULL, NULL); // Flush channel to make sure player actually gets it now g_io_channel_flush(channel, NULL); }
static gboolean maki_dcc_send_out_write (GIOChannel* source, GIOCondition condition, gpointer data) { gchar buffer[1024]; gsize bytes_read; GIOStatus status; makiDCCSend* dcc = data; if (condition & (G_IO_HUP | G_IO_ERR)) { goto error; } if ((status = g_io_channel_read_chars(dcc->channel.file, buffer, 1024, &bytes_read, NULL)) != G_IO_STATUS_ERROR) { if (bytes_read > 0) { dcc->position += bytes_read; i_io_channel_write_chars(source, buffer, bytes_read, NULL, NULL); g_io_channel_flush(source, NULL); } if (dcc->position >= dcc->size || status == G_IO_STATUS_EOF) { if (dcc->d.out.ack.position < dcc->size) { dcc->d.out.wait = TRUE; } goto finish; } } if (status == G_IO_STATUS_ERROR) { goto error; } return TRUE; error: dcc->status |= s_error; finish: if (!dcc->d.out.wait) { dcc->status &= ~s_running; maki_dcc_send_close(dcc); maki_dcc_send_emit(dcc); } dcc->d.out.sources[s_out_write] = 0; return FALSE; }
void gtk_pipe_int_write(int c) { #if GTK_MAJOR_VERSION == 2 int len; int code=INT_CODE; #ifdef DEBUGPIPE //fprintf(stderr, "Writing debug int %d\n", code); len = write(fpip_out,&code,sizeof(code)); if (len!=sizeof(code)) pipe_error("PIPE_INT_WRITE"); #endif //fprintf(stderr, "Writing int %d\n", c); len = write(fpip_out,&c,sizeof(c)); if (len!=sizeof(int)) pipe_error("PIPE_INT_WRITE"); #else // GTK 3 gsize len; int code=INT_CODE; GError *error = NULL; GIOStatus status; #ifdef DEBUGPIPE //fprintf(stderr, "Writing gtk debug int %d\n", code); status = g_io_channel_write_chars(channel_out, (gchar *)&code, sizeof(code), &len, &error); if ((len!=sizeof(code)) || (status != G_IO_STATUS_NORMAL)) channel_error("CHANNEL_INT_WRITE", status, error); g_io_channel_flush(channel_out, &error); #endif //fprintf(stderr, "Writing gtk int %d\n", c); g_io_channel_write_chars(channel_out, (gchar *)&c, sizeof(c), &len, &error); if (len!=sizeof(int)) pipe_error("CHANNEL_INT_WRITE"); g_io_channel_flush(channel_out, &error); #endif }
static void gdkevent_handle_any (GdkEvent *event, GIOChannel *channel) { gchar buffer[32]; g_snprintf(buffer, sizeof(buffer), "%d|%p\n", event->any.type, event->configure.window); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); }
static void gdkevent_handle_destroy (GdkEvent *event, GIOChannel *channel) { gchar buffer[32]; g_snprintf(buffer, sizeof(buffer), "%d|%p\n", GDK_DESTROY, event->any.window); g_io_channel_write_chars(channel, buffer, -1, NULL, NULL); g_io_channel_flush(channel, NULL); }
void bacon_message_connection_send (BaconMessageConnection *conn, const char *message) { g_return_if_fail (conn != NULL); g_return_if_fail (message != NULL); g_io_channel_write_chars (conn->chan, message, strlen (message), NULL, NULL); g_io_channel_write_chars (conn->chan, "\n", 1, NULL, NULL); g_io_channel_flush (conn->chan, NULL); }
static gboolean socket_watch(GIOChannel *chan) { GIOStatus ret; GError *error = NULL; char *line, *inputtext; gsize len; ret = g_io_channel_read_line(chan, &line, &len, NULL, &error); if (ret == G_IO_STATUS_ERROR || ret == G_IO_STATUS_EOF) { if (ret == G_IO_STATUS_ERROR) { g_warning("Error reading: %s", error->message); g_error_free(error); } /* shutdown and remove the client channel */ ret = g_io_channel_shutdown(chan, true, &error); g_io_channel_unref(chan); if (ret == G_IO_STATUS_ERROR) { g_warning("Error closing: %s", error->message); g_error_free(error); } return false; } /* simulate the typed flag to allow to record the commands in history */ vb.state.typed = true; /* run the commands */ map_handle_string(line, true); g_free(line); /* unset typed flag */ vb.state.typed = false; /* We assume that the commands result is still available in the inputbox, * so the whole inputbox content is written to the socket. */ inputtext = vb_get_input_text(); ret = g_io_channel_write_chars(chan, inputtext, -1, &len, &error); if (ret == G_IO_STATUS_ERROR) { g_warning("Error writing: %s", error->message); g_error_free(error); } if (g_io_channel_flush(chan, &error) == G_IO_STATUS_ERROR) { g_warning("Error flushing: %s", error->message); g_error_free(error); } g_free(inputtext); return true; }
static void gdkevent_handle_focus (GdkEvent *event, GIOChannel *channel) { 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); }