GNet Network Library Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
TcpSocket represents an open TCP (stream) socket. Create a TcpSocket by calling tcp_socket_new or tcp_socket_port_new.
|
A quick and easy
GTcpSocketConnectAsyncID gnet_tcp_socket_connect_async (const |
A quick and easy asynchronous
hostname : | Name of host to connect to |
port : | Port to connect to |
func : | Callback function |
data : | User data passed when callback function is called. |
Returns : | ID of the connection which can be used with gnet_tcp_socket_connect_async_cancel() to cancel it; NULL on failure. |
void gnet_tcp_socket_connect_async_cancel (GTcpSocketConnectAsyncID id); |
Cancel an asynchronous connection that was started with gnet_tcp_socket_connect_async().
ID of an asynchronous connection started with gnet_tcp_socket_connect_async(). The connection can be canceled by calling gnet_tcp_socket_connect_async_cancel() with the ID.
void (*GTcpSocketConnectAsyncFunc) ( |
Callback for gnet_tcp_socket_connect_async().
typedef enum { GTCP_SOCKET_CONNECT_ASYNC_STATUS_OK, GTCP_SOCKET_CONNECT_ASYNC_STATUS_INETADDR_ERROR, GTCP_SOCKET_CONNECT_ASYNC_STATUS_TCP_ERROR } GTcpSocketConnectAsyncStatus; |
Status for connecting via gnet_tcp_socket_connect_async(), passed by GTcpSocketConnectAsyncFunc. More errors may be added in the future, so it's best to compare against GTCP_SOCKET_CONNECT_ASYNC_STATUS_OK.
|
Connect to a specified address. Use this sort of socket when you're a client connecting to a server. This function will block to connect. SOCKS is used if SOCKS is enabled.
GTcpSocketNewAsyncID gnet_tcp_socket_new_async (const |
Connect to a specifed address asynchronously. When the connection is complete or there is an error, it will call the callback. It may call the callback before the function returns. It will call the callback if there is a failure. SOCKS is used if SOCKS is enabled. The SOCKS negotiation will block.
addr : | Address to connect to. |
func : | Callback function. |
data : | User data passed when callback function is called. |
Returns : | ID of the connection which can be used with gnet_tcp_socket_connect_async_cancel() to cancel it; NULL on failure. |
void gnet_tcp_socket_new_async_cancel (GTcpSocketNewAsyncID id); |
Cancel an asynchronous connection that was started with gnet_tcp_socket_new_async().
ID of an asynchronous tcp socket creation started with gnet_tcp_socket_new_async(). The creation can be canceled by calling gnet_tcp_socket_new_async_cancel() with the ID.
void (*GTcpSocketNewAsyncFunc) ( |
Callback for gnet_tcp_socket_new_async().
typedef enum { GTCP_SOCKET_NEW_ASYNC_STATUS_OK, GTCP_SOCKET_NEW_ASYNC_STATUS_ERROR } GTcpSocketNewAsyncStatus; |
void gnet_tcp_socket_ref ( |
Increment the reference counter of the GTcpSocket.
void gnet_tcp_socket_unref ( |
Remove a reference from the
|
Get the
For a client socket, the
For a server socket however, the
There is one channel for every socket. This function refs the channel before returning it. You should unref the channel when you are done with it. However, you should not close the channel - this is done when you delete the socket.
|
Get the address of the socket. If the socket is client socket,
the address is the address of the remote host it is connected to.
If the socket is a server socket, the address is the address of
the local host. (Though you should use
gnet_inetaddr_gethostaddr() to get the
|
Get the port number the socket is bound to.
typedef enum { GNET_TOS_NONE, GNET_TOS_LOWDELAY, GNET_TOS_THROUGHPUT, GNET_TOS_RELIABILITY, GNET_TOS_LOWCOST } GNetTOS; |
void gnet_tcp_socket_set_tos ( |
Set the type-of-service of the socket. Usually, routers don't honor this. Some systems don't support this function. If the operating system does not support it, the function does nothing.
|
Create and open a new
|
Create and open a new
|
Accept a connection from the socket. The socket must have been
created using gnet_tcp_socket_server_new(). This function will
block (use gnet_tcp_socket_server_accept_nonblock() if you don't
want to block). If the socket's
|
Accept a connection from the socket without blocking. The socket
must have been created using gnet_tcp_socket_server_new(). This
function is best used with the socket's
void gnet_tcp_socket_server_accept_async ( |
Accept a connection from the socket asynchronously. The callback is called when a client has connection or the socket has an error.