MOD_IOLAYER

Modules

 MOD_IOLAYER_BUFFERED
 MOD_IOLAYER_FILE
 MOD_IOLAYER_HTTP
 MOD_IOLAYER_MEMORY
 MOD_IOLAYER_SOCKET

Typedefs

typedef struct GWEN_IO_LAYER GWEN_IO_LAYER

Enumerations

enum  GWEN_IO_LAYER_STATUS {
  GWEN_Io_Layer_StatusUnknown = -1, GWEN_Io_Layer_StatusUnconnected = 0, GWEN_Io_Layer_StatusConnecting, GWEN_Io_Layer_StatusConnected,
  GWEN_Io_Layer_StatusDisconnecting, GWEN_Io_Layer_StatusDisconnected, GWEN_Io_Layer_StatusListening, GWEN_Io_Layer_StatusDisabled
}
enum  GWEN_IO_LAYER_WORKRESULT { GWEN_Io_Layer_WorkResultError = -1, GWEN_Io_Layer_WorkResultOk = 0, GWEN_Io_Layer_WorkResultBlocking }

Informational Functions



GWENHYWFAR_API void GWEN_Io_Layer_AddFlags (GWEN_IO_LAYER *io, uint32_t f)
GWENHYWFAR_API void GWEN_Io_Layer_ClearIncomingLayers (GWEN_IO_LAYER *io)
GWENHYWFAR_API GWEN_IO_LAYERGWEN_Io_Layer_FindBaseLayerByType (GWEN_IO_LAYER *io, const char *tname)
GWENHYWFAR_API GWEN_IO_LAYERGWEN_Io_Layer_GetBaseLayer (GWEN_IO_LAYER *io)
GWENHYWFAR_API uint32_t GWEN_Io_Layer_GetFlags (const GWEN_IO_LAYER *io)
GWENHYWFAR_API GWEN_IO_LAYERGWEN_Io_Layer_GetNextIncomingLayer (GWEN_IO_LAYER *io)
GWENHYWFAR_API GWEN_IO_LAYER_STATUS GWEN_Io_Layer_GetStatus (const GWEN_IO_LAYER *io)
GWENHYWFAR_API void GWEN_Io_Layer_SetFlags (GWEN_IO_LAYER *io, uint32_t f)
GWENHYWFAR_API void GWEN_Io_Layer_SubFlags (GWEN_IO_LAYER *io, uint32_t f)

Request Handling



GWENHYWFAR_API int GWEN_Io_Layer_AddRequest (GWEN_IO_LAYER *io, GWEN_IO_REQUEST *r)
GWENHYWFAR_API int GWEN_Io_Layer_DelRequest (GWEN_IO_LAYER *io, GWEN_IO_REQUEST *r)
GWENHYWFAR_API int GWEN_Io_Layer_HasWaitingRequests (GWEN_IO_LAYER *io)

Object Management



GWENHYWFAR_API void GWEN_Io_Layer_Attach (GWEN_IO_LAYER *io)
GWENHYWFAR_API void GWEN_Io_Layer_free (GWEN_IO_LAYER *io)

Convenience Functions

Internally all IO layers work with IO requests. However, some users don't want to handle requests by themselves. Those users can use the functions of this group which internally again setup and dispatch IO requests.



