示例#1
0
static gboolean
gst_gio_base_sink_event (GstBaseSink * base_sink, GstEvent * event)
{
  GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink);
  GstFlowReturn ret = GST_FLOW_OK;

  if (sink->stream == NULL)
    return TRUE;

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_SEGMENT:
      if (G_IS_OUTPUT_STREAM (sink->stream)) {
        const GstSegment *segment;

        gst_event_parse_segment (event, &segment);

        if (segment->format != GST_FORMAT_BYTES) {
          GST_WARNING_OBJECT (sink, "ignored SEGMENT event in %s format",
              gst_format_get_name (segment->format));
          break;
        }

        if (GST_GIO_STREAM_IS_SEEKABLE (sink->stream)) {
          ret = gst_gio_seek (sink, G_SEEKABLE (sink->stream), segment->start,
              sink->cancel);
          if (ret == GST_FLOW_OK)
            sink->position = segment->start;
        } else {
          ret = GST_FLOW_NOT_SUPPORTED;
        }
      }
      break;

    case GST_EVENT_EOS:
    case GST_EVENT_FLUSH_START:
      if (G_IS_OUTPUT_STREAM (sink->stream)) {
        gboolean success;
        GError *err = NULL;

        success = g_output_stream_flush (sink->stream, sink->cancel, &err);

        if (!success && !gst_gio_error (sink, "g_output_stream_flush", &err,
                &ret)) {
          GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL),
              ("flush failed: %s", err->message));
          g_clear_error (&err);
        }
      }
      break;

    default:
      break;
  }
  if (ret == GST_FLOW_OK)
    return GST_BASE_SINK_CLASS (parent_class)->event (base_sink, event);
  else {
    gst_event_unref (event);
    return FALSE;
  }
}
static gboolean
dispatch_close (OstreeRepo                 *repo,
                StaticDeltaExecutionState  *state,
                GCancellable               *cancellable,  
                GError                    **error)
{
  gboolean ret = FALSE;
  
  if (state->content_out)
    {
      if (!g_output_stream_flush (state->content_out, cancellable, error))
        goto out;

      if (!_ostree_repo_commit_trusted_content_bare (repo, state->checksum, &state->barecommitstate,
                                                     state->uid, state->gid, state->mode,
                                                     state->xattrs,
                                                     cancellable, error))
        goto out;
    }

  if (!dispatch_unset_read_source (repo, state, cancellable, error))
    goto out;
      
  g_clear_pointer (&state->xattrs, g_variant_unref);
  g_clear_object (&state->content_out);
  
  state->checksum_index++;
  state->output_target = NULL;

  ret = TRUE;
 out:
  if (!ret)
    g_prefix_error (error, "opcode open-splice-and-close: ");
  return ret;
}
示例#3
0
gboolean	
_http_package_write_to_stream_real(HttpPackage * package,
				GOutputStream * stream,
				gsize * length,
				GCancellable * cancellable,
				GError ** error)
{
	HttpPackagePrivate
	* priv = http_package_get_instance_private(package);
	gsize 
	count = 0,total_count = 0;
	GList
	* iter;
	gboolean
	done = TRUE;
	for(iter = g_list_first(priv->attributes);((iter)&&(done));iter = iter->next)
	{
		HttpPackageAttribute
		* attr = (HttpPackageAttribute*)iter->data;
		done = g_output_stream_printf(stream,&count,cancellable,error,"%s: %s\r\n",attr->name,attr->value);
		total_count += count;
	}
	if(done)
	{
		done = g_output_stream_printf(stream,&count,cancellable,error,"\r\n");
		if(length) *length = total_count + count;
	}
	if(done)
		g_output_stream_flush(stream,cancellable,error);
	return done;
}
示例#4
0
static gboolean
emfe_error_format (EMailFormatterExtension *extension,
                   EMailFormatter *formatter,
                   EMailFormatterContext *context,
                   EMailPart *part,
                   GOutputStream *stream,
                   GCancellable *cancellable)
{
	GOutputStream *filtered_stream;
	CamelMimeFilter *filter;
	CamelMimePart *mime_part;
	CamelDataWrapper *dw;
	const gchar *string;
	gchar *html;

	mime_part = e_mail_part_ref_mime_part (part);
	dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));

	html = g_strdup_printf (
		"<div class=\"part-container -e-mail-formatter-frame-color "
		"-e-mail-formatter-body-color -e-web-view-text-color\">"
		"<div class=\"part-container-inner-margin pre\">\n"
		"<table border=\"0\" cellspacing=\"10\" "
		"cellpadding=\"0\" width=\"100%%\">\n"
		"<tr valign=\"top\"><td width=50>"
		"<img src=\"gtk-stock://%s/?size=%d\" /></td>\n"
		"<td style=\"color: red;\">",
		"dialog-error", GTK_ICON_SIZE_DIALOG);

	g_output_stream_write_all (
		stream, html, strlen (html), NULL, cancellable, NULL);

	g_free (html);

	filter = camel_mime_filter_tohtml_new (
		CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
		CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
	filtered_stream = camel_filter_output_stream_new (stream, filter);
	g_object_unref (filter);

	camel_data_wrapper_decode_to_output_stream_sync (
		dw, filtered_stream, cancellable, NULL);
	g_output_stream_flush (filtered_stream, cancellable, NULL);

	g_object_unref (filtered_stream);

	string = "</td></tr></table></div></div>";

	g_output_stream_write_all (
		stream, string, strlen (string), NULL, cancellable, NULL);

	g_object_unref (mime_part);

	return TRUE;
}
示例#5
0
static void 
get_callback (SoupSession *session, SoupMessage *msg, SeahorseHKPOperation *hop) 
{
    GError *err = NULL;
    const gchar *start;
    const gchar *end;
    GOutputStream *output;
    const gchar *text;
    gboolean ret;
    guint len;
    gsize written;
    
    if (hop->cancelling)
        return;
    
    if (SOUP_MESSAGE_IS_ERROR (msg)) {
        fail_hkp_operation (hop, msg, NULL);
        return;
    }
    
    end = text = msg->response_body->data;
    len = msg->response_body->length;
    
    for (;;) {

        len -= end - text;
        text = end;
        
        if(!detect_key (text, len, &start, &end))
            break;
        
		/* Any key blocks get written to our result data */
		output = seahorse_operation_get_result (SEAHORSE_OPERATION (hop));
		g_return_if_fail (G_IS_OUTPUT_STREAM (output));

		ret = g_output_stream_write_all (output, start, end - start, &written, NULL, &err) &&
		      g_output_stream_write_all (output, "\n", 1, &written, NULL, &err) &&
		      g_output_stream_flush (output, NULL, &err);

		if (!ret) {
			seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, err);
			return;
		}
    	}
        
    	if (--hop->requests <= 0) {
    		output = seahorse_operation_get_result (SEAHORSE_OPERATION (hop));
    		g_return_if_fail (G_IS_OUTPUT_STREAM (output));
    		g_output_stream_close (output, NULL, &err);
    		seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, err);
    	} else {
    		seahorse_operation_mark_progress_full (SEAHORSE_OPERATION (hop), _("Retrieving keys..."), 
    		                                       hop->requests, hop->total);
    	}
}
示例#6
0
 arrow::Status Flush() override {
   GError *error = NULL;
   auto successed = g_output_stream_flush(output_stream_, NULL, &error);
   if (successed) {
     return arrow::Status::OK();
   } else {
     return garrow_error_to_status(error,
                                   arrow::StatusCode::IOError,
                                   "[gio-output-stream][flush]");
   }
 }
