# inetsocket.h File Reference

This file contains sockets and socket sets. More...

`#include <gwenhywfar/gwenhywfarapi.h>`
`#include "gwenhywfar/error.h"`
`#include <gwenhywfar/inetaddr.h>`

Go to the source code of this file.

## Error Codes

#define | GWEN_SOCKET_ERROR_ABORTED (-8)
#define | GWEN_SOCKET_ERROR_BAD_SOCKETTYPE (-1)
#define | GWEN_SOCKET_ERROR_BROKEN_PIPE (-9)
#define | GWEN_SOCKET_ERROR_IN_PROGRESS (-4)
#define | GWEN_SOCKET_ERROR_INTERRUPTED (-6)
#define | GWEN_SOCKET_ERROR_NOT_OPEN (-2)
#define | GWEN_SOCKET_ERROR_STARTUP (-5)
#define | GWEN_SOCKET_ERROR_TIMEOUT (-3)
#define | GWEN_SOCKET_ERROR_TYPE "Socket"
#define | GWEN_SOCKET_ERROR_UNSUPPORTED (-7)

## Connecting and Disconnecting

These functions allow active and passive connections to other hosts.
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Accept (GWEN_SOCKET *sp, GWEN_INETADDRESS **addr, GWEN_SOCKET **newsock)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Accept_Wait (GWEN_SOCKET *sp, GWEN_INETADDRESS **addr, GWEN_SOCKET **newsock, int timeout)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Bind (GWEN_SOCKET *sp, const GWEN_INETADDRESS *addr)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Connect (GWEN_SOCKET *sp, const GWEN_INETADDRESS *addr)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Connect_Wait (GWEN_SOCKET *sp, const GWEN_INETADDRESS *addr, int timeout)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Listen (GWEN_SOCKET *sp, int backlog)

## Creation and Destruction

GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Close (GWEN_SOCKET *sp)
GWENHYWFAR_API void | GWEN_Socket_free (GWEN_SOCKET *sp)
GWENHYWFAR_API GWEN_SOCKET * | GWEN_Socket_new (GWEN_SOCKETTYPE socketType)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Open (GWEN_SOCKET *sp)

## Informational Functions

These functions return some usefull information about sockets or connections.
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_GetPeerAddr (GWEN_SOCKET *sp, GWEN_INETADDRESS **addr)
GWENHYWFAR_API GWEN_SOCKETTYPE | GWEN_Socket_GetSocketType (GWEN_SOCKET *sp)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Select (GWEN_SOCKETSET *rs, GWEN_SOCKETSET *ws, GWEN_SOCKETSET *xs, int timeout)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_WaitForRead (GWEN_SOCKET *sp, int timeout)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_WaitForWrite (GWEN_SOCKET *sp, int timeout)

## Socket Settings Functions

These functions manipulate settings on a socket.
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_GetSocketError (GWEN_SOCKET *sp)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_SetBlocking (GWEN_SOCKET *sp, int fl)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_SetBroadcast (GWEN_SOCKET *sp, int fl)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_SetReuseAddress (GWEN_SOCKET *sp, int fl)

## Data Exchange Functions

These functions handle exchange of data with other hosts via the Internet Protocol.
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Read (GWEN_SOCKET *sp, char *buffer, int *bsize)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Read_Wait (GWEN_SOCKET *sp, char *buffer, int *bsize, int timeout, int force)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_ReadFrom (GWEN_SOCKET *sp, GWEN_INETADDRESS **addr, char *buffer, int *bsize)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Write (GWEN_SOCKET *sp, const char *buffer, int *bsize)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_Write_Wait (GWEN_SOCKET *sp, const char *buffer, int *bsize, int timeout, int force)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_Socket_WriteTo (GWEN_SOCKET *sp, const GWEN_INETADDRESS *addr, const char *buffer, int *bsize)

## Add, remove, check sockets

These functions allow adding and removing sockets to/from a socket set as well as checking whether a specific socket is part of a socket set.
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_SocketSet_AddSocket (GWEN_SOCKETSET *ssp, const GWEN_SOCKET *sp)
GWENHYWFAR_API int | GWEN_SocketSet_GetSocketCount (GWEN_SOCKETSET *ssp)
GWENHYWFAR_API int | GWEN_SocketSet_HasSocket (GWEN_SOCKETSET *ssp, const GWEN_SOCKET *sp)
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_SocketSet_RemoveSocket (GWEN_SOCKETSET *ssp, const GWEN_SOCKET *sp)

## Creation and destruction

These functions initialize and de-initialize socket sets. A socket set is a group of sockets. They are used for the function GWEN_Socket_Select.
GWENHYWFAR_API GWEN_ERRORCODE | GWEN_SocketSet_Clear (GWEN_SOCKETSET *ssp)
GWENHYWFAR_API void | GWEN_SocketSet_free (GWEN_SOCKETSET *ssp)
GWENHYWFAR_API GWEN_SOCKETSET * | GWEN_SocketSet_new ()

## Typedefs

typedef GWEN_SOCKETSTRUCT | GWEN_SOCKET
typedef GWEN_SOCKETSETSTRUCT | GWEN_SOCKETSET

## Enumerations

enum | GWEN_SOCKETTYPE { GWEN_SocketTypeTCP = 1, GWEN_SocketTypeUDP, GWEN_SocketTypeRAW, GWEN_SocketTypeUnix }

## Detailed Description

This file contains sockets and socket sets.