/* Creates a new TCP connection from an accepted socket. This is only used * by InfdTcpServer and should not be considered regular API. Do not call * this function. Language bindings should not wrap it. */ InfTcpConnection* _inf_tcp_connection_accepted(InfIo* io, InfNativeSocket socket, InfIpAddress* address, guint port, const InfKeepalive* keepalive, GError** error) { InfTcpConnection* connection; InfTcpConnectionPrivate* priv; int errcode; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(socket != INVALID_SOCKET, NULL); g_return_val_if_fail(address != NULL, NULL); g_return_val_if_fail(keepalive != NULL, NULL); if(inf_tcp_connection_configure_socket(socket, keepalive, error) != TRUE) return NULL; g_return_val_if_fail(address != NULL, NULL); g_return_val_if_fail(port != 0, NULL); connection = inf_tcp_connection_new(io, address, port); inf_ip_address_free(address); priv = INF_TCP_CONNECTION_PRIVATE(connection); priv->socket = socket; priv->keepalive = *keepalive; inf_tcp_connection_connected(connection); return connection; }
/** * inf_io_remove_dispatch: * @io: A #InfIo. * @dispatch: A dispatch handle obtained from inf_io_add_dispatch(). * * Removes the given dispatch from @io so that it is not called. **/ void inf_io_remove_dispatch(InfIo* io, InfIoDispatch* dispatch) { InfIoIface* iface; g_return_if_fail(INF_IS_IO(io)); g_return_if_fail(dispatch != NULL); iface = INF_IO_GET_IFACE(io); g_return_if_fail(iface->remove_dispatch != NULL); iface->remove_dispatch(io, dispatch); }
/** * inf_io_remove_timeout: * @io: A #InfIo. * @timeout: A timeout handle obtained from inf_io_add_timeout(). * * Removes the given timeout. **/ void inf_io_remove_timeout(InfIo* io, InfIoTimeout* timeout) { InfIoIface* iface; g_return_if_fail(INF_IS_IO(io)); g_return_if_fail(timeout != NULL); iface = INF_IO_GET_IFACE(io); g_return_if_fail(iface->remove_timeout != NULL); iface->remove_timeout(io, timeout); }
/** * inf_io_update_watch: * @io: A #InfIo. * @watch: The watch to update, as returned by inf_io_add_watch(). * @events: The new events to watch for. * * Changes the events that the socket bound to @watch is being watched for. * The callback of @watch will only be called if one of the newly watched for * events occurs. */ void inf_io_update_watch(InfIo* io, InfIoWatch* watch, InfIoEvent events) { InfIoIface* iface; g_return_if_fail(INF_IS_IO(io)); g_return_if_fail(watch != NULL); iface = INF_IO_GET_IFACE(io); g_return_if_fail(iface->update_watch != NULL); iface->update_watch(io, watch, events); }
/** * inf_io_add_dispatch: * @io: A #InfIo. * @func: Function to be called when the function is dispatched. * @user_data: Extra data to pass to @func. * @notify: A #GDestroyNotify that is called when @user_data is no longer * needed, or %NULL. * * Schedules @func to be called by the thread @io runs in. This function can * be used from a different thread to communicate to @io's thread. * * Returns: A dispatch handle that can be used to stop the dispatched function * from being called as long as it has not yet been called. **/ InfIoDispatch* inf_io_add_dispatch(InfIo* io, InfIoDispatchFunc func, gpointer user_data, GDestroyNotify notify) { InfIoIface* iface; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(func != NULL, NULL); iface = INF_IO_GET_IFACE(io); g_return_val_if_fail(iface->add_dispatch != NULL, NULL); return iface->add_dispatch(io, func, user_data, notify); }
/** * inf_io_add_timeout: * @io: A #InfIo. * @msecs: Number of milliseconds after which the timeout should be elapsed. * @func: Function to be called when the timeout elapsed. * @user_data: Extra data to pass to @func. * @notify: A #GDestroyNotify that is called when @user_data is no longer * needed, or %NULL. * * Calls @func after at least @msecs milliseconds have elapsed. The timeout * is removed after it has elapsed. * * Returns: A timeout handle that can be used to remove the timeout. **/ InfIoTimeout* inf_io_add_timeout(InfIo* io, guint msecs, InfIoTimeoutFunc func, gpointer user_data, GDestroyNotify notify) { InfIoIface* iface; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(func != NULL, NULL); iface = INF_IO_GET_IFACE(io); g_return_val_if_fail(iface->add_timeout != NULL, NULL); return iface->add_timeout(io, msecs, func, user_data, notify); }
/** * inf_io_add_watch: * @io: A #InfIo. * @socket: The socket to watch. * @events: Events to watch for. * @func: Function to be called when one of the events occurs. * @user_data: Extra data to pass to @func. * @notify: A #GDestroyNotify that is called when @user_data is no longer * needed, or %NULL. * * Monitors the given socket for activity and calls @func if one of the * events specified in @events occurs. * * Returns: A #InfIoWatch that can be used to update or remove the watch. **/ InfIoWatch* inf_io_add_watch(InfIo* io, InfNativeSocket* socket, InfIoEvent events, InfIoWatchFunc func, gpointer user_data, GDestroyNotify notify) { InfIoIface* iface; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(socket != NULL, NULL); g_return_val_if_fail(func != NULL, NULL); iface = INF_IO_GET_IFACE(io); g_return_val_if_fail(iface->add_watch != NULL, NULL); return iface->add_watch(io, socket, events, func, user_data, notify); }
/** * inf_io_watch: * @io: A #InfIo. * @socket: The socket to watch. * @events: Events to watch for. * @func: Function to be called when one of the events occurs. * @user_data: Extra data to pass to @func. * @notify: A #GDestroyNotify that is called when @user_data is no longer * needed, or %NULL. * * Monitors the given socket for activity and calls @func if one of the * events specified in @events occurs. **/ void inf_io_watch(InfIo* io, InfNativeSocket* socket, InfIoEvent events, InfIoFunc func, gpointer user_data, GDestroyNotify notify) { InfIoIface* iface; g_return_if_fail(INF_IS_IO(io)); g_return_if_fail(socket != NULL); g_return_if_fail(events == 0 || func != NULL); iface = INF_IO_GET_IFACE(io); g_return_if_fail(iface->watch != NULL); iface->watch(io, socket, events, func, user_data, notify); }
/** * inf_tcp_connection_new_resolve: (constructor) * @io: A #InfIo object used to watch for activity. * @resolver: The hostname resolver object used to look up the remote * hostname. * * Creates a new #InfTcpConnection and instead of setting the remote IP * address and port number directly, a hostname resolver is used to look up * the remote hostname before connecting. This has the advantage that all * available addresses for that hostname are tried before giving up. * * The argument is stored as a property for an eventual * inf_tcp_connection_open() call, this function itself does not * establish a connection. * * Returns: (transfer full): A new #InfTcpConnection. Free with * g_object_unref(). */ InfTcpConnection* inf_tcp_connection_new_resolve(InfIo* io, InfNameResolver* resolver) { InfTcpConnection* tcp; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(INF_IS_NAME_RESOLVER(resolver), NULL); tcp = INF_TCP_CONNECTION( g_object_new( INF_TYPE_TCP_CONNECTION, "io", io, "resolver", resolver, NULL ) ); return tcp; }
/** * inf_tcp_connection_new_and_open: (constructor) * @io: A #InfIo object used to watch for activity. * @remote_addr: The address to connect to. * @remote_port: The port to connect to. * @error: Location to store error information. * * Creates a new #InfTcpConnection and connects it to the given TCP endpoint. * Like inf_tcp_connection_new(), but calls inf_tcp_connection_open(). * * Returns: (transfer full): A new #InfTcpConnection, or %NULL on error. * Free with g_object_unref(). **/ InfTcpConnection* inf_tcp_connection_new_and_open(InfIo* io, const InfIpAddress* remote_addr, guint remote_port, GError** error) { InfTcpConnection* tcp; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(remote_addr != NULL, NULL); g_return_val_if_fail(remote_port <= 65535, NULL); g_return_val_if_fail(error == NULL || *error == NULL, NULL); tcp = inf_tcp_connection_new(io, remote_addr, remote_port); if(inf_tcp_connection_open(tcp, error) == FALSE) { g_object_unref(tcp); return NULL; } return tcp; }
/** * inf_tcp_connection_new: (constructor) * @io: A #InfIo object used to watch for activity. * @remote_addr: The address to eventually connect to. * @remote_port: The port to eventually connect to. * * Creates a new #InfTcpConnection. The arguments are stored as properties for * an eventual inf_tcp_connection_open() call, this function itself does not * establish a connection. * * Returns: (transfer full): A new #InfTcpConnection. Free with * g_object_unref(). **/ InfTcpConnection* inf_tcp_connection_new(InfIo* io, const InfIpAddress* remote_addr, guint remote_port) { InfTcpConnection* tcp; g_return_val_if_fail(INF_IS_IO(io), NULL); g_return_val_if_fail(remote_addr != NULL, NULL); g_return_val_if_fail(remote_port <= 65535, NULL); tcp = INF_TCP_CONNECTION( g_object_new( INF_TYPE_TCP_CONNECTION, "io", io, "remote-address", remote_addr, "remote-port", remote_port, NULL ) ); return tcp; }