Example #1
0
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;
}
Example #2
0
int main (int argc, char *argv[])
{
  GMainLoop     *loop   = NULL;
  GSocketClient *client = NULL;

  g_type_init ();

  map = open("dummy.dat", O_RDWR | O_CREAT);
  if (-1 == map)
  {
    perror ("open");
    return 0;
  }

  data = mmap (NULL, 1024 * 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE, map, 0);
  if (MAP_FAILED == data)
  {
    perror ("mmap");
    return 0;
  }

  client = g_socket_client_new ();

  g_socket_client_connect_to_host_async (client, "127.0.0.1", 8080, NULL, on_connected, client);

  loop = g_main_loop_new (NULL, FALSE);
  
  g_main_loop_run (loop);

  g_main_loop_unref (loop);

  return 0;
}
Example #3
0
static VALUE
rg_initialize(VALUE self)
{
        G_INITIALIZE(self, g_socket_client_new());

        return Qnil;
}
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');
}
Example #5
0
static void
test_happy_eyeballs_cancel_delayed (void)
{
  GSocketClient *client;
  GSocketService *service;
  GError *error = NULL;
  guint16 port;
  GMainLoop *loop;
  GCancellable *cancel;
  gboolean got_completed_event = FALSE;

  /* This just tests that cancellation works as expected, still emits the completed signal,
   * and never returns a connection */

  loop = g_main_loop_new (NULL, FALSE);

  service = g_socket_service_new ();
  port = g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL, &error);
  g_assert_no_error (error);
  g_socket_service_start (service);

  client = g_socket_client_new ();
  cancel = g_cancellable_new ();
  g_socket_client_connect_to_host_async (client, "localhost", port, cancel, on_connected_cancelled, loop);
  g_timeout_add (1, (GSourceFunc) on_timer, cancel);
  g_signal_connect (client, "event", G_CALLBACK (on_event), &got_completed_event);
  g_main_loop_run (loop);

  g_assert_true (got_completed_event);
  g_main_loop_unref (loop);
  g_object_unref (service);
  g_object_unref (client);
  g_object_unref (cancel);
}
Example #6
0
static void
test_happy_eyeballs_cancel_instant (void)
{
  GSocketClient *client;
  GSocketService *service;
  GError *error = NULL;
  guint16 port;
  GMainLoop *loop;
  GCancellable *cancel;
  gboolean got_completed_event = FALSE;

  /* This tests the same things as above, test_happy_eyeballs_cancel_delayed(), but
   * with different timing since it sends an already cancelled cancellable */

  loop = g_main_loop_new (NULL, FALSE);

  service = g_socket_service_new ();
  port = g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL, &error);
  g_assert_no_error (error);
  g_socket_service_start (service);

  client = g_socket_client_new ();
  cancel = g_cancellable_new ();
  g_cancellable_cancel (cancel);
  g_socket_client_connect_to_host_async (client, "localhost", port, cancel, on_connected_cancelled, loop);
  g_signal_connect (client, "event", G_CALLBACK (on_event), &got_completed_event);
  g_main_loop_run (loop);

  g_assert_true (got_completed_event);
  g_main_loop_unref (loop);
  g_object_unref (service);
  g_object_unref (client);
  g_object_unref (cancel);
}
Example #7
0
static void
test_happy_eyeballs (void)
{
  GSocketClient *client;
  GSocketService *service;
  GError *error = NULL;
  guint16 port;
  GMainLoop *loop;

  loop = g_main_loop_new (NULL, FALSE);

  service = g_socket_service_new ();
  port = g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL, &error);
  g_assert_no_error (error);
  g_socket_service_start (service);

  /* All of the magic here actually happens in slow-connect-preload.c
   * which as you would guess is preloaded. So this is just making a
   * normal connection that happens to take 600ms each time. This will
   * trigger the logic to make multiple parallel connections.
   */
  client = g_socket_client_new ();
  g_socket_client_connect_to_host_async (client, "localhost", port, NULL, on_connected, loop);
  g_main_loop_run (loop);

  g_main_loop_unref (loop);
  g_object_unref (service);
  g_object_unref (client);
}
Example #8
0
static GSocketConnection *_s52_init_sock(char *hostname, int port)
{
    g_print("s52ais:_init_s52_sock(): starting ..\n");

    GSocketClient *client = g_socket_client_new();
    if (NULL == client) {
        g_print("s52ais:_s52_init_sock(): client NULL  ..\n");
        return NULL;
    }

    GSocketConnectable *connectable = g_network_address_new(hostname, port);
    if (NULL == connectable) {
        g_print("s52ais:_s52_init_sock(): connectable NULL  ..\n");
        return NULL;
    }

    GError            *error = NULL;
    GSocketConnection *conn  = g_socket_client_connect(client, connectable, NULL, &error);

    g_object_unref(client);
    g_object_unref(connectable);

    if (NULL != error) {
        g_print("s52ais:_s52_init_sock():ERROR: %s\n", error->message);
        return NULL;
    }

    g_print("s52ais:_s52_init_sock(): connected to hostname:%s, port:%i\n", hostname, port);

    return conn;
}
Example #9
0
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_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;
    }

  conn->connection = G_SOCKET_CONNECTION (conn->commands);
  enable_nodelay (conn->connection);
  enable_keepalive (conn->connection);
  create_input_stream (conn);
  /* The first thing that needs to happen is receiving the welcome message */
  conn->waiting_for_reply = TRUE;

  return conn;
}
Example #10
0
GSocketClient *     
xg_socket_client_new (void)
{
    GSocketClient *s = g_socket_client_new ();
    if (s == NULL)
        g_critical("g_socket_client_new() returned NULL");
    return s;
}
static void idle_server_connection_init(IdleServerConnection *conn) {
	IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn);

	priv->host = NULL;
	priv->port = 0;

	priv->socket_client = g_socket_client_new();

	priv->state = SERVER_CONNECTION_STATE_NOT_CONNECTED;
}
static void
wocky_ll_connection_factory_init (WockyLLConnectionFactory *self)
{
  WockyLLConnectionFactoryPrivate *priv;

  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, WOCKY_TYPE_LL_CONNECTION_FACTORY,
      WockyLLConnectionFactoryPrivate);
  priv = self->priv;

  priv->client = g_socket_client_new ();
}
Example #13
0
// 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;
}
SocketStreamHandle::SocketStreamHandle(const KURL& url, SocketStreamHandleClient* client)
    : SocketStreamHandleBase(url, client)
    , m_readBuffer(0)
{
    unsigned int port = url.hasPort() ? url.port() : (url.protocolIs("wss") ? 443 : 80);

    m_id = activateHandle(this);
    GRefPtr<GSocketClient> socketClient = adoptGRef(g_socket_client_new());
    if (url.protocolIs("wss"))
        g_socket_client_set_tls(socketClient.get(), TRUE);
    g_socket_client_connect_to_host_async(socketClient.get(), url.host().utf8().data(), port, 0,
        reinterpret_cast<GAsyncReadyCallback>(connectedCallback), m_id);
}
Example #15
0
Ref<SocketStreamHandle> SocketStreamHandle::create(const URL& url, SocketStreamHandleClient& client, NetworkingContext&, SessionID)
{
    Ref<SocketStreamHandle> socket = adoptRef(*new SocketStreamHandle(url, client));

    unsigned port = url.hasPort() ? url.port() : (url.protocolIs("wss") ? 443 : 80);
    GRefPtr<GSocketClient> socketClient = adoptGRef(g_socket_client_new());
    if (url.protocolIs("wss"))
        g_socket_client_set_tls(socketClient.get(), TRUE);
    Ref<SocketStreamHandle> protectedSocketStreamHandle = socket.copyRef();
    g_socket_client_connect_to_host_async(socketClient.get(), url.host().utf8().data(), port, socket->m_cancellable.get(),
        reinterpret_cast<GAsyncReadyCallback>(connectedCallback), &protectedSocketStreamHandle.leakRef());
    return socket;
}
Example #16
0
File: server.c Project: worr/eventd
void
eventd_relay_server_start(EventdRelayServer *server)
{
    if ( server->address == NULL )
        return;

    GSocketClient *client;

    client = g_socket_client_new();

    g_socket_client_connect_async(client, server->address, NULL, _eventd_relay_connection_handler, server);

    g_object_unref(client);
}
Example #17
0
/* Test whether given host has an AppSocket/HP JetDirect printer connected.
   See http://en.wikipedia.org/wiki/JetDirect
       http://www.cups.org/documentation.php/network.html */