示例#7
0
文件: png-save.c 项目: jonnor/gegl
static void
flush_fn(png_structp png_ptr)
{
  GError *err = NULL;
  GOutputStream *stream = G_OUTPUT_STREAM(png_get_io_ptr(png_ptr));
  g_assert(stream);

  g_output_stream_flush(stream, NULL, &err);
  if (err) {
    g_printerr("gegl:save-png %s: %s\n", __PRETTY_FUNCTION__, err->message);
  }
}
static gboolean
emfe_text_enriched_format (EMailFormatterExtension *extension,
                           EMailFormatter *formatter,
                           EMailFormatterContext *context,
                           EMailPart *part,
                           GOutputStream *stream,
                           GCancellable *cancellable)
{
	GOutputStream *filtered_stream;
	CamelMimeFilter *filter;
	const gchar *mime_type;
	const gchar *string;
	gchar *str;
	guint32 filter_flags = 0;

	if (g_cancellable_is_cancelled (cancellable))
		return FALSE;

	mime_type = e_mail_part_get_mime_type (part);

	if (g_strcmp0 (mime_type, "text/richtext") == 0)
		filter_flags = CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT;

	filter = camel_mime_filter_enriched_new (filter_flags);
	filtered_stream = camel_filter_output_stream_new (stream, filter);
	g_filter_output_stream_set_close_base_stream (
		G_FILTER_OUTPUT_STREAM (filtered_stream), FALSE);
	g_object_unref (filter);

	str = g_strdup_printf (
		"<div class=\"part-container -e-mail-formatter-frame-color %s"
		"-e-web-view-background-color -e-web-view-text-color\">"
		"<div class=\"part-container-inner-margin\">\n",
		e_mail_part_get_frame_security_style (part));

	g_output_stream_write_all (
		stream, str, strlen (str), NULL, cancellable, NULL);
	g_free (str);

	e_mail_formatter_format_text (
		formatter, part, filtered_stream, cancellable);
	g_output_stream_flush (filtered_stream, cancellable, NULL);

	g_object_unref (filtered_stream);

	string = "</div></div>";

	g_output_stream_write_all (
		stream, string, strlen (string), NULL, cancellable, NULL);

	return TRUE;
}
static gpointer
gegl_tile_backend_file_flush (GeglTileSource *source,
                              GeglTile       *tile,
                              gint            x,
                              gint            y,
                              gint            z)
{
  GeglTileBackend     *backend;
  GeglTileBackendFile *self;
  GList               *tiles;

  backend  = GEGL_TILE_BACKEND (source);
  self     = GEGL_TILE_BACKEND_FILE (backend);

  gegl_tile_backend_file_ensure_exist (self);

  GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "flushing %s", self->path);


  self->header.rev ++;
  self->header.next = self->next_pre_alloc; /* this is the offset
                                               we start handing
                                               out headers from*/
  tiles = g_hash_table_get_keys (self->index);

  if (tiles == NULL)
    self->header.next = 0;
  else
    {
      GList *iter;
      for (iter = tiles; iter; iter = iter->next)
        {
          GeglBufferItem *item = iter->data;

          gegl_tile_backend_file_write_block (self, &item->block);
        }
      gegl_tile_backend_file_write_block (self, NULL); /* terminate the index */
      g_list_free (tiles);
    }

  gegl_tile_backend_file_write_header (self);
#if HAVE_GIO
  g_output_stream_flush (self->o, NULL, NULL);
#else
  fsync (self->o);
