コード例 #1
0
ファイル: simple-proxy.c プロジェクト: Distrotech/libsoup
static void
tunnel_connected_cb (GObject      *object,
		     GAsyncResult *result,
		     gpointer      user_data)
{
	Tunnel *tunnel = user_data;
	GError *error = NULL;

	tunnel->server.iostream = (GIOStream *)
		g_socket_client_connect_to_host_finish (G_SOCKET_CLIENT (object), result, &error);
	if (!tunnel->server.iostream) {
		soup_message_set_status (tunnel->msg, SOUP_STATUS_BAD_GATEWAY);
		soup_message_set_response (tunnel->msg, "text/plain",
					   SOUP_MEMORY_COPY,
					   error->message, strlen (error->message));
		g_error_free (error);
		soup_server_unpause_message (tunnel->self, tunnel->msg);
		tunnel_close (tunnel);
		return;
	}

	tunnel->server.istream = g_io_stream_get_input_stream (tunnel->server.iostream);
	tunnel->server.ostream = g_io_stream_get_output_stream (tunnel->server.iostream);

	soup_message_set_status (tunnel->msg, SOUP_STATUS_OK);
	soup_server_unpause_message (tunnel->self, tunnel->msg);
	g_signal_connect (tunnel->msg, "finished",
			  G_CALLBACK (start_tunnel), tunnel);
}
コード例 #2
0
ファイル: giostream.c プロジェクト: BreakawayConsulting/glib
static void
g_io_stream_get_property (GObject    *object,
			  guint       prop_id,
			  GValue     *value,
			  GParamSpec *pspec)
{
  GIOStream *stream = G_IO_STREAM (object);

  switch (prop_id)
    {
      case PROP_CLOSED:
        g_value_set_boolean (value, stream->priv->closed);
        break;

      case PROP_INPUT_STREAM:
        g_value_set_object (value, g_io_stream_get_input_stream (stream));
        break;

      case PROP_OUTPUT_STREAM:
        g_value_set_object (value, g_io_stream_get_output_stream (stream));
        break;

      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}
コード例 #3
0
void lllp_connected_cb(GObject *listener, GAsyncResult *res, gpointer pstore_library) {
	GtkListStore *store_library = GTK_LIST_STORE(pstore_library);
	GSocketConnection *connection;
	GSocketAddress *address;
	gchar *address_char;
	GInputStream *stream;
	GFile *output_file;
	GOutputStream *file_stream;
	gsize count;
	gboolean valid = FALSE;


	connection = g_socket_listener_accept_finish(G_SOCKET_LISTENER(listener), res, NULL, NULL);
	address = g_socket_connection_get_remote_address(connection, NULL);
	address_char = g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address)));
	printf("%s\n", address_char);

	output_file = g_file_new_for_path(address_char);
	g_file_delete(output_file, NULL, NULL);
	file_stream = (GOutputStream*)g_file_replace(output_file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL);

	stream = g_io_stream_get_input_stream(G_IO_STREAM(connection));
	g_output_stream_splice(file_stream, stream, 
		G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE & G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, NULL);
	g_output_stream_close(file_stream, NULL, NULL);

	convert_library_to_list_store(store_library, address_char);

	printf("%s CONNECTED\n", address_char);

	g_socket_listener_accept_async(G_SOCKET_LISTENER(listener), NULL, lllp_connected_cb, store_library);
}
コード例 #4
0
ファイル: cockpitwebserver.c プロジェクト: briceburg/cockpit
static void
start_request_input (CockpitRequest *request)
{
  GPollableInputStream *poll_in;
  GInputStream *in;

  /* Both GSocketConnection and GTlsServerConnection are pollable */
  in = g_io_stream_get_input_stream (request->io);
  poll_in = NULL;
  if (G_IS_POLLABLE_INPUT_STREAM (in))
    poll_in = (GPollableInputStream *)in;

  if (!poll_in || !g_pollable_input_stream_can_poll (poll_in))
    {
      g_critical ("cannot use a non-pollable input stream: %s", G_OBJECT_TYPE_NAME (in));
      cockpit_request_finish (request);
      return;
    }

  /* Replace with a new source */
  if (request->source)
    {
      g_source_destroy (request->source);
      g_source_unref (request->source);
    }

  request->source = g_pollable_input_stream_create_source (poll_in, NULL);
  g_source_set_callback (request->source, (GSourceFunc)on_request_input, request, NULL);
  g_source_attach (request->source, request->web_server->main_context);
}
コード例 #5
0
/* Class Implementation */
static void
kixmail_io_stream_set_property (GObject *object,
                                guint prop_id,
                                const GValue *value,
                                GParamSpec *pspec)
{
  KixmailIOStream *iostream = KIXMAIL_IO_STREAM (object);
  GIOStream *io;

  switch (prop_id) {
	case PROP_BASE_IOSTREAM:
		io = iostream->priv->base_iostream = g_value_dup_object (value);
		if (io) {
			iostream->priv->istream =
				kixmail_filter_input_stream_new (g_io_stream_get_input_stream (io));
			iostream->priv->ostream =
				g_object_ref (g_io_stream_get_output_stream (io));
		} else {
			g_clear_object (&iostream->priv->istream);
			g_clear_object (&iostream->priv->ostream);
		}
		break;
	case PROP_CLOSE_ON_DISPOSE:
		iostream->priv->close_on_dispose = g_value_get_boolean (value);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
  }
}
コード例 #6
0
FusionTLSInputStream* fusion_tls_input_stream_construct (GType object_type, FusionTLSConnection* connection) {
	FusionTLSInputStream * self = NULL;
	FusionTLSConnection* _tmp0_ = NULL;
	GSocketConnection* _tmp1_ = NULL;
	GSocketConnection* _tmp2_ = NULL;
	GInputStream* _tmp3_ = NULL;
	FusionTLSConnection* _tmp4_ = NULL;
	FusionTLSConnection* _tmp5_ = NULL;
	FusionTLSConnection* _tmp6_ = NULL;
	GSocketConnection* _tmp7_ = NULL;
	GSocketConnection* _tmp8_ = NULL;
	GSocket* _tmp9_ = NULL;
	GSocket* _tmp10_ = NULL;
	g_return_val_if_fail (connection != NULL, NULL);
	_tmp0_ = connection;
	_tmp1_ = fusion_tls_connection_get_socket_connection (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_io_stream_get_input_stream ((GIOStream*) _tmp2_);
	self = (FusionTLSInputStream*) g_object_new (object_type, "base-stream", _tmp3_, NULL);
	_tmp4_ = connection;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_g_object_unref0 (self->priv->connection);
	self->priv->connection = _tmp5_;
	_tmp6_ = connection;
	_tmp7_ = fusion_tls_connection_get_socket_connection (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_socket_connection_get_socket (_tmp8_);
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_g_object_unref0 (self->priv->socket);
	self->priv->socket = _tmp10_;
	return self;
}
コード例 #7
0
ファイル: cockpitstream.c プロジェクト: firebitsbr/cockpit
static void
initialize_io (CockpitStream *self)
{
  GInputStream *is;
  GOutputStream *os;

  g_return_if_fail (self->priv->in_source == NULL);

  is = g_io_stream_get_input_stream (self->priv->io);
  os = g_io_stream_get_output_stream (self->priv->io);

  if (!G_IS_POLLABLE_INPUT_STREAM (is) ||
      !g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (is)) ||
      !G_IS_POLLABLE_OUTPUT_STREAM (os) ||
      !g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (os)))
    {
      g_warning ("%s: stream is not pollable", self->priv->name);
      close_immediately (self, "internal-error");
      return;
    }

  if (self->priv->connecting)
    {
      g_object_unref (self->priv->connecting);
      self->priv->connecting = NULL;
    }

  self->priv->in_source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (is), NULL);
  g_source_set_name (self->priv->in_source, "stream-input");
  g_source_set_callback (self->priv->in_source, (GSourceFunc)dispatch_input, self, NULL);
  g_source_attach (self->priv->in_source, self->priv->context);

  start_output (self);
}
コード例 #8
0
ファイル: gspeechd-client.c プロジェクト: razr/gspeechd
GSpeechdClient *
gspeechd_client_new (GSocketConnection *connection)
{
	GSpeechdClient *client;
	GOutputStream *output_stream;
	GInputStream *input_stream;

	client = g_slice_new0 (GSpeechdClient);
	client->ref_count = 1;
	client->cancellable = g_cancellable_new ();
	client->connection = g_object_ref (connection);
	client->failed = FALSE;

	/*
	 * Start listening for the message
	 */
	input_stream = g_io_stream_get_input_stream(G_IO_STREAM(connection));
	client->input = g_data_input_stream_new (input_stream);

	g_data_input_stream_read_line_async(client->input,
							G_PRIORITY_DEFAULT,
							client->cancellable,
							(GAsyncReadyCallback)gspeechd_client_read_line_cb,
							gspeechd_client_ref (client));

	output_stream = g_io_stream_get_output_stream (G_IO_STREAM(connection));
	client->output = g_data_output_stream_new (output_stream);

	return (client);
}
コード例 #9
0
static void sendIncompleteRequest(InspectorServerTest* test, gconstpointer)
{
    GOwnPtr<GError> error;

    // Connect to the inspector server.
    GRefPtr<GSocketClient> client = adoptGRef(g_socket_client_new());
    GRefPtr<GSocketConnection> connection = adoptGRef(g_socket_client_connect_to_host(client.get(), "127.0.0.1", 2999, 0, &error.outPtr()));
    g_assert_no_error(error.get());

    // Send incomplete request (missing blank line after headers) and check if inspector server
    // replies. The server should not reply to an incomplete request and the test should timeout
    // on read.
    GOutputStream* ostream = g_io_stream_get_output_stream(G_IO_STREAM(connection.get()));
    // Request missing blank line after headers.
    const gchar* incompleteRequest = "GET /devtools/page/1 HTTP/1.1\r\nHost: Localhost\r\n";
    g_output_stream_write(ostream, incompleteRequest, strlen(incompleteRequest), 0, &error.outPtr());
    g_assert_no_error(error.get());

    GInputStream* istream = g_io_stream_get_input_stream(G_IO_STREAM(connection.get()));
    char response[16];
    memset(response, 0, sizeof(response));
    GRefPtr<GCancellable> cancel = adoptGRef(g_cancellable_new());
    g_input_stream_read_async(istream, response, sizeof(response) - 1, G_PRIORITY_DEFAULT, cancel.get(), 0, 0);
    // Give a chance for the server to reply.
    test->wait(1);
    g_cancellable_cancel(cancel.get());
    // If we got any answer it means the server replied to an incomplete request, lets fail.
    g_assert(response[0] == '\0');
}
コード例 #10
0
ファイル: gvfsftpconnection.c プロジェクト: BATYakhkhkh/gvfs
GVfsFtpConnection *
g_vfs_ftp_connection_new (GSocketConnectable *addr,
                          GCancellable *      cancellable,
                          GError **           error)
{
  GVfsFtpConnection *conn;

  g_return_val_if_fail (G_IS_SOCKET_CONNECTABLE (addr), NULL);

  conn = g_slice_new0 (GVfsFtpConnection);
  conn->client = g_socket_client_new ();
  conn->debug_id = g_atomic_int_exchange_and_add (&debug_id, 1);
  conn->commands = G_IO_STREAM (g_socket_client_connect (conn->client,
                                                         addr,
                                                         cancellable,
                                                         error));
  if (conn->commands == NULL)
    {
      g_object_unref (conn->client);
      g_slice_free (GVfsFtpConnection, conn);
      return NULL;
    }

  enable_keepalive (G_SOCKET_CONNECTION (conn->commands));
  conn->commands_in = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (conn->commands)));
  g_data_input_stream_set_newline_type (conn->commands_in, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
  /* The first thing that needs to happen is receiving the welcome message */
  conn->waiting_for_reply = TRUE;

  return conn;
}
コード例 #11
0
ファイル: connections.c プロジェクト: AdKwiatkos/ekg2
static void done_async_connect(GObject *obj, GAsyncResult *res, gpointer user_data) {
	GSocketClient *sock = G_SOCKET_CLIENT(obj);
	struct ekg_connection_starter *cs = user_data;
	GSocketConnection *conn;
	GError *err = NULL;
	
	conn = g_socket_client_connect_finish(sock, res, &err);
	if (conn) {
#ifdef HAVE_LIBGNUTLS
		if (cs->use_tls) {
			ekg_gnutls_new_session(sock, conn, cs);
		} else
#endif
		{
			GIOStream *cio = G_IO_STREAM(conn);
			succeeded_async_connect(
					sock, conn, cs,
					g_io_stream_get_input_stream(cio),
					g_io_stream_get_output_stream(cio));
		}
	} else {
		failed_async_connect(sock, err, cs);
		g_error_free(err);
	}
}
コード例 #12
0
ファイル: hotssh-tab.c プロジェクト: GNOME/hotssh
static void
on_open_shell_complete (GObject           *src,
			GAsyncResult      *res,
			gpointer           user_data)
{
  HotSshTab *self = user_data;
  HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
  GError *local_error = NULL;
  GInputStream *istream;

  g_debug ("open shell complete");

  priv->channel = gssh_connection_open_shell_finish ((GSshConnection*)src,
						       res, &local_error);
  if (!priv->channel)
    goto out;

  page_transition (self, HOTSSH_TAB_PAGE_TERMINAL);

  istream = g_io_stream_get_input_stream ((GIOStream*)priv->channel);

  g_input_stream_read_bytes_async (istream, 8192, G_PRIORITY_DEFAULT,
				   priv->cancellable, on_istream_read_complete, self);
  
 out:
  if (local_error)
    page_transition_take_error (self, local_error);
}
コード例 #13
0
ファイル: gdkclipboard.c プロジェクト: GNOME/gtk
static void
gdk_clipboard_read_local_async (GdkClipboard        *clipboard,
                                GdkContentFormats   *formats,
                                int                  io_priority,
                                GCancellable        *cancellable,
                                GAsyncReadyCallback  callback,
                                gpointer             user_data)
{
  GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
  GdkContentFormats *content_formats;
  const char *mime_type;
  GTask *task;

  task = g_task_new (clipboard, cancellable, callback, user_data);
  g_task_set_priority (task, io_priority);
  g_task_set_source_tag (task, gdk_clipboard_read_local_async);

  if (priv->content == NULL)
    {
      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                                     _("Cannot read from empty clipboard."));
      g_object_unref (task);
      return;
    }

  content_formats = gdk_content_provider_ref_formats (priv->content);
  content_formats = gdk_content_formats_union_serialize_mime_types (content_formats);
  mime_type = gdk_content_formats_match_mime_type (content_formats, formats);

  if (mime_type != NULL)
    {
      GOutputStream *output_stream;
      GIOStream *stream;
      
      stream = gdk_pipe_io_stream_new ();
      output_stream = g_io_stream_get_output_stream (stream);
      gdk_clipboard_write_async (clipboard,
                                 mime_type,
                                 output_stream,
                                 io_priority,
                                 cancellable,
                                 gdk_clipboard_read_local_write_done,
                                 g_object_ref (output_stream));
      g_task_set_task_data (task, (gpointer) mime_type, NULL);
      g_task_return_pointer (task, g_object_ref (g_io_stream_get_input_stream (stream)), g_object_unref);

      g_object_unref (stream);
    }
  else
    {
      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                                     _("No compatible formats to transfer clipboard contents."));
    }

  gdk_content_formats_unref (content_formats);
  g_object_unref (task);
}
コード例 #14
0
ファイル: io.c プロジェクト: SteveJones/j4status
static void
_j4status_io_stream_set_connection(J4statusIOStream *self, GSocketConnection *connection)
{
    self->connection = connection;
    self->out = g_data_output_stream_new(g_io_stream_get_output_stream(G_IO_STREAM(self->connection)));
    self->in = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(self->connection)));
    if ( ! self->header_sent )
        _j4status_io_stream_put_header(self, self->io->header);
    g_data_input_stream_read_line_async(self->in, G_PRIORITY_DEFAULT, NULL, _j4status_io_stream_read_callback, self);
}
コード例 #15
0
ファイル: vdagent.c プロジェクト: elmarco/vdagent-gtk
static void
read_new_message(SpiceVDAgent *agent)
{
    input_stream_read_all_async(g_io_stream_get_input_stream(agent->connection),
                                &agent->header, sizeof(agent->header),
                                G_PRIORITY_DEFAULT,
                                agent->cancellable,
                                message_header_cb,
                                agent);
}
コード例 #16
0
ファイル: gvfsftpdircache.c プロジェクト: BATYakhkhkh/gvfs
static GVfsFtpDirCacheEntry *
g_vfs_ftp_dir_cache_lookup_entry (GVfsFtpDirCache *  cache,
                                  GVfsFtpTask *      task,
                                  const GVfsFtpFile *dir,
                                  guint              stamp)
{
  GVfsFtpDirCacheEntry *entry;

  g_mutex_lock (cache->lock);
  entry = g_hash_table_lookup (cache->directories, dir);
  if (entry)
    g_vfs_ftp_dir_cache_entry_ref (entry);
  g_mutex_unlock (cache->lock);
  if (entry && entry->stamp < stamp)
    g_vfs_ftp_dir_cache_entry_unref (entry);
  else if (entry)
    return entry;

  if (g_vfs_ftp_task_send (task,
        	           G_VFS_FTP_PASS_550,
        		   "CWD %s", g_vfs_ftp_file_get_ftp_path (dir)) == 550)
    {
      g_set_error_literal (&task->error,
        	           G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY,
        		   _("The file is not a directory"));
    }
  g_vfs_ftp_task_setup_data_connection (task);
  g_vfs_ftp_task_send (task,
        	       G_VFS_FTP_PASS_100 | G_VFS_FTP_FAIL_200,
                       "%s", cache->funcs->command);
  g_vfs_ftp_task_open_data_connection (task);
  if (g_vfs_ftp_task_is_in_error (task))
    return NULL;

  entry = g_vfs_ftp_dir_cache_entry_new (stamp);
  cache->funcs->process (g_io_stream_get_input_stream (g_vfs_ftp_connection_get_data_stream (task->conn)),
                         g_vfs_ftp_connection_get_debug_id (task->conn),
                         dir,
                         entry,
                         task->cancellable,
                         &task->error);
  g_vfs_ftp_task_close_data_connection (task);
  g_vfs_ftp_task_receive (task, 0, NULL);
  if (g_vfs_ftp_task_is_in_error (task))
    {
      g_vfs_ftp_dir_cache_entry_unref (entry);
      return NULL;
    }
  g_mutex_lock (cache->lock);
  g_hash_table_insert (cache->directories,
                       g_vfs_ftp_file_copy (dir),
                       g_vfs_ftp_dir_cache_entry_ref (entry));
  g_mutex_unlock (cache->lock);
  return entry;
}
コード例 #17
0
ファイル: arvfb.c プロジェクト: uincore/OpenSAR
// poll if there is a message on port needed to be transmitted or processed.
// port: see localhost:port, socket
// pMsg: both input ArMsg and output ArMsg
boolean ArvfbPoll(ArPortType port,ArMsgType* pMsg)
{
	boolean rv= FALSE;
	GError * error = NULL;

	uint32 command = pMsg->Command;

	/* create a new connection */
	GSocketConnection * connection = NULL;
	GSocketClient * client = g_socket_client_new();

	/* connect to the host */
	connection = g_socket_client_connect_to_host (client,
										   (gchar*)"localhost",
										    port, /* your port goes here */
											NULL,
											&error);

	/* don't forget to check for errors */
	if (error != NULL)
	{
		g_print("SERVER: <%s>!\n",error->message);
		g_object_unref(client);
		return FALSE;
	}

	/* use the connection */
	GOutputStream * ostream = g_io_stream_get_output_stream (G_IO_STREAM (connection));
	g_output_stream_write  (ostream,
						  pMsg,
						  pMsg->Length+MSG_MIN_LENGTH,
						  NULL,
						  &error);
	GInputStream * istream = g_io_stream_get_input_stream (G_IO_STREAM (connection));
	gssize size = g_input_stream_read(istream,pMsg,sizeof(ArMsgType),NULL,&error);
	if( (size > MSG_MIN_LENGTH) &&
		((MSG_MIN_LENGTH+pMsg->Length)==size) &&
		((command|MSG_CMD_ACK) == pMsg->Command) )
	{
		rv = TRUE;
	}
	else
	{   // <= MSG_MIN_LENGTH, default nothing has been gotten on the port
		rv = FALSE;
	}
	/* don't forget to check for errors */
	if (error != NULL)
	{
		g_print("SERVER: <%s>!\n",error->message);
	}
	g_object_unref(connection);
	g_object_unref(client);
	return rv;
}
コード例 #18
0
ファイル: FileSystemGlib.cpp プロジェクト: caiolima/webkit
int readFromFile(PlatformFileHandle handle, char* data, int length)
{
    GUniqueOutPtr<GError> error;
    do {
        gssize bytesRead = g_input_stream_read(g_io_stream_get_input_stream(G_IO_STREAM(handle)),
            data, length, 0, &error.outPtr());
        if (bytesRead >= 0)
            return bytesRead;
    } while (error && error->code == G_FILE_ERROR_INTR);
    return -1;
}
コード例 #19
0
ファイル: interface.c プロジェクト: fossology/fossology
/**
 * Given a new socket, this will create the interface connection structure.
 *
 * @param conn    The socket that this interface is connected to
 * @param threads Thread pool handling sockets
 * @return the newly allocated and populated interface connection
 */
