static void test_event_signal (void) { gboolean success = FALSE; GInetAddress *iaddr; GSocketAddress *saddr; GSocketListener *listener; GError *error = NULL; iaddr = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4); saddr = g_inet_socket_address_new (iaddr, 0); g_object_unref (iaddr); listener = g_socket_listener_new (); g_signal_connect (listener, "event", G_CALLBACK (event_cb), &success); g_socket_listener_add_address (listener, saddr, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, NULL, NULL, &error); g_assert_no_error (error); g_assert_true (success); g_object_unref (saddr); g_object_unref (listener); }
gint interface_createAddress(struct node *n) //GInetAddress *addr) { GError * e = NULL; GInetAddress *lo = g_inet_address_new_loopback( G_SOCKET_FAMILY_IPV6); GSocketAddress *sa = g_inet_socket_address_new( lo, 42); GSocket *s = n->ubnetd; if( s != NULL ){ g_socket_close(s,NULL); g_object_unref(s); } s = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, &e); if( e != NULL ){ syslog(LOG_ERR,"interface_pushAddress: Error while creating socket: %s\n", e->message); g_error_free(e); return -1; } g_socket_connect(s, sa, NULL, &e); if( e != NULL ){ syslog(LOG_ERR,"interface_pushAddress: Error while connecting: %s\n", e->message); g_error_free(e); return -1; } g_socket_send(s,"A",1,NULL,NULL); gchar *bytes = (gchar*)g_inet_address_to_bytes(n->netadr); g_socket_send(s,bytes,16,NULL,NULL); n->ubnetd = s; //gchar buf[1]; //g_socket_receive(s,buf,1,NULL,NULL); return 0; }
GSocket * _client_create_local_socket (GError **error) { GSocket *socket = NULL; GInetAddress * inet_address = NULL; GSocketAddress *socket_address = NULL; /* Create the IPv4 socket, and listen for connection on it */ socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, error); if (socket != NULL) { inet_address = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4); socket_address = g_inet_socket_address_new (inet_address, 0); g_socket_bind (socket, socket_address, FALSE, error); } tp_clear_object (&inet_address); tp_clear_object (&socket_address); return socket; }
static void cockpit_channel_class_init (CockpitChannelClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GSocketAddress *address; GInetAddress *inet; const gchar *port; gobject_class->constructed = cockpit_channel_constructed; gobject_class->get_property = cockpit_channel_get_property; gobject_class->set_property = cockpit_channel_set_property; gobject_class->dispose = cockpit_channel_dispose; gobject_class->finalize = cockpit_channel_finalize; klass->prepare = cockpit_channel_real_prepare; klass->close = cockpit_channel_real_close; /** * CockpitChannel:transport: * * The transport to send and receive messages over. */ g_object_class_install_property (gobject_class, PROP_TRANSPORT, g_param_spec_object ("transport", "transport", "transport", COCKPIT_TYPE_TRANSPORT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel:channel: * * The numeric channel to receive and send messages on. */ g_object_class_install_property (gobject_class, PROP_ID, g_param_spec_string ("id", "id", "id", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel:options: * * The JSON options used to open this channel. The exact contents are * dependent on the derived channel class ... but this must at the * very least contain a 'payload' field describing what kind of channel * this should be. */ g_object_class_install_property (gobject_class, PROP_OPTIONS, g_param_spec_boxed ("options", "options", "options", JSON_TYPE_OBJECT, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel:capabilities: * * The capabilties that this channel supports. */ g_object_class_install_property (gobject_class, PROP_CAPABILITIES, g_param_spec_boxed ("capabilities", "Capabilities", "Channel Capabilities", G_TYPE_STRV, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel::closed: * * Emitted when the channel closes. This is similar to CockpitTransport::closed * but only applies to the individual channel. * * The channel will also be closed when the transport closes. */ cockpit_channel_sig_closed = g_signal_new ("closed", COCKPIT_TYPE_CHANNEL, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (CockpitChannelClass, closed), NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_STRING); g_type_class_add_private (klass, sizeof (CockpitChannelPrivate)); /* * If we're running under a test server, register that server's HTTP address * as an internal address, available for use in cockpit channels. */ port = g_getenv ("COCKPIT_TEST_SERVER_PORT"); if (port) { inet = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4); address = g_inet_socket_address_new (inet, atoi (port)); cockpit_channel_internal_address ("test-server", address); g_object_unref (address); g_object_unref (inet); } }
static VALUE rg_s_new_loopback(G_GNUC_UNUSED VALUE self, VALUE family) { return GOBJ2RVAL_UNREF(g_inet_address_new_loopback(RVAL2GSOCKETFAMILY(family))); }
/** * tp_stream_tube_channel_offer_async: * @self: an outgoing #TpStreamTubeChannel * @params: (allow-none) (transfer none): parameters of the tube, or %NULL * @callback: a callback to call when the tube has been offered * @user_data: data to pass to @callback * * Offer an outgoing stream tube. When the tube has been offered, @callback * will be called. You can then call tp_stream_tube_channel_offer_finish() * to get the result of the operation. * * You have to connect to the #TpStreamTubeChannel::incoming signal to get a * #TpStreamTubeConnection each time a contact establishes a connection to * the tube. * * Since: 0.13.2 */ void tp_stream_tube_channel_offer_async (TpStreamTubeChannel *self, GHashTable *params, GAsyncReadyCallback callback, gpointer user_data) { GHashTable *properties; GHashTable *supported_sockets; GError *error = NULL; g_return_if_fail (TP_IS_STREAM_TUBE_CHANNEL (self)); g_return_if_fail (self->priv->result == NULL); g_return_if_fail (tp_channel_get_requested (TP_CHANNEL (self))); if (self->priv->service != NULL) { g_critical ("Can't reoffer Tube!"); return; } self->priv->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, tp_stream_tube_channel_offer_async); properties = _tp_channel_get_immutable_properties (TP_CHANNEL (self)); supported_sockets = tp_asv_get_boxed (properties, TP_PROP_CHANNEL_TYPE_STREAM_TUBE_SUPPORTED_SOCKET_TYPES, TP_HASH_TYPE_SUPPORTED_SOCKET_MAP); if (!_tp_set_socket_address_type_and_access_control_type (supported_sockets, &self->priv->socket_type, &self->priv->access_control, &error)) { operation_failed (self, error); g_clear_error (&error); return; } DEBUG ("Using socket type %u with access control %u", self->priv->socket_type, self->priv->access_control); self->priv->service = g_socket_service_new (); switch (self->priv->socket_type) { #ifdef HAVE_GIO_UNIX case TP_SOCKET_ADDRESS_TYPE_UNIX: { self->priv->address = _tp_create_temp_unix_socket ( self->priv->service, &error); /* check there wasn't an error on the final attempt */ if (self->priv->address == NULL) { operation_failed (self, error); g_clear_error (&error); return; } } break; #endif /* HAVE_GIO_UNIX */ case TP_SOCKET_ADDRESS_TYPE_IPV4: case TP_SOCKET_ADDRESS_TYPE_IPV6: { GInetAddress *localhost; GSocketAddress *in_address; localhost = g_inet_address_new_loopback ( self->priv->socket_type == TP_SOCKET_ADDRESS_TYPE_IPV4 ? G_SOCKET_FAMILY_IPV4 : G_SOCKET_FAMILY_IPV6); in_address = g_inet_socket_address_new (localhost, 0); g_socket_listener_add_address ( G_SOCKET_LISTENER (self->priv->service), in_address, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL, &self->priv->address, &error); g_object_unref (localhost); g_object_unref (in_address); if (error != NULL) { operation_failed (self, error); g_clear_error (&error); return; } break; } default: /* should have already errored */ g_assert_not_reached (); break; } tp_g_signal_connect_object (self->priv->service, "incoming", G_CALLBACK (service_incoming_cb), self, 0); g_socket_service_start (self->priv->service); _offer_with_address (self, params); }