#endif

  GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "flushed %s", self->path);

  return (gpointer)0xf0f;
}
static gboolean
dispatch_close (OstreeRepo                 *repo,
                StaticDeltaExecutionState  *state,
                GCancellable               *cancellable,  
                GError                    **error)
{
  gboolean ret = FALSE;
  
  if (state->content_out)
    {
      if (!g_output_stream_flush (state->content_out, cancellable, error))
        goto out;

      if (state->content_checksum)
        {
          const char *actual_checksum = g_checksum_get_string (state->content_checksum);

          if (strcmp (actual_checksum, state->checksum) != 0)
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Corrupted object %s (actual checksum is %s)",
                           state->checksum, actual_checksum);
              goto out;
            }
        }

      if (!_ostree_repo_commit_trusted_content_bare (repo, state->checksum, &state->barecommitstate,
                                                     state->uid, state->gid, state->mode,
                                                     state->xattrs,
                                                     cancellable, error))
        goto out;
    }

  if (!dispatch_unset_read_source (repo, state, cancellable, error))
    goto out;
      
  g_clear_pointer (&state->xattrs, g_variant_unref);
  g_clear_pointer (&state->content_checksum, g_checksum_free);
  g_clear_object (&state->content_out);
  
  state->checksum_index++;
  state->output_target = NULL;

  ret = TRUE;
 out:
  if (!ret)
    g_prefix_error (error, "opcode open-splice-and-close: ");
  return ret;
}
示例#11
0
static gboolean
gst_gio_base_sink_stop (GstBaseSink * base_sink)
{
  GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink);
  GstGioBaseSinkClass *klass = GST_GIO_BASE_SINK_GET_CLASS (sink);
  gboolean success;
  GError *err = NULL;

  if (klass->close_on_stop && G_IS_OUTPUT_STREAM (sink->stream)) {
    GST_DEBUG_OBJECT (sink, "closing stream");

    /* FIXME: can block but unfortunately we can't use async operations
     * here because they require a running main loop */
    success = g_output_stream_close (sink->stream, sink->cancel, &err);

    if (!success && !gst_gio_error (sink, "g_output_stream_close", &err, NULL)) {
      GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL),
          ("gio_output_stream_close failed: %s", err->message));
      g_clear_error (&err);
    } else if (!success) {
      GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL),
          ("g_output_stream_close failed"));
    } else {
      GST_DEBUG_OBJECT (sink, "g_outut_stream_close succeeded");
    }

    g_object_unref (sink->stream);
    sink->stream = NULL;
  } else {
    success = g_output_stream_flush (sink->stream, sink->cancel, &err);

    if (!success && !gst_gio_error (sink, "g_output_stream_flush", &err, NULL)) {
      GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL),
          ("gio_output_stream_flush failed: %s", err->message));
      g_clear_error (&err);
    } else if (!success) {
      GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL),
          ("g_output_stream_flush failed"));
    } else {
      GST_DEBUG_OBJECT (sink, "g_outut_stream_flush succeeded");
    }

    g_object_unref (sink->stream);
    sink->stream = NULL;
  }

  return TRUE;
}
示例#12
0
static gboolean
g_filter_output_stream_flush (GOutputStream  *stream,
                              GCancellable   *cancellable,
                              GError        **error)
{
  GFilterOutputStream *filter_stream;
  gboolean res;

  filter_stream = G_FILTER_OUTPUT_STREAM (stream);

  res = g_output_stream_flush (filter_stream->base_stream,
                               cancellable,
                               error);

  return res;
}
示例#13
0
gboolean
gegl_tile_backend_file_unlock (GeglTileBackendFile *self)
{
  if (!(self->header.flags & GEGL_FLAG_LOCKED))
    {
      g_warning ("tried to unlock unlocked buffer");
      return FALSE;
    }
  self->header.flags -= GEGL_FLAG_LOCKED;
  gegl_tile_backend_file_write_header (self);
#if HAVE_GIO
  g_output_stream_flush (self->o, NULL, NULL);
#else
  fsync (self->o);
#endif
  return TRUE;
}
示例#14
0
/* Called by gpgme to read data */
static ssize_t
output_write(void *handle, const void *buffer, size_t size)
{
	GOutputStream* output = handle;
	GError *err = NULL;
	gsize written;
	
	g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), -1);
	
	if (!g_output_stream_write_all (output, buffer, size, &written, NULL, &err))
		return handle_gio_error (err);
	
	if (!g_output_stream_flush (output, NULL, &err))
		return handle_gio_error (err);
		
	return written;
}
示例#15
0
gboolean
gegl_tile_backend_file_try_lock (GeglTileBackendFile *self)
{
  GeglBufferHeader new_header;
  new_header = gegl_buffer_read_header (self->i, NULL)->header;
  if (new_header.flags & GEGL_FLAG_LOCKED)
    {
      return FALSE;
    }
  self->header.flags += GEGL_FLAG_LOCKED;
  gegl_tile_backend_file_write_header (self);
#if HAVE_GIO
  g_output_stream_flush (self->o, NULL, NULL);
#else
  fsync (self->o);
#endif
  return TRUE;
}
static gboolean
emqfe_text_html_format (EMailFormatterExtension *extension,
                        EMailFormatter *formatter,
                        EMailFormatterContext *context,
                        EMailPart *part,
                        GOutputStream *stream,
                        GCancellable *cancellable)
{
	EMailFormatterQuoteContext *qf_context;
	GOutputStream *filtered_stream;
	const gchar *string;

	qf_context = (EMailFormatterQuoteContext *) context;

	string = "<!-- text/html -->";
	g_output_stream_write_all (
		stream, string, strlen (string), NULL, cancellable, NULL);

	filtered_stream = g_object_ref (stream);

	if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
		CamelMimeFilter *filter;
		GOutputStream *temp_stream;

		filter = e_mail_stripsig_filter_new (FALSE);
		temp_stream = camel_filter_output_stream_new (
			filtered_stream, filter);
		g_filter_output_stream_set_close_base_stream (
			G_FILTER_OUTPUT_STREAM (temp_stream), FALSE);
		g_object_unref (filtered_stream);
		filtered_stream = temp_stream;
		g_object_unref (filter);
	}

	e_mail_formatter_format_text (
		formatter, part, filtered_stream, cancellable);

	g_output_stream_flush (filtered_stream, cancellable, NULL);

	g_object_unref (filtered_stream);

	return TRUE;
}
static int
stream_flush (CamelStream *stream)
{
	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
	GError *error = NULL;

	g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1);
	g_return_val_if_fail (stream_vfs->stream != NULL, -1);
	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), -1);

	g_output_stream_flush (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error);

	if (error) {
		g_warning ("%s", error->message);
		g_error_free (error);
		return -1;
	}

	return 0;
}
示例#18
0
static void
_completion_create_initial_file(GFile *file, const gchar *text)
{
	gchar *path;
	gint len;
	GFileOutputStream *stream;
	gchar buffer[block_size];

	g_assert(file != NULL);
	g_assert(text != NULL);

	len = strlen(text);

	g_return_if_fail(len <= COMPLETION_STRING_SIZE);

	path = g_file_get_path(file);

	g_debug("Creating file: \"%s\"", path);

	if((stream = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, NULL)))
	{
		memset(buffer, 0, block_size);
		memcpy(buffer + COMPLETION_COUNTER_SIZE, text, len);

		g_debug("Appending new text: \"%s\"", text);
		g_output_stream_write(G_OUTPUT_STREAM(stream), buffer, block_size, NULL, NULL);
		g_output_stream_flush(G_OUTPUT_STREAM(stream), NULL, NULL);

		g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
		g_object_unref(stream);
	}
	else
	{
		g_warning("Couldn't create file: \"%s\"", path);
	}

	g_free(path);
}
示例#19
0
static void ekg_gnutls_flush(struct ekg_connection *c) {
	struct ekg_gnutls_connection *gc = c->master->priv_data;
	GMemoryOutputStream *dos = gc->outstream;
	ssize_t ret;
	gconstpointer bufp;
	gsize bufleft;

		/* GMemoryOutputStream is not supposed to fail */
	g_assert(g_output_stream_flush(
			G_OUTPUT_STREAM(c->outstream),
			NULL,
			NULL));

		/* now pass the written data to gnutls */
	bufp = g_memory_output_stream_get_data(dos);
	bufleft = g_memory_output_stream_get_data_size(dos);
	do {
		ret = gnutls_record_send(gc->session, bufp, bufleft);

		if (ret > 0) {
			g_assert(ret <= bufleft);
			bufp += ret;
			bufleft -= ret;
		} else if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN) {
			debug_error("gnutls_flush(), write failed: %s\n",
					gnutls_strerror(ret));
			/* XXX */
			failed_write(c);
		}
	} while (bufleft > 0);

	{
		GSeekable *sos = G_SEEKABLE(dos);
		g_assert(g_seekable_seek(sos, 0, G_SEEK_SET, NULL, NULL));
		g_assert(g_seekable_truncate(sos, 0, NULL, NULL));
	}
}
static gboolean
emqfe_text_plain_format (EMailFormatterExtension *extension,
                         EMailFormatter *formatter,
                         EMailFormatterContext *context,
                         EMailPart *part,
                         GOutputStream *stream,
                         GCancellable *cancellable)
{
	GOutputStream *filtered_stream;
	GOutputStream *temp_stream;
	CamelMimeFilter *filter;
	CamelMimePart *mime_part;
	CamelContentType *type;
	EMailFormatterQuoteContext *qf_context;
	CamelMimeFilterToHTMLFlags text_flags;
	const gchar *format;
	guint32 rgb = 0x737373;

	mime_part = e_mail_part_ref_mime_part (part);
	if (mime_part == NULL)
		return FALSE;

	qf_context = (EMailFormatterQuoteContext *) context;

	text_flags =
		CAMEL_MIME_FILTER_TOHTML_PRE |
		CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
		CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES;

	/* XXX Should we define a separate EMailFormatter property
	 *     for using CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION? */
	if (e_mail_formatter_get_mark_citations (formatter))
		text_flags |= CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION;

	/* Check for RFC 2646 flowed text. */
	type = camel_mime_part_get_content_type (mime_part);
	if (camel_content_type_is (type, "text", "plain")
	    && (format = camel_content_type_param (type, "format"))
	    && !g_ascii_strcasecmp (format, "flowed"))
		text_flags |= CAMEL_MIME_FILTER_TOHTML_FORMAT_FLOWED;

	filtered_stream = g_object_ref (stream);

	if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
		filter = e_mail_stripsig_filter_new (TRUE);
		temp_stream = camel_filter_output_stream_new (
			filtered_stream, filter);
		g_filter_output_stream_set_close_base_stream (
			G_FILTER_OUTPUT_STREAM (temp_stream), FALSE);
		g_object_unref (filtered_stream);
		filtered_stream = temp_stream;
		g_object_unref (filter);
	}

	filter = camel_mime_filter_tohtml_new (text_flags, rgb);
	temp_stream = camel_filter_output_stream_new (filtered_stream, filter);
	g_filter_output_stream_set_close_base_stream (
		G_FILTER_OUTPUT_STREAM (temp_stream), FALSE);
	g_object_unref (filtered_stream);
	filtered_stream = temp_stream;
	g_object_unref (filter);

	e_mail_formatter_format_text (
		formatter, part, filtered_stream, cancellable);

	g_output_stream_flush (filtered_stream, cancellable, NULL);
	g_object_unref (filtered_stream);

	g_object_unref (mime_part);

	return TRUE;
}
示例#21
0
static gboolean on_incoming_connection(GThreadedSocketService *service,
    GSocketConnection *connection, GObject *source_object, OwrImageServer *image_server)
{
    GOutputStream *bos;
    GDataInputStream *dis;
    gchar *error_body, *error_header = NULL, *response_header = NULL;
    gchar *line, *tag;
    gsize line_length, i;
    guint content_length = 0;
    OwrImageRenderer *image_renderer;
    GBytes *image;
    gconstpointer image_data;
    gsize image_data_size = 0;

    OWR_UNUSED(service);
    OWR_UNUSED(source_object);

    g_return_val_if_fail(OWR_IS_IMAGE_SERVER(image_server), TRUE);

    bos = g_buffered_output_stream_new(g_io_stream_get_output_stream(G_IO_STREAM(connection)));
    dis = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(connection)));
    g_data_input_stream_set_newline_type(dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);

    error_body = "404 Not Found";
    error_header = g_strdup_printf(HTTP_RESPONSE_HEADER_TEMPLATE, 404, "Not Found",
        "text/plain", (guint)strlen(error_body));

    while (TRUE) {
        line = g_data_input_stream_read_line(dis, &line_length, NULL, NULL);
        if (!line)
            break;

        if (line_length > 6) {
            tag = g_strdup(line + 7);
            for (i = 0; i < strlen(tag); i++) {
                if (tag[i] == '-') {
                    tag[i] = '\0';
                    break;
                }
            }
        } else
            tag = NULL;

        g_free(line);

        while ((line = g_data_input_stream_read_line(dis, &line_length, NULL, NULL))) {
            g_free(line);

            if (!line_length) {
                /* got all request headers */
                break;
            }
        }

        if (!line)
            break;

        g_mutex_lock(&image_server->priv->image_renderers_mutex);
        image_renderer = tag ? g_hash_table_lookup(image_server->priv->image_renderers, tag) : NULL;
        g_mutex_unlock(&image_server->priv->image_renderers_mutex);

        image = image_renderer ? _owr_image_renderer_pull_bmp_image(image_renderer) : NULL;

        if (!image) {
            g_output_stream_write(bos, error_header, strlen(error_header), NULL, NULL);
            g_output_stream_write(bos, error_body, strlen(error_body), NULL, NULL);
            break;
        }

        image_data = g_bytes_get_data(image, &image_data_size);

        if (content_length != image_data_size) {
            content_length = image_data_size;
            g_free(response_header);
            response_header = g_strdup_printf(HTTP_RESPONSE_HEADER_TEMPLATE, 200, "OK",
                "image/bmp", content_length);
            g_buffered_output_stream_set_buffer_size(G_BUFFERED_OUTPUT_STREAM(bos),
                strlen(response_header) + content_length);
        }
        g_output_stream_write(bos, response_header, strlen(response_header), NULL, NULL);
        g_output_stream_write(bos, image_data, image_data_size, NULL, NULL);
        g_output_stream_flush(bos, NULL, NULL);

        g_bytes_unref(image);
    }

    g_free(response_header);
    g_free(error_header);
    g_object_unref(dis);
    g_object_unref(bos);

    return FALSE;
}
示例#22
0
static gboolean
checkout_object_for_uncompressed_cache (OstreeRepo      *self,
                                        const char      *loose_path,
                                        GFileInfo       *src_info,
                                        GInputStream    *content,
                                        GCancellable    *cancellable,
                                        GError         **error)
{
  gboolean ret = FALSE;
  g_autofree char *temp_filename = NULL;
  g_autoptr(GOutputStream) temp_out = NULL;
  int fd;
  int res;
  guint32 file_mode;

  /* Don't make setuid files in uncompressed cache */
  file_mode = g_file_info_get_attribute_uint32 (src_info, "unix::mode");
  file_mode &= ~(S_ISUID|S_ISGID);

  if (!gs_file_open_in_tmpdir_at (self->tmp_dir_fd, file_mode,
                                  &temp_filename, &temp_out,
                                  cancellable, error))
    goto out;

  if (g_output_stream_splice (temp_out, content, 0, cancellable, error) < 0)
    goto out;

  if (!g_output_stream_flush (temp_out, cancellable, error))
    goto out;

  fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)temp_out);

  if (!self->disable_fsync)
    {
      do
        res = fsync (fd);
      while (G_UNLIKELY (res == -1 && errno == EINTR));
      if (G_UNLIKELY (res == -1))
        {
          glnx_set_error_from_errno (error);
          goto out;
        }
    }

  if (!g_output_stream_close (temp_out, cancellable, error))
    goto out;

  if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd,
                                            loose_path,
                                            cancellable, error))
    goto out;

  if (G_UNLIKELY (renameat (self->tmp_dir_fd, temp_filename,
                            self->uncompressed_objects_dir_fd, loose_path) == -1))
    {
      if (errno != EEXIST)
        {
          glnx_set_error_from_errno (error);
          g_prefix_error (error, "Storing file '%s': ", temp_filename);
          goto out;
        }
      else
        (void) unlinkat (self->tmp_dir_fd, temp_filename, 0);
    }

  ret = TRUE;
 out:
  return ret;
}
示例#23
0
static gboolean
write_regular_file_content (OstreeRepo            *self,
                            OstreeRepoCheckoutOptions *options,
                            GOutputStream         *output,
                            GFileInfo             *file_info,
                            GVariant              *xattrs,
                            GInputStream          *input,
                            GCancellable          *cancellable,
                            GError               **error)
{
  gboolean ret = FALSE;
  const OstreeRepoCheckoutMode mode = options->mode;
  int fd;
  int res;

  if (g_output_stream_splice (output, input, 0,
                              cancellable, error) < 0)
    goto out;

  if (!g_output_stream_flush (output, cancellable, error))
    goto out;

  fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)output);

  if (mode != OSTREE_REPO_CHECKOUT_MODE_USER)
    {
      do
        res = fchown (fd,
                      g_file_info_get_attribute_uint32 (file_info, "unix::uid"),
                      g_file_info_get_attribute_uint32 (file_info, "unix::gid"));
      while (G_UNLIKELY (res == -1 && errno == EINTR));
      if (G_UNLIKELY (res == -1))
        {
          glnx_set_error_from_errno (error);
          goto out;
        }

      do
        res = fchmod (fd, g_file_info_get_attribute_uint32 (file_info, "unix::mode"));
      while (G_UNLIKELY (res == -1 && errno == EINTR));
      if (G_UNLIKELY (res == -1))
        {
          glnx_set_error_from_errno (error);
          goto out;
        }
              
      if (xattrs)
        {
          if (!glnx_fd_set_all_xattrs (fd, xattrs, cancellable, error))
            goto out;
        }
    }
          
  if (fsync_is_enabled (self, options))
    {
      if (fsync (fd) == -1)
        {
          glnx_set_error_from_errno (error);
          goto out;
        }
    }
          
  if (!g_output_stream_close (output, cancellable, error))
    goto out;

  ret = TRUE;
 out:
  return ret;
}
示例#24
0
文件: skkserv.c 项目: pkg-ime/libskk
static void skk_skk_serv_close_connection (SkkSkkServ* self) {
	GSocketConnection* _tmp0_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->connection;
	if (_tmp0_ != NULL) {
		{
			guint8 _tmp1_;
			gsize bytes_written = 0UL;
			GSocketConnection* _tmp2_;
			GOutputStream* _tmp3_;
			GOutputStream* _tmp4_;
			gsize _tmp5_ = 0UL;
			GSocketConnection* _tmp6_;
			GOutputStream* _tmp7_;
			GOutputStream* _tmp8_;
			GSocketConnection* _tmp9_;
			self->priv->buffer[0] = (guint8) '0';
			_tmp1_ = self->priv->buffer[0];
			_tmp2_ = self->priv->connection;
			_tmp3_ = g_io_stream_get_output_stream ((GIOStream*) _tmp2_);
			_tmp4_ = _tmp3_;
			g_output_stream_write_all (_tmp4_, self->priv->buffer + 0, (gsize) (1 - 0), &_tmp5_, NULL, &_inner_error_);
			bytes_written = _tmp5_;
			if (_inner_error_ != NULL) {
				goto __catch16_g_error;
			}
			_tmp6_ = self->priv->connection;
			_tmp7_ = g_io_stream_get_output_stream ((GIOStream*) _tmp6_);
			_tmp8_ = _tmp7_;
			g_output_stream_flush (_tmp8_, NULL, &_inner_error_);
			if (_inner_error_ != NULL) {
				goto __catch16_g_error;
			}
			_tmp9_ = self->priv->connection;
			g_io_stream_close ((GIOStream*) _tmp9_, NULL, &_inner_error_);
			if (_inner_error_ != NULL) {
				goto __catch16_g_error;
			}
		}
		goto __finally16;
		__catch16_g_error:
		{
			GError* e = NULL;
			GError* _tmp10_;
			const gchar* _tmp11_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp10_ = e;
			_tmp11_ = _tmp10_->message;
			g_warning ("skkserv.vala:43: can't close skkserv: %s", _tmp11_);
			_g_error_free0 (e);
		}
		__finally16:
		if (_inner_error_ != NULL) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
		_g_object_unref0 (self->priv->connection);
		self->priv->connection = NULL;
	}
}
示例#25
0
static gboolean
handle_install_authorized_keys (MinCloudAgentApp      *self,
                                GInputStream               *instream,
                                GCancellable               *cancellable,
                                GError                    **error)
{
  gboolean ret = FALSE;
  int fd;
  guint i;
  gs_unref_object GOutputStream *outstream = NULL;
  gs_unref_object GDataInputStream *datain = NULL;
  gs_unref_ptrarray GPtrArray *lines = g_ptr_array_new_with_free_func (g_free);

  datain = g_data_input_stream_new (instream);

  while (TRUE)
    {
      gsize len;
      GError *temp_error = NULL;
      char *line = g_data_input_stream_read_line_utf8 (datain, &len, cancellable, &temp_error);
      if (temp_error != NULL)
        {
          g_propagate_error (error, temp_error);
          g_prefix_error (error, "Reading ssh keys: ");
          goto out;
        }
      if (!line)
        break;
      g_ptr_array_add (lines, line);
    }

  (void) g_input_stream_close ((GInputStream*)datain, NULL, NULL);

  outstream = (GOutputStream*)g_file_append_to (self->authorized_keys_path, 0, cancellable, error);
  if (!outstream)
    {
      g_prefix_error (error, "Appending to '%s': ",
                      gs_file_get_path_cached (self->authorized_keys_path));
      goto out;
    }

  fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)outstream);
  if (fchmod (fd, 0600) != 0)
    {
      int errsv = errno;
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Failed to chmod authorized_keys: %s",
                   g_strerror (errsv));
      goto out;
    }

  for (i = 0; i < lines->len; i++)
    {
      const char *line = lines->pdata[i];
      char nl[] = { '\n' };
      gsize bytes_written;
      if (!g_output_stream_write_all (outstream, line, strlen (line),
                                      &bytes_written,
                                      cancellable, error))
        goto out;
      if (!g_output_stream_write_all (outstream, nl, sizeof (nl),
                                      &bytes_written,
                                      cancellable, error))
        goto out;
    }

  if (!g_output_stream_flush (outstream, cancellable, error))
    goto out;

  gs_log_structured_print_id_v (MCA_KEY_INSTALLED_SUCCESS_ID,
                                "Successfully installed ssh key for '%s'",
                                "root");

  ret = TRUE;
 out:
  return ret;
}
示例#26
0
/**
 * gs_console_read_password:
 * @console: the #GSConsole
 * @prompt: A string to output before reading the password
 * @error: a #GError
 *
 * Write @prompt to standard output, then switch output echo off, read
 * a result string, then switch output echo back on.
 *
 * Returns: A string, or %NULL on error
 */