static interface_connection* interface_conn_init(
    GSocketConnection* conn, GThreadPool* threads)
{
  interface_connection* inter = g_new0(interface_connection, 1);

  inter->conn = conn;
  inter->istr = g_io_stream_get_input_stream((GIOStream*)inter->conn);
  inter->ostr = g_io_stream_get_output_stream((GIOStream*)inter->conn);
  g_thread_pool_push(threads, inter, NULL);

  return inter;
}
コード例 #20
0
ファイル: gvfsafpconnection.c プロジェクト: Amerekanets/gvfs
static void
read_reply (GVfsAfpConnection *afp_connection)
{
  GVfsAfpConnectionPrivate *priv = afp_connection->priv;
  
  GInputStream *input;

  input = g_io_stream_get_input_stream (priv->conn);
  
  read_all_async (input, &priv->read_dsi_header, sizeof (DSIHeader), 0, NULL,
                  read_dsi_header_cb, afp_connection);
}
コード例 #21
0
ファイル: gvfsftpconnection.c プロジェクト: gicmo/gvfs
static void
create_input_stream (GVfsFtpConnection *conn)
{
  if (conn->commands_in)
    {
      g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (conn->commands_in), FALSE);
      g_object_unref (conn->commands_in);
    }

  conn->commands_in = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (conn->commands)));
  g_data_input_stream_set_newline_type (conn->commands_in, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
}
コード例 #22
0
ファイル: gsocks4aproxy.c プロジェクト: 183amir/glib
static void
do_read (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data)
{
   GInputStream *in;
   in = g_io_stream_get_input_stream (data->io_stream);
   g_input_stream_read_async (in,
			      data->buffer + data->offset,
			      data->length - data->offset,
			      g_task_get_priority (task),
			      g_task_get_cancellable (task),
			      callback, task);
}
コード例 #23
0
ファイル: gsocks4aproxy.c プロジェクト: 183amir/glib
static GIOStream *
g_socks4a_proxy_connect (GProxy            *proxy,
			 GIOStream         *io_stream,
			 GProxyAddress     *proxy_address,
			 GCancellable      *cancellable,
			 GError           **error)
{
  GInputStream *in;
  GOutputStream *out;
  const gchar *hostname;
  guint16 port;
  const gchar *username;

  hostname = g_proxy_address_get_destination_hostname (proxy_address);
  port = g_proxy_address_get_destination_port (proxy_address);
  username = g_proxy_address_get_username (proxy_address);

  in = g_io_stream_get_input_stream (io_stream);
  out = g_io_stream_get_output_stream (io_stream);

  /* Send SOCKS4 connection request */
    {
      guint8 msg[SOCKS4_CONN_MSG_LEN];
      gint len;
      
      len = set_connect_msg (msg, hostname, port, username, error);

      if (len < 0)
	goto error;

      if (!g_output_stream_write_all (out, msg, len, NULL,
				      cancellable, error))
	goto error;
    }

  /* Read SOCKS4 response */
    {
      guint8 data[SOCKS4_CONN_REP_LEN];

      if (!g_input_stream_read_all (in, data, SOCKS4_CONN_REP_LEN, NULL,
				    cancellable, error))
	goto error;

      if (!parse_connect_reply (data, error))
	goto error;
    }

  return g_object_ref (io_stream);

error:
  return NULL;
}
コード例 #24
0
ファイル: pn_node.c プロジェクト: felipec/msn-pecan
static void
connect_cb(GObject *source,
           GAsyncResult *res,
           gpointer user_data)
{
    GSocketConnection *socket_conn;
    PnNode *conn;
    GError *error = NULL;

    conn = PN_NODE(user_data);
    socket_conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), res, &error);

    g_object_unref(source);

    if (error) {
        g_error_free(error);
        return;
    }

    g_object_ref(conn);

    if (socket_conn) {
        GSocket *socket;
        GInputStream *input;

        conn->socket_conn = socket_conn;
        socket = g_socket_connection_get_socket(socket_conn);

        conn->status = PN_NODE_STATUS_OPEN;

        input = g_io_stream_get_input_stream (G_IO_STREAM (conn->socket_conn));
        g_object_ref (conn);
        g_input_stream_read_async (input, conn->input_buffer, PN_BUF_LEN,
                                   G_PRIORITY_DEFAULT, NULL,
                                   read_cb, conn);
    }
    else {
        conn->error = g_error_new_literal(PN_NODE_ERROR, PN_NODE_ERROR_OPEN,
                                          "Unable to connect");

        pn_node_error(conn);
    }

    {
        PnNodeClass *class;
        class = g_type_class_peek(PN_NODE_TYPE);
        g_signal_emit(G_OBJECT(conn), class->open_sig, 0, conn);
    }

    g_object_unref(conn);
}
コード例 #25
0
void SocketStreamHandle::connected(GRefPtr<GSocketConnection>&& socketConnection)
{
    m_socketConnection = WTFMove(socketConnection);
    m_outputStream = G_POLLABLE_OUTPUT_STREAM(g_io_stream_get_output_stream(G_IO_STREAM(m_socketConnection.get())));
    m_inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_socketConnection.get()));
    m_readBuffer = std::make_unique<char[]>(READ_BUFFER_SIZE);

    RefPtr<SocketStreamHandle> protectedThis(this);
    g_input_stream_read_async(m_inputStream.get(), m_readBuffer.get(), READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, m_cancellable.get(),
        reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), protectedThis.leakRef());

    m_state = Open;
    m_client.didOpenSocketStream(*this);
}
コード例 #26
0
static void
test_io_stream_properties (NiceAddress *addr)
{
  NiceAgent *agent;
  guint stream_id;
  GIOStream *io_stream;
  GInputStream *input_stream;
  GOutputStream *output_stream;

  agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
  nice_agent_add_local_address (agent, addr);

  stream_id = nice_agent_add_stream (agent, 1);

  /* Try building an I/O stream around it. */
  io_stream = nice_agent_get_io_stream (agent, stream_id, 1);
  g_assert (G_IS_IO_STREAM (io_stream));
  g_assert (NICE_IS_IO_STREAM (io_stream));

  /* Check various initial properties. */
  g_assert (!g_io_stream_is_closed (G_IO_STREAM (io_stream)));
  g_assert (!g_io_stream_has_pending (G_IO_STREAM (io_stream)));

  /* Check the input stream’s properties. */
  input_stream = g_io_stream_get_input_stream (G_IO_STREAM (io_stream));
  g_assert (G_IS_INPUT_STREAM (input_stream));
  g_assert (NICE_IS_INPUT_STREAM (input_stream));

  g_assert (!g_input_stream_is_closed (input_stream));
  g_assert (!g_input_stream_has_pending (input_stream));

  /* Check the output stream’s properties. */
  output_stream = g_io_stream_get_output_stream (G_IO_STREAM (io_stream));
  g_assert (G_IS_OUTPUT_STREAM (output_stream));
  g_assert (NICE_IS_OUTPUT_STREAM (output_stream));

  g_assert (!g_output_stream_is_closing (output_stream));
  g_assert (!g_output_stream_is_closed (output_stream));
  g_assert (!g_output_stream_has_pending (output_stream));

  /* Remove the component and check that the I/O streams close. */
  nice_agent_remove_stream (agent, stream_id);

  g_assert (g_io_stream_is_closed (G_IO_STREAM (io_stream)));
  g_assert (g_input_stream_is_closed (input_stream));
  g_assert (g_output_stream_is_closed (output_stream));

  g_object_unref (io_stream);
  g_object_unref (agent);
}
コード例 #27
0
/* command socket callback */
gboolean socket_callback(GSocketService * service, GSocketConnection * conn,
                         GObject * source_object, gpointer user_data)
{
    video_server_t * server = (video_server_t *)user_data;
    gchar            message[128];
    guint64          value;

    GInputStream * istream = g_io_stream_get_input_stream(G_IO_STREAM(conn));

    g_input_stream_read(istream, message, 128, NULL, NULL);

    /* Supported commands:
     *
     *   "b 5000"     set bitrate to 5 Mbps
     *   "i 3000"     set I-frame interval in msec
     *   "f 30"       set framerate in frames/sec
     *   "s 640x360"  set frame size
     */
    gchar **cmd_str = g_strsplit(message, " ", 0);
    if (g_strv_length(cmd_str) != 2)
    {
        fprintf(stderr, "Incorrect command syntax: %s", message);
        return FALSE;
    }

    switch (cmd_str[0][0])
    {
    case 'b':
        value = g_ascii_strtoull(cmd_str[1], NULL, 0);
        video_server_set_bitrate(server, (unsigned int) value);
        break;
    case 'i':
        value = g_ascii_strtoull(cmd_str[1], NULL, 0);
        video_server_set_iframe_period(server, (unsigned int) value);
        break;
    case 'f':
        value = g_ascii_strtoull(cmd_str[1], NULL, 0);
        video_server_set_framerate(server, (unsigned int) value);
        break;
    case 's':
        get_frame_size(cmd_str[1], server->conf);
        video_server_reset_frame_size(server);
        break;
    }

    g_strfreev(cmd_str);

    return FALSE;
}
コード例 #28
0
ファイル: FileSystemGlib.cpp プロジェクト: caiolima/webkit
long long seekFile(PlatformFileHandle handle, long long offset, FileSeekOrigin origin)
{
    GSeekType seekType = G_SEEK_SET;
    switch (origin) {
    case SeekFromBeginning:
        seekType = G_SEEK_SET;
        break;
    case SeekFromCurrent:
        seekType = G_SEEK_CUR;
        break;
    case SeekFromEnd:
        seekType = G_SEEK_END;
        break;
    default:
        ASSERT_NOT_REACHED();
    }

    if (!g_seekable_seek(G_SEEKABLE(g_io_stream_get_input_stream(G_IO_STREAM(handle))),
        offset, seekType, 0, 0))
    {
        return -1;
    }
    return g_seekable_tell(G_SEEKABLE(g_io_stream_get_input_stream(G_IO_STREAM(handle))));
}
コード例 #29
0
ファイル: cockpitstream.c プロジェクト: AmartC/cockpit
static void
initialize_io (CockpitStream *self)
{
  GInputStream *is;
  GOutputStream *os;

  g_return_if_fail (self->priv->in_source == NULL);

  is = g_io_stream_get_input_stream (self->priv->io);
  os = g_io_stream_get_output_stream (self->priv->io);

  if (!G_IS_POLLABLE_INPUT_STREAM (is) ||
      !g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (is)) ||
      !G_IS_POLLABLE_OUTPUT_STREAM (os) ||
      !g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (os)))
    {
      g_warning ("%s: stream is not pollable", self->priv->name);
      close_immediately (self, "internal-error");
      return;
    }

  if (self->priv->connecting)
    {
      cockpit_connectable_unref (self->priv->connecting);
      self->priv->connecting = NULL;
    }

  self->priv->in_source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (is), NULL);
  g_source_set_name (self->priv->in_source, "stream-input");
  g_source_set_callback (self->priv->in_source, (GSourceFunc)dispatch_input, self, NULL);
  g_source_attach (self->priv->in_source, self->priv->context);

  if (G_IS_TLS_CONNECTION (self->priv->io))
    {
      self->priv->sig_accept_cert =  g_signal_connect (G_TLS_CONNECTION (self->priv->io),
                                                       "accept-certificate",
                                                       G_CALLBACK (on_rejected_certificate),
                                                       self);
    }
  else
    {
      self->priv->sig_accept_cert = 0;
    }

  start_output (self);

  g_signal_emit (self, cockpit_stream_sig_open, 0);
}
コード例 #30
0
static gboolean
on_incoming_connection (GSocketService * service,
                        GSocketConnection * connection,
                        GObject * source_object,
                        gpointer user_data)
{
  GInputStream * input;
  void * buf;

  input = g_io_stream_get_input_stream (G_IO_STREAM (connection));
  buf = g_malloc (1);
  g_input_stream_read_async (input, buf, 1, G_PRIORITY_DEFAULT, NULL,
      on_read_ready, NULL);

  return TRUE;
}