GWENHYWFAR_API int GWEN_Io_Layer_Connect (GWEN_IO_LAYER *io, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_ConnectRecursively (GWEN_IO_LAYER *io, GWEN_IO_LAYER *stopAtLayer, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_Disconnect (GWEN_IO_LAYER *io, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_DisconnectRecursively (GWEN_IO_LAYER *io, GWEN_IO_LAYER *stopAtLayer, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_FlushRecursively (GWEN_IO_LAYER *io, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_Listen (GWEN_IO_LAYER *io)
GWENHYWFAR_API int GWEN_Io_Layer_ListenRecursively (GWEN_IO_LAYER *io, GWEN_IO_LAYER *stopAtLayer)
GWENHYWFAR_API int GWEN_Io_Layer_ReadBytes (GWEN_IO_LAYER *io, uint8_t *buffer, uint32_t size, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_ReadPacket (GWEN_IO_LAYER *io, uint8_t *buffer, uint32_t size, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_ReadPacketToBuffer (GWEN_IO_LAYER *io, GWEN_BUFFER *buf, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_ReadToBufferUntilEof (GWEN_IO_LAYER *io, GWEN_BUFFER *buf, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_WriteBytes (GWEN_IO_LAYER *io, const uint8_t *buffer, uint32_t size, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_WriteChar (GWEN_IO_LAYER *io, char c, uint32_t flags, uint32_t guiid, int msecs)
GWENHYWFAR_API int GWEN_Io_Layer_WriteString (GWEN_IO_LAYER *io, const char *buffer, uint32_t flags, uint32_t guiid, int msecs)

Flags For IO Layers

You can set these flags using GWEN_Io_Layer_SetFlags() or GWEN_Io_Layer_AddFlags().



#define GWEN_IO_LAYER_FLAGS_DONTCLOSE   0x40000000
#define GWEN_IO_LAYER_FLAGS_PASSIVE   0x10000000
#define GWEN_IO_LAYER_FLAGS_PKG_BASED   0x20000000
#define GWEN_IO_LAYER_FLAGS_REGISTERED   0x80000000
#define GWEN_IO_LAYER_FLAGS_TAKEOVER   0x01000000

Detailed Description

This module introduces IO layer objects which are used to perform input/output operations. IO layers can be stacked in order to create IO layer chains. There are a few io layer types which work as endpoints (i.e. they have no base layer underneath them but rather perform direct input/output operations such as reading from a file, writing to a network socket etc).

Most io layer objects operate over base io layers, e.g. the HTTP io layer can work directly over network socket io layers or over an SSL layer which in turn operates over a network socket io layer.

All toplevel io layers (i.e. those which do not serve as base layers to others) must be registered via GWEN_Io_Manager_RegisterLayer() to allow Gwenhywfar to manage them.

This module is based on io requests, e.g. to read some bytes from from an io layer object an io request is created and enqueued with the io layer object. IO requests may have a callback function which is called when the request has been finished (either because the requested operations has been performed or because the request was aborted).

This module also contains convenience functions which provide a simpler API for io operations thereby hiding the internal io request usage.


Define Documentation

#define GWEN_IO_LAYER_FLAGS_DONTCLOSE   0x40000000

If this flag is set then the given file descriptor will never be closed. However, upon receiption of the request GWEN_Io_Request_TypeDisconnect the file will be made unaccessibly by this module.

Definition at line 108 of file iolayer.h.

Referenced by GWEN_DB_ReadFromFd(), GWEN_DB_WriteToFd(), GWEN_Io_LayerFile_AddRequest(), GWEN_Io_LayerFile_freeData(), GWEN_Io_LayerSocket_AddRequest(), GWEN_Io_LayerSocket_DelRequest(), and GWEN_Io_LayerSocket_freeData().

#define GWEN_IO_LAYER_FLAGS_PASSIVE   0x10000000

If this flag is set then this connection is a passive one (e.g. other hosts/processes actively connect to this one)

Definition at line 98 of file iolayer.h.

Referenced by GWEN_Io_LayerBuffered_WorkOnReadRequest(), GWEN_Io_LayerHttp_AddRequest(), GWEN_Io_LayerHttp_WorkOnRequests(), GWEN_Io_LayerSocket_AddRequest(), GWEN_Io_LayerSocket_CheckForIncoming(), GWEN_Io_LayerTls_Prepare(), and GWEN_Io_LayerTls_WorkOnRequests().

#define GWEN_IO_LAYER_FLAGS_PKG_BASED   0x20000000

If this flag is set then the io layer is packet based.

Definition at line 103 of file iolayer.h.

#define GWEN_IO_LAYER_FLAGS_REGISTERED   0x80000000
#define GWEN_IO_LAYER_FLAGS_TAKEOVER   0x01000000

If this flag is set then an object will take over the buffer given to the constructor. i.e. the buffer is only valid as long as the io layer exists.

Definition at line 92 of file iolayer.h.

Referenced by GWEN_Io_LayerMemory_freeData(), GWEN_Io_LayerMemory_fromString(), GWEN_Io_LayerSocket_CheckForIncoming(), and GWEN_Io_LayerSocket_freeData().


Typedef Documentation

typedef struct GWEN_IO_LAYER GWEN_IO_LAYER

Definition at line 55 of file iolayer.h.


Enumeration Type Documentation

Enumerator:
GWEN_Io_Layer_StatusUnknown 
GWEN_Io_Layer_StatusUnconnected 
GWEN_Io_Layer_StatusConnecting 
GWEN_Io_Layer_StatusConnected 
GWEN_Io_Layer_StatusDisconnecting 
GWEN_Io_Layer_StatusDisconnected 
GWEN_Io_Layer_StatusListening 
GWEN_Io_Layer_StatusDisabled 

Definition at line 67 of file iolayer.h.

Enumerator:
GWEN_Io_Layer_WorkResultError 
GWEN_Io_Layer_WorkResultOk 
GWEN_Io_Layer_WorkResultBlocking 

Definition at line 60 of file iolayer.h.


Function Documentation

GWENHYWFAR_API void GWEN_Io_Layer_AddFlags ( GWEN_IO_LAYER io,
uint32_t  f 
)
GWENHYWFAR_API int GWEN_Io_Layer_AddRequest ( GWEN_IO_LAYER io,
GWEN_IO_REQUEST r 
)

Adds a request to a given io layer.

Please note that some io layers handle requests directly within this function, so when it returns the given request has already been finished (and the request's finish handler has already been called if any).

If the io layer is unable to accept this request (e.g. because there are already too many requests enqueued) then it returns GWEN_ERROR_TRY_AGAIN thus indicating that you may try at a later time.

Please not that the request's finish handler (if any) is not called if GWEN_ERROR_TRY_AGAIN is returned here to allow to try again later to add the request.

Definition at line 309 of file iolayer.c.

References GWEN_ERROR_NOT_IMPLEMENTED, GWEN_Io_Request_SetBufferPos(), GWEN_Io_Request_SetIoLayer(), GWEN_Io_Request_SetResultCode(), GWEN_Io_Request_SetStatus(), and GWEN_Io_Request_StatusEnqueued.

Referenced by GWEN_Io_Layer__WaitForRequest(), GWEN_Io_LayerBuffered_ReadLineToBuffer(), GWEN_Io_LayerBuffered_TryFlush(), GWEN_Io_LayerBuffered_WorkOnReadRequest(), GWEN_Io_LayerCodec_EnsureReadOk(), GWEN_Io_LayerCodec_WorkOnOutRequests(), GWEN_Io_LayerHttp_WorkOnReadRequest1(), GWEN_Io_LayerHttp_WorkOnReadRequest2(), GWEN_Io_LayerHttp_WorkOnWriteRequest1(), GWEN_Io_LayerHttp_WorkOnWriteRequest2(), GWEN_Io_LayerPackets_WorkOnReadRequests(), and GWEN_Io_LayerPackets_WorkOnWriteRequests().

GWENHYWFAR_API void GWEN_Io_Layer_Attach ( GWEN_IO_LAYER io  ) 

Definition at line 61 of file iolayer.c.

Referenced by GWEN_Io_Layer_new().

GWENHYWFAR_API void GWEN_Io_Layer_ClearIncomingLayers ( GWEN_IO_LAYER io  ) 

Definition at line 139 of file iolayer.c.

GWENHYWFAR_API int GWEN_Io_Layer_Connect ( GWEN_IO_LAYER io,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)

This function only connects the given io layer, it doesn't care for the possibly available base layers.

Definition at line 456 of file iolayer.c.

References GWEN_Io_Layer__WaitForRequest(), GWEN_Io_Request_new(), GWEN_Io_Request_SetFlags(), GWEN_Io_Request_TypeConnect, and NULL.

Referenced by GWEN_Io_Layer_ConnectRecursively().

GWENHYWFAR_API int GWEN_Io_Layer_ConnectRecursively ( GWEN_IO_LAYER io,
GWEN_IO_LAYER stopAtLayer,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)

This function connects an io layer and all its base layers until the given layer has been reached (which is then not connected). The order of connecting all the layers in a chain is from the inner most base layer up to the outermost one. If an io layer along the chain already is connected then this function will not try to connect it again.

Definition at line 471 of file iolayer.c.

References GWEN_Io_Layer_Connect(), GWEN_Io_Layer_ConnectRecursively(), and GWEN_Io_Layer_StatusConnected.

Referenced by GWEN_HttpSession_ConnectionTest(), GWEN_HttpSession_SendPacket(), GWEN_Io_Layer_ConnectRecursively(), GWEN_IpcManager__SendMsg(), and GWEN_IpcManager__Work().

GWENHYWFAR_API int GWEN_Io_Layer_DelRequest ( GWEN_IO_LAYER io,
GWEN_IO_REQUEST r 
)

This function can be used to abort a request which has been added with GWEN_Io_Layer_AddRequest(). The request's finish handler is called from within this function (if the request really is enqueued with this io layer).

Definition at line 327 of file iolayer.c.

References GWEN_ERROR_NOT_IMPLEMENTED, GWEN_Io_Request_SetIoLayer(), and NULL.

Referenced by GWEN_Io_Layer__WaitForRequest(), GWEN_Io_LayerBuffered_AbortOutRequests(), GWEN_Io_LayerCodec_AbortOutRequests(), GWEN_Io_LayerCodec_AbortRequests(), GWEN_Io_LayerHttp_AbortOutRequests(), GWEN_Io_LayerPackets_Abort(), and GWEN_Io_LayerPackets_DelRequest().

GWENHYWFAR_API int GWEN_Io_Layer_Disconnect ( GWEN_IO_LAYER io,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API int GWEN_Io_Layer_DisconnectRecursively ( GWEN_IO_LAYER io,
GWEN_IO_LAYER stopAtLayer,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)

This function disconnects all io layers along a chain of io layers until the given layer is reached (which is then not disconnected). The order of disconnecting all the layers is from the given io layer downto the inner most io layer (i.e. the one which has no bas layer). If the flag GWEN_IO_REQUEST_FLAGS_FORCE is cleared then this function first tries to flush the given io layers and all layers below before disconnecting.

Definition at line 574 of file iolayer.c.

References DBG_INFO, GWEN_Io_Layer__DisconnectRecursively(), GWEN_Io_Layer_FlushRecursively(), GWEN_IO_REQUEST_FLAGS_FORCE, and GWEN_LOGDOMAIN.

Referenced by GWEN_DB_ReadFileAs(), GWEN_DB_ReadFromFd(), GWEN_DB_ReadFromString(), GWEN_DB_WriteToBuffer(), GWEN_DB_WriteToFd(), GWEN_DBIO_ExportToBuffer(), GWEN_DBIO_ExportToFile(), GWEN_DBIO_ImportFromFile(), GWEN_HttpSession_ConnectionTest(), GWEN_HttpSession_RecvPacket(), GWEN_HttpSession_SendPacket(), GWEN_IpcManager__Work(), GWEN_IpcManager_Disconnect(), GWEN_IpcManager_RemoveClient(), GWEN_XMLNode_toBuffer(), and GWEN_XMLNode_WriteFile().

GWENHYWFAR_API GWEN_IO_LAYER* GWEN_Io_Layer_FindBaseLayerByType ( GWEN_IO_LAYER io,
const char *  tname 
)

Compare the type name of the given io layer and all its base layers until one with the given type name is found.

Definition at line 97 of file iolayer.c.

Referenced by GWEN_HttpSession_ConnectionTest(), GWEN_HttpSession_SendPacket(), and GWEN_Io_LayerTls_WorkOnRequests().

GWENHYWFAR_API int GWEN_Io_Layer_FlushRecursively ( GWEN_IO_LAYER io,
uint32_t  guiid,
int  msecs 
)

This functions lets all io layers write any data from any internal buffer. It works its way down from the given io layer to its lowest base layer.

Definition at line 832 of file iolayer.c.

References DBG_INFO, GWEN_Io_Layer_WriteString(), GWEN_IO_REQUEST_FLAGS_FLUSH, and GWEN_LOGDOMAIN.

Referenced by GWEN_Io_Layer_DisconnectRecursively().

GWENHYWFAR_API void GWEN_Io_Layer_free ( GWEN_IO_LAYER io  ) 
GWENHYWFAR_API GWEN_IO_LAYER* GWEN_Io_Layer_GetBaseLayer ( GWEN_IO_LAYER io  ) 
GWENHYWFAR_API uint32_t GWEN_Io_Layer_GetFlags ( const GWEN_IO_LAYER io  ) 
GWENHYWFAR_API GWEN_IO_LAYER* GWEN_Io_Layer_GetNextIncomingLayer ( GWEN_IO_LAYER io  ) 
GWENHYWFAR_API GWEN_IO_LAYER_STATUS GWEN_Io_Layer_GetStatus ( const GWEN_IO_LAYER io  ) 
GWENHYWFAR_API int GWEN_Io_Layer_HasWaitingRequests ( GWEN_IO_LAYER io  ) 

Checks whether this io layer has any waiting incoming requests.

Returns:
0 no waiting requests, !=0 otherwise

Definition at line 340 of file iolayer.c.

References GWEN_ERROR_NOT_IMPLEMENTED.

GWENHYWFAR_API int GWEN_Io_Layer_Listen ( GWEN_IO_LAYER io  ) 

Definition at line 370 of file iolayer.c.

References GWEN_Io_Layer_SetStatus(), and GWEN_Io_Layer_StatusListening.

Referenced by GWEN_Io_Layer_ListenRecursively().

GWENHYWFAR_API int GWEN_Io_Layer_ListenRecursively ( GWEN_IO_LAYER io,
GWEN_IO_LAYER stopAtLayer 
)
GWENHYWFAR_API int GWEN_Io_Layer_ReadBytes ( GWEN_IO_LAYER io,
uint8_t *  buffer,
uint32_t  size,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API int GWEN_Io_Layer_ReadPacket ( GWEN_IO_LAYER io,
uint8_t *  buffer,
uint32_t  size,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API int GWEN_Io_Layer_ReadPacketToBuffer ( GWEN_IO_LAYER io,
GWEN_BUFFER buf,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API int GWEN_Io_Layer_ReadToBufferUntilEof ( GWEN_IO_LAYER io,
GWEN_BUFFER buf,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API void GWEN_Io_Layer_SetFlags ( GWEN_IO_LAYER io,
uint32_t  f 
)

Definition at line 166 of file iolayer.c.

GWENHYWFAR_API void GWEN_Io_Layer_SubFlags ( GWEN_IO_LAYER io,
uint32_t  f 
)
GWENHYWFAR_API int GWEN_Io_Layer_WriteBytes ( GWEN_IO_LAYER io,
const uint8_t *  buffer,
uint32_t  size,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API int GWEN_Io_Layer_WriteChar ( GWEN_IO_LAYER io,
char  c,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)
GWENHYWFAR_API int GWEN_Io_Layer_WriteString ( GWEN_IO_LAYER io,
const char *  buffer,
uint32_t  flags,
uint32_t  guiid,
int  msecs 
)

Generated on Sat Jan 2 09:32:39 2010 for gwenhywfar by  doxygen 1.6.1