char *
gs_console_read_password (GSConsole     *console,
                          const char    *prompt,
                          GCancellable  *cancellable,
                          GError       **error)
{
#ifdef G_OS_UNIX
  gboolean ret = FALSE;
  /* This code is modified from that found in
   * polkit/src/polkittextagentlistener.c, reused under the LGPL v2.1
   */
  int res;
  struct termios ts, ots;
  GInputStream *in;
  GOutputStream *out;
  GString *str = NULL;
  gsize bytes_written;
  gboolean reset_terminal = FALSE;

  in = gs_console_get_stdin ();
  out = gs_console_get_stdout ();

  if (!g_output_stream_write_all (out, prompt, strlen (prompt), &bytes_written,
                                  cancellable, error))
    goto out;
  if (!g_output_stream_flush (out, cancellable, error))
    goto out;

  /* TODO: We really ought to block SIGINT and STGSTP (and probably
   *       other signals too) so we can restore the terminal (since we
   *       turn off echoing). See e.g. Advanced Programming in the
   *       UNIX Environment 2nd edition (Steves and Rago) section
   *       18.10, pg 660 where this is suggested. See also various
   *       getpass(3) implementations
   *
   *       However, since we are a library routine the user could have
   *       multiple threads - in fact, typical usage of
   *       PolkitAgentTextListener is to run it in a thread. And
   *       unfortunately threads and POSIX signals is a royal PITA.
   *
   *       Maybe we could fork(2) and ask for the password in the
   *       child and send it back to the parent over a pipe? (we are
   *       guaranteed that there is only one thread in the child
   *       process).
   *
   *       (Side benefit of doing this in a child process is that we
   *       could avoid blocking the thread where the
   *       PolkitAgentTextListener object is being serviced from. But
   *       since this class is normally used in a dedicated thread
   *       it doesn't really matter *anyway*.)
   *
   *       Anyway, On modern Linux not doing this doesn't seem to be a
   *       problem - looks like modern shells restore echoing anyway
   *       on the first input. So maybe it's not even worth solving
   *       the problem.
   */

  do
    res = tcgetattr (1, &ts);
  while (G_UNLIKELY (res == -1 && errno == EINTR));
  if (res == -1)
    {
      gs_set_error_from_errno (error, errno);
      goto out;
    }
  ots = ts;
  ts.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
  do
    res = tcsetattr (1, TCSAFLUSH, &ts);
  while (G_UNLIKELY (res == -1 && errno == EINTR));
  if (res == -1)
    {
      gs_set_error_from_errno (error, errno);
      goto out;
    }

  /* After this point, we'll need to clean up the terminal in case of
   * error.
   */
  reset_terminal = TRUE;

  str = g_string_new (NULL);
  while (TRUE)
    {
      gssize bytes_read;
      guint8 buf[1];

      /* FIXME - we should probably be converting from the system
       * codeset, in case it's not UTF-8.
       */
      bytes_read = g_input_stream_read (in, buf, sizeof (buf),
                                        cancellable, error);
      if (bytes_read < 0)
        goto out;
      else if (bytes_read == 0)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
                       "End of stream while reading password");
          goto out;
        }
      else if (buf[0] == '\n')
        {
          break;
        }
      else
        {
          g_string_append_c (str, buf[0]);
        }
    }

  ret = TRUE;
 out:
  if (reset_terminal)
    {
      do
        res = tcsetattr (1, TCSAFLUSH, &ots);
      while (G_UNLIKELY (res == -1 && errno == EINTR));
      if (res == -1)
        {
          gs_set_error_from_errno (error, errno);
          g_string_free (str, TRUE);
          return NULL;
        }
    }

  if (!ret)
    {
      g_string_free (str, TRUE);
      return NULL;
    }
  else
    {
      return g_string_free (str, FALSE);
    }
