GNet Network Library Reference Manual
<<< Previous Page | Home | Up | Next Page >>>

# Unix

## Name

Unix -- Unix Sockets

## Synopsis

    struct      GUnixSocket;
    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

### struct GUnixSocket

    struct GUnixSocket
    {
      gint sockfd;
      struct sockaddr sa;
      guint ref_count;
      gboolean server;
      GIOChannel *iochannel;
    };

### 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` : |
Returns : |

### 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` : |
Returns : |

### gnet_unix_socket_delete ()

    void        gnet_unix_socket_delete         (GUnixSocket *s);

Close and delete a GUnixSocket, regardless of reference count.

`s` : |

### gnet_unix_socket_ref ()

    void        gnet_unix_socket_ref            (GUnixSocket *s);

Increment the reference counter of a GUnixSocket.

`s` : |

### 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` : |

### 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` : |
Returns : |

### gnet_unix_socket_get_path ()

    gchar*      gnet_unix_socket_get_path       (const GUnixSocket *socket);

Get the path of the socket.

`socket` : |
Returns : |

### 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` : |
Returns : |

### 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` : |
Returns : |

### 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` : |
Returns : |

<<< Previous Page | Home | Up | Next Page >>>
TCP | socks