Unix

Name

Unix -- Unix Sockets

Synopsis



GUnixSocket* gnet_unix_socket_connect       (const gchar *path);
GUnixSocket* gnet_unix_socket_new           (const gchar *path);
void        gnet_unix_socket_delete         (GUnixSocket *s);
void        gnet_unix_socket_ref            (GUnixSocket *s);
void        gnet_unix_socket_unref          (GUnixSocket *s);
GIOChannel* gnet_unix_socket_get_iochannel  (GUnixSocket *socket);
gchar*      gnet_unix_socket_get_path       (const GUnixSocket *socket);
GUnixSocket* gnet_unix_socket_server_new    (const gchar *path);
GUnixSocket* gnet_unix_socket_server_accept (const GUnixSocket *socket);
GUnixSocket* gnet_unix_socket_server_accept_nonblock
                                            (const GUnixSocket *socket);

Description

Unix Sockets are only available on Unix systems.

Details

gnet_unix_socket_connect ()

GUnixSocket* gnet_unix_socket_connect       (const gchar *path);

A quick and easy GUnixSocket constructor. This connects to the specified path. This function does block. Use this function when you are a client connecting to a server and you don't mind blocking.

path : Path to socket to connect to
Returns : A new GUnixSocket, or NULL if there was a failure.


gnet_unix_socket_new ()

GUnixSocket* gnet_unix_socket_new           (const gchar *path);

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.

path : Path to connect to.
Returns : A new GUnixSocket, or NULL if there was a failure.


gnet_unix_socket_delete ()

void        gnet_unix_socket_delete         (GUnixSocket *s);

Close and delete a GUnixSocket, regardless of reference count.

s : UnixSocket to delete.


gnet_unix_socket_ref ()

void        gnet_unix_socket_ref            (GUnixSocket *s);

Increment the reference counter of a GUnixSocket.

s : GUnixSocket to reference


gnet_unix_socket_unref ()

void        gnet_unix_socket_unref          (GUnixSocket *s);

Remove a reference from the GUnixSocket. When the reference count reaches 0, the socket is deleted.

s : GUnixSocket to unreference


gnet_unix_socket_get_iochannel ()

GIOChannel* gnet_unix_socket_get_iochannel  (GUnixSocket *socket);

Get the GIOChannel for the GUnixSocket.

For a client socket, the GIOChannel represents the data stream. Use it like you would any other GIOChannel.

For a server socket, however, the GIOChannel represents incoming connections. If you can read from it, there's a connection waiting to be accepted.

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.

socket : GUnixSocket to get GIOChannel from.
Returns : A GIOChannel; NULL on failure.


gnet_unix_socket_get_path ()

gchar*      gnet_unix_socket_get_path       (const GUnixSocket *socket);

Get the path of the socket.

socket : GUnixSocket to get the path of.
Returns : Caller-owned path; NULL on failure.


gnet_unix_socket_server_new ()

GUnixSocket* gnet_unix_socket_server_new    (const gchar *path);

Create and open a new GUnixSocket with the specified path. Use this sort of socket when you are a server.

path : Path for the socket.
Returns : a new GUnixSocket, or NULL if there was a failure.


gnet_unix_socket_server_accept ()

GUnixSocket* gnet_unix_socket_server_accept (const GUnixSocket *socket);

Accept connections from the socket. The socket must have been created using gnet_unix_socket_server_new(). This function will block (use gnet_unix_socket_server_accept_nonblock() if you don't want to block). If the socket's GIOChannel is readable, it DOES NOT mean that this function will block.

socket : GUnixSocket to accept connections from
Returns : a new GUnixSocket if there is another connect, or NULL if there's an error.


gnet_unix_socket_server_accept_nonblock ()

GUnixSocket* gnet_unix_socket_server_accept_nonblock
                                            (const GUnixSocket *socket);

Accept a connection from the socket without blocking. The socket must have been created using gnet_unix_socket_server_new(). This function is best used with the socket's GIOChannel. If the channel is readable, then you PROBABLY have a connection. It is possible for the connection to close by the time you call this, so it may return NULL even if the channel was readable.

socket : GUnixSocket to accept connections from.
Returns : a new GUnixSocket if there was another connect, or NULL otherwise.