#else
  g_error ("not implemented");
#endif
}
示例#27
0
static void
gegl_tile_backend_file_ensure_exist (GeglTileBackendFile *self)
{
  if (!self->exist)
    {
      GeglTileBackend *backend;
#if HAVE_GIO
      GError *error = NULL;

      if (self->io)
        {
          g_print ("we already existed\n");
          return;
        }
#endif
      self->exist = TRUE;

      backend = GEGL_TILE_BACKEND (self);

      GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "creating swapfile  %s", self->path);

#if HAVE_GIO
      self->o = G_OUTPUT_STREAM (g_file_replace (self->file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
      g_output_stream_flush (self->o, NULL, NULL);
      g_output_stream_close (self->o, NULL, NULL);

      self->io = G_IO_STREAM (g_file_open_readwrite (self->file, NULL, &error));
      if (error)
        {
          g_warning ("%s: %s", G_STRLOC, error->message);
          g_error_free (error);
          error = NULL;
        }
      self->o = g_io_stream_get_output_stream (self->io);
      self->i = g_io_stream_get_input_stream (self->io);

#else
      self->o = open (self->path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
#endif

      self->next_pre_alloc = 256;  /* reserved space for header */
      self->total          = 256;  /* reserved space for header */
#if HAVE_GIO
      g_assert(g_seekable_seek (G_SEEKABLE (self->o), 256, G_SEEK_SET, NULL, NULL));
#endif
      gegl_buffer_header_init (&self->header,
                               backend->priv->tile_width,
                               backend->priv->tile_height,
                               backend->priv->px_size,
                               backend->priv->format
                               );
      gegl_tile_backend_file_write_header (self);
#if HAVE_GIO
      g_output_stream_flush (self->o, NULL, NULL);
#else
      fsync (self->o);
      self->i = dup (self->o);
#endif

      /*self->i = G_INPUT_STREAM (g_file_read (self->file, NULL, NULL));*/
      self->next_pre_alloc = 256;  /* reserved space for header */
      self->total          = 256;  /* reserved space for header */
#if HAVE_GIO
      g_assert (self->io);
      g_assert (self->i);
      g_assert (self->o);
#else
      g_assert (self->i != -1);
      g_assert (self->o != -1);
#endif
    }
}
static void
gb_view_source_save (GbView *view)
{
    GbViewSourcePrivate *priv;
    GFileOutputStream *stream;
    GtkTextBuffer *buffer;
    GbViewSource *source = (GbViewSource *)view;
    GCancellable *cancellable = NULL;
    GtkTextIter iter1;
    GtkTextIter iter2;
    const gchar *etag = NULL;
    GtkWidget *widget;
    gboolean make_backup = FALSE;
    GError *error = NULL;
    gchar *text;
    gsize n_written;

    ENTRY;

    g_return_if_fail(GB_IS_VIEW_SOURCE(source));

    priv = source->priv;

    if (!priv->file) {
        GtkDialog *dialog;

        widget = gtk_widget_get_toplevel(GTK_WIDGET(view));
        dialog = g_object_new(GTK_TYPE_FILE_CHOOSER_DIALOG,
                              "action", GTK_FILE_CHOOSER_ACTION_SAVE,
                              "title", _("Save File"),
                              "transient-for", widget,
                              NULL);
        gtk_dialog_add_buttons(dialog,
                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                               GTK_STOCK_SAVE, GTK_RESPONSE_OK,
                               NULL);
        if (gtk_dialog_run(dialog) != GTK_RESPONSE_OK) {
            gtk_widget_destroy(GTK_WIDGET(dialog));
            EXIT;
        }
        priv->file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));
        gtk_widget_destroy(GTK_WIDGET(dialog));
    }

    g_signal_emit(source, gSignals[PRE_SAVE], 0);

    g_object_set(priv->progress,
                 "fraction", 0.0,
                 "visible", TRUE,
                 NULL);
    gb_object_animate_full(priv->progress,
                           GB_ANIMATION_EASE_IN_OUT_QUAD,
                           500,
                           60,
                           save_animation_done,
                           g_object_ref(priv->progress),
                           "fraction", 1.0,
                           NULL);

    buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(priv->source1));

    /*
     * TODO: Do this all async.
     */

    if (!(stream = g_file_replace(priv->file, etag, make_backup,
                                  G_FILE_CREATE_NONE,
                                  cancellable, &error))) {
        g_printerr("%s\n", error->message);
        g_error_free(error);
        EXIT;
    }

    gtk_text_buffer_get_start_iter(buffer, &iter1);
    gtk_text_buffer_get_end_iter(buffer, &iter2);
    text = gtk_text_buffer_get_text(buffer, &iter1, &iter2, TRUE);

    if (!g_output_stream_write_all(G_OUTPUT_STREAM(stream), text, strlen(text),
                                   &n_written, cancellable, &error)) {
        g_printerr("%s\n", error->message);
        g_error_free(error);
    } else {
        g_output_stream_flush(G_OUTPUT_STREAM(stream), NULL, NULL);
        if (!g_output_stream_close(G_OUTPUT_STREAM(stream), cancellable,
                                   &error)) {
            g_printerr("%s\n", error->message);
            g_error_free(error);
        } else {
            gb_view_set_can_save(view, FALSE);
        }
    }

    gtk_text_buffer_set_modified(buffer, FALSE);

    g_object_unref(stream);
    g_free(text);

    gb_view_source_set_file_attribs(source, priv->file);

    EXIT;
}
示例#29
0
static gboolean
checkout_object_for_uncompressed_cache (OstreeRepo      *self,
                                        const char      *loose_path,
                                        GFileInfo       *src_info,
                                        GInputStream    *content,
                                        GCancellable    *cancellable,
                                        GError         **error)
{
  gboolean ret = FALSE;
  g_autofree char *temp_filename = NULL;
  g_autoptr(GOutputStream) temp_out = NULL;
  glnx_fd_close int fd = -1;
  int res;
  guint32 file_mode;

  /* Don't make setuid files in uncompressed cache */
  file_mode = g_file_info_get_attribute_uint32 (src_info, "unix::mode");
  file_mode &= ~(S_ISUID|S_ISGID);

  if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY | O_CLOEXEC,
                                      &fd, &temp_filename,
                                      error))
    goto out;
  temp_out = g_unix_output_stream_new (fd, FALSE);

  if (g_output_stream_splice (temp_out, content, 0, cancellable, error) < 0)
    goto out;

  if (!g_output_stream_flush (temp_out, cancellable, error))
    goto out;

  if (!self->disable_fsync)
    {
      do
        res = fsync (fd);
      while (G_UNLIKELY (res == -1 && errno == EINTR));
      if (G_UNLIKELY (res == -1))
        {
          glnx_set_error_from_errno (error);
          goto out;
        }
    }

  if (!g_output_stream_close (temp_out, cancellable, error))
    goto out;

  if (fchmod (fd, file_mode) < 0)
    {
      glnx_set_error_from_errno (error);
      goto out;
    }

  if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd,
                                            loose_path,
                                            cancellable, error))
    goto out;

  if (!glnx_link_tmpfile_at (self->tmp_dir_fd, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
                             fd, temp_filename,
                             self->uncompressed_objects_dir_fd, loose_path,
                             error))
    goto out;

  ret = TRUE;
 out:
  return ret;
}
示例#30
0
文件: skkserv.c 项目: pkg-ime/libskk
static void skk_skk_serv_real_reload (SkkDict* base, GError** error) {
	SkkSkkServ * self;
	GError * _inner_error_ = NULL;
	self = (SkkSkkServ*) base;
	skk_skk_serv_close_connection (self);
	{
		GSocketClient* _tmp0_;
		GSocketClient* client;
		GSocketClient* _tmp1_;
		const gchar* _tmp2_;
		guint16 _tmp3_;
		GSocketConnection* _tmp4_ = NULL;
		GSocketConnection* _tmp5_;
		GSocketConnection* _tmp6_;
		guint8 _tmp7_;
		gsize bytes_written = 0UL;
		GSocketConnection* _tmp8_;
		GOutputStream* _tmp9_;
		GOutputStream* _tmp10_;
		gsize _tmp11_ = 0UL;
		GSocketConnection* _tmp12_;
		GOutputStream* _tmp13_;
		GOutputStream* _tmp14_;
		GSocketConnection* _tmp15_;
		GInputStream* _tmp16_;
		GInputStream* _tmp17_;
		gssize _tmp18_ = 0L;
		gssize len;
		gssize _tmp19_;
		_tmp0_ = g_socket_client_new ();
		client = _tmp0_;
		_tmp1_ = client;
		_tmp2_ = self->priv->host;
		_tmp3_ = self->priv->port;
		_tmp4_ = g_socket_client_connect_to_host (_tmp1_, _tmp2_, _tmp3_, NULL, &_inner_error_);
		_tmp5_ = _tmp4_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (client);
			goto __catch17_g_error;
		}
		_tmp6_ = _g_object_ref0 (_tmp5_);
		_g_object_unref0 (self->priv->connection);
		self->priv->connection = _tmp6_;
		self->priv->buffer[0] = (guint8) '2';
		_tmp7_ = self->priv->buffer[0];
		_tmp8_ = self->priv->connection;
		_tmp9_ = g_io_stream_get_output_stream ((GIOStream*) _tmp8_);
		_tmp10_ = _tmp9_;
		g_output_stream_write_all (_tmp10_, self->priv->buffer + 0, (gsize) (1 - 0), &_tmp11_, NULL, &_inner_error_);
		bytes_written = _tmp11_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (client);
			goto __catch17_g_error;
		}
		_tmp12_ = self->priv->connection;
		_tmp13_ = g_io_stream_get_output_stream ((GIOStream*) _tmp12_);
		_tmp14_ = _tmp13_;
		g_output_stream_flush (_tmp14_, NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (client);
			goto __catch17_g_error;
		}
		_tmp15_ = self->priv->connection;
		_tmp16_ = g_io_stream_get_input_stream ((GIOStream*) _tmp15_);
		_tmp17_ = _tmp16_;
		_tmp18_ = g_input_stream_read (_tmp17_, self->priv->buffer, (gsize) 4096, NULL, &_inner_error_);
		len = _tmp18_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (client);
			goto __catch17_g_error;
		}
		_tmp19_ = len;
		if (_tmp19_ <= ((gssize) 0)) {
			skk_skk_serv_close_connection (self);
		}
		_g_object_unref0 (client);
	}
	goto __finally17;
	__catch17_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp20_;
		guint16 _tmp21_;
		GError* _tmp22_;
		const gchar* _tmp23_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp20_ = self->priv->host;
		_tmp21_ = self->priv->port;
		_tmp22_ = e;
		_tmp23_ = _tmp22_->message;
		g_warning ("skkserv.vala:67: can't open skkserv at %s:%u: %s", _tmp20_, (guint) _tmp21_, _tmp23_);
		skk_skk_serv_close_connection (self);
		_g_error_free0 (e);
	}
	__finally17:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}