void
pp_host_get_jetdirect_devices_async (PpHost              *host,
                                     GCancellable        *cancellable,
                                     GAsyncReadyCallback  callback,
                                     gpointer             user_data)
{
  PpHostPrivate *priv = host->priv;
  GSocketClient *client;
  JetDirectData *data;
  GTask         *task;
  gchar         *address;
  gpointer       result;

  data = g_new0 (JetDirectData, 1);
  data->host = g_object_ref (host);
  data->devices = g_new0 (PpDevicesList, 1);

  if (priv->port == PP_HOST_UNSET_PORT)
    data->port = PP_HOST_DEFAULT_JETDIRECT_PORT;
  else
    data->port = priv->port;

  task = g_task_new (G_OBJECT (host), cancellable, callback, user_data);
  g_task_set_task_data (task, data, (GDestroyNotify) jetdirect_data_free);

  address = g_strdup_printf ("%s:%d", priv->hostname, data->port);
  if (address != NULL && address[0] != '/')
    {
      client = g_socket_client_new ();

      g_socket_client_connect_to_host_async (client,
                                             address,
                                             data->port,
                                             cancellable,
                                             jetdirect_connection_test_cb,
                                             task);

      g_object_unref (client);
    }
  else
    {
      result = data->devices;
      data->devices = NULL;
      g_task_return_pointer (task, result, (GDestroyNotify) pp_devices_list_free);
      g_object_unref (task);
    }

  g_free (address);
}
Example #18
0
static void
use_socket_client (gboolean synchronous)
{
  GError *error = NULL;
  GSocketClient *client;

  client = g_socket_client_new ();

  printf ("Proxies for URI '%s' are:\n", info);

  if (synchronous)
    {
      GSocketConnection *connection;
      GSocketAddress *proxy_addr;

      connection = g_socket_client_connect_to_uri (client,
						   info,
						   0,
      						   cancellable,
						   &error);

      if (connection)
	{
	  proxy_addr = g_socket_connection_get_remote_address (connection, NULL);
	  print_proxy_address (proxy_addr);
	}
      else
	{
	  print_and_free_error (error);
	}
    }
  else
    {
      GMainLoop *loop = g_main_loop_new (NULL, FALSE);

      g_socket_client_connect_to_uri_async (client,
					    info,
					    0,
					    cancellable,
					    _socket_connect_cb,
					    loop);

      g_main_loop_run (loop);
      g_main_loop_unref (loop);
    }

  g_object_unref (client);
}
Example #19
0
xr_client_conn* xr_client_new(GError** err)
{
  g_return_val_if_fail(err == NULL || *err == NULL, NULL);

  xr_trace(XR_DEBUG_CLIENT_TRACE, "(err=%p)", err);

  xr_init();

  xr_client_conn* conn = g_new0(xr_client_conn, 1);
  conn->client = g_socket_client_new();

  conn->headers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
  conn->transport = XR_CALL_XML_RPC;

  return conn;
}
Example #20
0
MCState *mc_state_new(char *host, int port) {
	GSocketClient *client;
	MCState *state = g_new0(MCState, 1);

	state->in = mc_buf_new();
	state->out = mc_buf_new();

	client = g_socket_client_new();
	state->conn = g_socket_client_connect_to_host(client, host, port, NULL, NULL);
	state->istream = g_io_stream_get_input_stream(G_IO_STREAM(state->conn));
	state->ostream = g_io_stream_get_output_stream(G_IO_STREAM(state->conn));

	g_object_unref(client);

	return state;
}
Example #21
0
int main (int argc, char *argv[])
{
  GError * error = NULL;
  gchar *str = "Hello server!";

  /* 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",
                                                1500, /* your port goes here */
                                                NULL,
                                                &error);

  /* don't forget to check for errors */
  if (error != NULL)
  {
    g_error ("%s", error->message);
  }
  else
  {
    g_print ("Connection successful!\n");
  }

  /* use the connection */
  GInputStream * istream = g_io_stream_get_input_stream (G_IO_STREAM (connection));
  GOutputStream * ostream = g_io_stream_get_output_stream (G_IO_STREAM (connection));
  g_output_stream_write  (ostream,
                          str, /* your message goes here */
                          strlen(str) + 1, /* length of your message */
                          NULL,
                          &error);
  /* don't forget to check for errors */
  if (error != NULL)
  {
    g_error ("%s", error->message);
  }

  g_object_unref(client);
  if (connection != NULL)
  {
    g_object_unref(connection);
  }
  return 0;
}
Example #22
0
static void mega_http_client_init(MegaHttpClient *http_client)
{
  MegaHttpClientPrivate* priv = http_client->priv = G_TYPE_INSTANCE_GET_PRIVATE(http_client, MEGA_TYPE_HTTP_CLIENT, MegaHttpClientPrivate);

  priv->client = g_socket_client_new();
  g_socket_client_set_timeout(priv->client, 60);
  g_socket_client_set_family(priv->client, G_SOCKET_FAMILY_IPV4);
  priv->request_headers = g_hash_table_new_full(stri_hash, stri_equal, g_free, g_free);
  priv->response_headers = g_hash_table_new_full(stri_hash, stri_equal, g_free, g_free);
  priv->regex_url = g_regex_new("^([a-z]+)://([a-z0-9.-]+(?::([0-9]+))?)(/.+)?$", G_REGEX_CASELESS, 0, NULL);
  priv->regex_status = g_regex_new("^HTTP/([0-9]+\\.[0-9]+) ([0-9]+) (.+)$", 0, 0, NULL);

  // set default headers
  mega_http_client_set_header(http_client, "Referer", "https://mega.co.nz/");
  mega_http_client_set_header(http_client, "User-Agent", "Megatools (" VERSION ")");
  mega_http_client_set_header(http_client, "Connection", "keep-alive");
}
int add_slave_to_control(struct UpDeviceNode *devnode)
{
	GError * error = NULL;
	g_print ("%s\n", __FUNCTION__);

	devnode->user_data.client = g_socket_client_new();
	devnode->user_data.connection = g_socket_client_connect_to_host (devnode->user_data.client, devnode->user_data.ip_addr, CONTROL_PORT, NULL, &error);
	if (error != NULL)
	{
		g_print ("%s\n", error->message);
	}
	else
	{
		g_print ("Connect to %s is successful!\n", devnode->user_data.ip_addr);
	}
	return 0;
}
Example #24
0
static void
web_socket_client_constructed (GObject *object)
{
  WebSocketClient *self = WEB_SOCKET_CLIENT (object);
  WebSocketConnection *conn = WEB_SOCKET_CONNECTION (object);
  GSocketClient *client;
  const gchar *url;
  guint16 default_port;
  gchar *scheme;

  G_OBJECT_CLASS (web_socket_client_parent_class)->constructed (object);

  if (web_socket_connection_get_io_stream (conn))
    {
      /* Start handshake from the main context */
      self->idle_start = g_idle_source_new ();
      g_source_set_priority (self->idle_start, G_PRIORITY_HIGH);
      g_source_set_callback (self->idle_start, (GSourceFunc)on_idle_do_handshake,
                             self, NULL);
      g_source_attach (self->idle_start, _web_socket_connection_get_main_context (conn));
    }
  else
    {
      client = g_socket_client_new ();
      self->cancellable = g_cancellable_new ();

      url = web_socket_connection_get_url (WEB_SOCKET_CONNECTION (self));
      scheme = g_uri_parse_scheme (url);
      if (scheme && (g_str_equal (scheme, "wss") || g_str_equal (scheme, "https")))
        {
          g_socket_client_set_tls (client, TRUE);
          default_port = 443;
        }
      else
        {
          default_port = 80;
        }
      g_free (scheme);

      g_socket_client_connect_to_uri_async (client, url, default_port,
                                            self->cancellable, on_connect_to_uri,
                                            g_object_ref (self));
      g_object_unref (client);
    }
}
Example #25
0
static void
connect_impl (PnNode *conn,
              const gchar *hostname,
              gint port)
{
    g_return_if_fail (conn);

    pn_log ("begin");

    pn_debug ("conn=%p,name=%s", conn, conn->name);
    pn_debug ("hostname=%s,port=%d", hostname, port);
    pn_debug ("next=%p", conn->next);

    g_free (conn->hostname);
    conn->hostname = g_strdup (hostname);
    conn->port = port;

    if (conn->next)
    {
        conn->status = PN_NODE_STATUS_CONNECTING;

        conn->next->prev = conn;
        pn_node_connect (conn->next, hostname, port);
        conn->next->prev = NULL;
    }
    else
    {
        pn_node_close (conn);

        conn->status = PN_NODE_STATUS_CONNECTING;

#if defined(USE_GIO)
        GSocketClient *client;
        client = g_socket_client_new();
        conn->socket_cancel = g_cancellable_new();
        g_socket_client_connect_to_host_async(client, hostname, port,
                                              conn->socket_cancel, connect_cb, conn);
#elif defined(HAVE_LIBPURPLE)
        conn->connect_data = purple_proxy_connect (NULL, msn_session_get_user_data (conn->session),
                             hostname, port, connect_cb, conn);
#endif
    }

    pn_log ("end");
}
int
main (int argc, char *argv[])
{
   /* initialize glib */
  //g_type_init ();

  GError * error = NULL;

  /* 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",
                                                2345, /* your port goes here */
                                                NULL,
                                                &error);

  /* don't forget to check for errors */
  if (error != NULL)
  {
      g_error (error->message);
  }
  else
  {
      g_print ("Connection successful!\n");
  }

  /* use the connection */
  //GInputStream * istream = g_io_stream_get_input_stream (G_IO_STREAM (connection));
  GOutputStream * ostream = g_io_stream_get_output_stream (G_IO_STREAM (connection));
  g_output_stream_write  (ostream,
                          "Hello server!", /* your message goes here */
                          13, /* length of your message */
                          NULL,
                          &error);
  /* don't forget to check for errors */
  if (error != NULL)
  {
      g_error (error->message);
  }
  return 0;
}
Example #27
0
static void
try_tunnel (SoupServer *server, SoupMessage *msg, SoupClientContext *context)
{
	Tunnel *tunnel;
	SoupURI *dest_uri;
	GSocketClient *sclient;

	soup_server_pause_message (server, msg);

	tunnel = g_new0 (Tunnel, 1);
	tunnel->self = g_object_ref (server);
	tunnel->msg = g_object_ref (msg);
	tunnel->context = context;

	dest_uri = soup_message_get_uri (msg);
	sclient = g_socket_client_new ();
	g_socket_client_connect_to_host_async (sclient, dest_uri->host, dest_uri->port,
					       NULL, tunnel_connected_cb, tunnel);
	g_object_unref (sclient);
}
Example #28
0
static void
_j4status_io_stream_connect(J4statusIOStream *self)
{
    if ( self->connection != NULL )
    {
        g_object_unref(self->in);
        g_object_unref(self->out);
        g_object_unref(self->connection);
        self->connection = NULL;
        self->out = NULL;
        self->in = NULL;
    }


    GSocketClient *client;
    client = g_socket_client_new();

    g_socket_client_connect_async(client, G_SOCKET_CONNECTABLE(self->address), NULL, _j4status_io_stream_connect_callback, self);
    g_object_unref(client);
}
Example #29
0
int main(int argc, char *argv[]) {
    LibWCRelay *relay = libwc_relay_new();
    GSocketClient *socket_client = g_socket_client_new();
    GSocketConnection *socket_connection;
    gboolean result;
    gchar *ping_result;
    GError *error = NULL;

    if (argc < 2) {
        fprintf(stderr, "Usage: test-client <host[:port]>\n");
        exit(1);
    }

    socket_connection = g_socket_client_connect_to_host(socket_client, argv[1],
                                                        49153, NULL, &error);
    END_IF_FAIL(socket_connection != NULL);

    libwc_relay_password_set(relay, "test");
    libwc_relay_connection_set(relay, G_IO_STREAM(socket_connection),
                               g_socket_connection_get_socket(socket_connection));

    result = libwc_relay_connection_init(relay, NULL, &error);

    if (result)
        printf("Connection successful!\n");
    else {
        fprintf(stderr, "Connection unsuccessful: %s\n",
                error->message);
        exit(1);
    }

    ping_result = libwc_relay_ping(relay, NULL, &error, TEST_PING_MESSAGE);

    if (ping_result && strcmp(ping_result, TEST_PING_MESSAGE) == 0)
        printf("Ping successful!\n");
    else {
        fprintf(stderr, "Ping unsuccessful: %s\n",
                error->message);
        exit(1);
    }
}
Example #30
0
GVfsAfpReply *
g_vfs_afp_connection_get_server_info (GVfsAfpConnection *afp_connection,
                                      GCancellable *cancellable,
                                      GError **error)
{
  GVfsAfpConnectionPrivate *priv = afp_connection->priv;
  
  GSocketClient *client;
  GIOStream *conn;
  gboolean res;
  DSIHeader dsi_header;
  char *data;

  client = g_socket_client_new ();
  conn = G_IO_STREAM (g_socket_client_connect (client, priv->addr, cancellable, error));
  g_object_unref (client);

  if (!conn)
    return NULL;

  res = send_request_sync (g_io_stream_get_output_stream (conn), DSI_GET_STATUS,
                           0, 0, 0, NULL, cancellable, error);
  if (!res)
  {
    g_object_unref (conn);
    return NULL;
  }

  res = read_reply_sync (g_io_stream_get_input_stream (conn), &dsi_header,
                         &data, cancellable, error);
  if (!res)
  {
    g_object_unref (conn);
    return NULL;
  }

  g_object_unref (conn);
  
  return g_vfs_afp_reply_new (dsi_header.errorCode, data,
                              dsi_header.totalDataLength, TRUE);
}