## socket

socket

## Synopsis

    #include <midori/midori.h>

    enum                ConnectionState;
    gint                (*SockConnectFunc)                  (SockInfo *sock,
                                                             gpointer data);
    gboolean            (*SockFunc)                         (SockInfo *sock,
                                                             GIOCondition condition,
                                                             gpointer data);
    struct              SockInfo;
    gint                fd_accept                           (gint sock);
    gint                fd_close                            (gint sock);
    gint                fd_connect_inet                     (gushort port);
    gint                fd_connect_unix                     (const gchar *path);
    gint                fd_getline                          (gint sock,
                                                             gchar **line);
    gint                fd_gets                             (gint sock,
                                                             gchar *buf,
                                                             gint len);
    gint                fd_open_inet                        (gushort port);
    gint                fd_open_unix                        (const gchar *path);
    gint                fd_read                             (gint sock,
                                                             gchar *buf,
                                                             gint len);
    gint                fd_write                            (gint sock,
                                                             const gchar *buf,
                                                             gint len);
    gint                fd_write_all                        (gint sock,
                                                             const gchar *buf,
                                                             gint len);
    struct hostent *    my_gethostbyname                    (const gchar *hostname);
    void                send_open_command                   (gint sock,
                                                             const gchar *command,
                                                             gchar **args);
    guint               sock_add_watch                      (SockInfo *sock,
                                                             GIOCondition condition,
                                                             SockFunc func,
                                                             gpointer data);
    gint                sock_cleanup                        (void);
    gint                sock_close                          (SockInfo *sock);
    SockInfo *          sock_connect                        (const gchar *hostname,
                                                             gushort port);
    gint                sock_connect_async                  (const gchar *hostname,
                                                             gushort port,
                                                             SockConnectFunc func,
                                                             gpointer data);
    gint                sock_connect_async_cancel           (gint id);
    gint                sock_getline                        (SockInfo *sock,
                                                             gchar **line);
    gint                sock_gets                           (SockInfo *sock,
                                                             gchar *buf,
                                                             gint len);
    gboolean            sock_has_read_data                  (SockInfo *sock);
    gboolean            sock_is_nonblocking_mode            (SockInfo *sock);
    gint                sock_peek                           (SockInfo *sock,
                                                             gchar *buf,
                                                             gint len);
    gint                sock_printf                         (SockInfo *sock,
                                                             const gchar *format,
                                                             ...);
    gint                sock_puts                           (SockInfo *sock,
                                                             const gchar *buf);
    gint                sock_read                           (SockInfo *sock,
                                                             gchar *buf,
                                                             gint len);
    gint                sock_set_io_timeout                 (guint sec);
    gint                sock_set_nonblocking_mode           (SockInfo *sock,
                                                             gboolean nonblock);
    gint                sock_write                          (SockInfo *sock,
                                                             const gchar *buf,
                                                             gint len);
    gint                sock_write_all                      (SockInfo *sock,
                                                             const gchar *buf,
                                                             gint len);
    gint                socket_init                         (const gchar *instance_name,
                                                             const gchar *config_dir,
                                                             gboolean *exists);

## Description

## Details

### enum ConnectionState

    typedef enum {
    	CONN_READY,
    	CONN_LOOKUPSUCCESS,
    	CONN_ESTABLISHED,
    	CONN_LOOKUPFAILED,
    	CONN_FAILED
    } ConnectionState;

### SockConnectFunc ()

    gint                (*SockConnectFunc)                  (SockInfo *sock,
                                                             gpointer data);

### SockFunc ()

    gboolean            (*SockFunc)                         (SockInfo *sock,
                                                             GIOCondition condition,
                                                             gpointer data);

### struct SockInfo

    struct SockInfo {
    	gint sock;
    	GIOChannel *sock_ch;

    	gchar *hostname;
    	gushort port;
    	ConnectionState state;
    	gboolean nonblock;
    	gpointer data;

    	SockFunc callback;
    	GIOCondition condition;
    };

### fd_accept ()

    gint                fd_accept                           (gint sock);

### fd_close ()

    gint                fd_close                            (gint sock);

### fd_connect_inet ()

    gint                fd_connect_inet                     (gushort port);

### fd_connect_unix ()

    gint                fd_connect_unix                     (const gchar *path);

### fd_getline ()

    gint                fd_getline                          (gint sock,
                                                             gchar **line);

### fd_gets ()

    gint                fd_gets                             (gint sock,
                                                             gchar *buf,
                                                             gint len);

### fd_open_inet ()

    gint                fd_open_inet                        (gushort port);

### fd_open_unix ()

    gint                fd_open_unix                        (const gchar *path);

### fd_read ()

    gint                fd_read                             (gint sock,
                                                             gchar *buf,
                                                             gint len);

### fd_write ()

    gint                fd_write                            (gint sock,
                                                             const gchar *buf,
                                                             gint len);

### fd_write_all ()

    gint                fd_write_all                        (gint sock,
                                                             const gchar *buf,
                                                             gint len);

### my_gethostbyname ()

    struct hostent *    my_gethostbyname                    (const gchar *hostname);

### send_open_command ()

    void                send_open_command                   (gint sock,
                                                             const gchar *command,
                                                             gchar **args);

### sock_add_watch ()

    guint               sock_add_watch                      (SockInfo *sock,
                                                             GIOCondition condition,
                                                             SockFunc func,
                                                             gpointer data);

### sock_cleanup ()

    gint                sock_cleanup                        (void);

### sock_close ()

    gint                sock_close                          (SockInfo *sock);

### sock_connect ()

    SockInfo *          sock_connect                        (const gchar *hostname,
                                                             gushort port);

### sock_connect_async ()

    gint                sock_connect_async                  (const gchar *hostname,
                                                             gushort port,
                                                             SockConnectFunc func,
                                                             gpointer data);

### sock_connect_async_cancel ()

    gint                sock_connect_async_cancel           (gint id);

### sock_getline ()

    gint                sock_getline                        (SockInfo *sock,
                                                             gchar **line);

### sock_gets ()

    gint                sock_gets                           (SockInfo *sock,
                                                             gchar *buf,
                                                             gint len);

### sock_has_read_data ()

    gboolean            sock_has_read_data                  (SockInfo *sock);

### sock_is_nonblocking_mode ()

    gboolean            sock_is_nonblocking_mode            (SockInfo *sock);

### sock_peek ()

    gint                sock_peek                           (SockInfo *sock,
                                                             gchar *buf,
                                                             gint len);

### sock_printf ()

    gint                sock_printf                         (SockInfo *sock,
                                                             const gchar *format,
                                                             ...);

### sock_puts ()

    gint                sock_puts                           (SockInfo *sock,
                                                             const gchar *buf);

### sock_read ()

    gint                sock_read                           (SockInfo *sock,
                                                             gchar *buf,
                                                             gint len);

### sock_set_io_timeout ()

    gint                sock_set_io_timeout                 (guint sec);

### sock_set_nonblocking_mode ()

    gint                sock_set_nonblocking_mode           (SockInfo *sock,
                                                             gboolean nonblock);

### sock_write ()

    gint                sock_write                          (SockInfo *sock,
                                                             const gchar *buf,
                                                             gint len);

### sock_write_all ()

    gint                sock_write_all                      (SockInfo *sock,
                                                             const gchar *buf,
                                                             gint len);

### socket_init ()

    gint                socket_init                         (const gchar *instance_name,
                                                             const gchar *config_dir,
                                                             gboolean *exists);