1.概述
GSocketConnection是一种用于socket连接的结构。
他在gobject中的继承关系如下:
GObject
+----GIOStream
+----GSocketConnection
+----GTcpConnection
+----GUnixConnection
描述:GSocketConnection是一种用于socket连接的GIO流子类,它的类型决定于底层socket;例如tcp/ip连接中,它就是GTcpConnection。
除了GTcpConnection和GUnixConnection两种,还可以用g_socket_connection_factory_register_type()来创建新的类型以定义特定的域/类型/协议组合。
2.几个函数
GSocketAddress * g_socket_connection_get_local_address(GSocketConnection *connection, GError **error);
获取socket连接的本地地址。
GSocketAddress 是一个代表socket通信终端的抽像基类,父类是Gobject
GSocketAddress * g_socket_connection_get_remote_address (GSocketConnection *connection, GError **error);
获取socket连接的远程端地址。
void g_socket_connection_factory_register_type (GType g_type, GSocketFamily family, GSocketType type, gint protocol);
查询用于创建属性为family、type、 protocol的g_type,如果没有找到,则用family、type、 protocol创建一个新的。
GType g_socket_connection_factory_lookup_type (GSocketFamily family, GSocketType type, gint protocol_id);
同上,只是不创建新类型
3.GSocketFamilly
typedef enum {
G_SOCKET_FAMILY_INVALID,
#ifdef GLIB_SYSDEF_AF_UNIX
G_SOCKET_FAMILY_UNIX = GLIB_SYSDEF_AF_UNIX,
#endif
G_SOCKET_FAMILY_IPV4 = GLIB_SYSDEF_AF_INET,
G_SOCKET_FAMILY_IPV6 = GLIB_SYSDEF_AF_INET6
} GSocketFamily;
4.GSocketType
typedef enum
{
G_SOCKET_TYPE_INVALID,
G_SOCKET_TYPE_STREAM,
G_SOCKET_TYPE_DATAGRAM,
G_SOCKET_TYPE_SEQPACKET
} GSocketType;
5.GSocketProtocol
typedef enum {
G_SOCKET_PROTOCOL_UNKNOWN = -1,
G_SOCKET_PROTOCOL_DEFAULT = 0,
G_SOCKET_PROTOCOL_TCP = 6,
G_SOCKET_PROTOCOL_UDP = 17,
G_SOCKET_PROTOCOL_SCTP = 132
} GSocketProtocol;