Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

KSocket.h File Reference

Socket Management Functions. More...

#include "ktypes.h"

Defines

#define KSocket_new()   _KSocket_new (__K_FILE__, __K_LINE__)
 Allocates a KSocket structure.
#define KSocket_waitStatus(pSocket, eStatus)   _KSocket_waitStatus (pSocket, eStatus, __K_FILE__, __K_LINE__)
 Waits that a socket reaches a particular state. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". This function is blocking.
#define KSocket_waitStatusForTime(pSocket, eStatus, imsec)   _KSocket_waitStatusForTime(pSocket, eStatus, imsec, __K_FILE__, __K_LINE__)
 Waits that a socket reaches a particular state before time elapsed. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". If the time is elapsed before status changed, the following code is returned "KSOK_RET_TIMEOUT".
#define KSocket_readAll(pSocket, pBuffer, pReadBytes)   _KSocket_readAll(pSocket, pBuffer, pReadBytes, __K_FILE__, __K_LINE__)
 Reads data available in the socket.

Typedefs

typedef _KSocket KSocket
 Sockets.

Enumerations

enum  ESokStatus {
  KSOK_STATUS_NOT_INIT = 0x0001, KSOK_STATUS_WAIT_CONNECTION = 0x0002, KSOK_STATUS_WAIT_DISCONNECT = 0x0003, KSOK_STATUS_CONNECTED = 0x0004,
  KSOK_STATUS_DISCONNECTED = 0x0005, KSOK_STATUS_AVAILABLE_DATA = 0x0100, KSOK_STATUS_MASK = 0x00ff, KSOK_STATUS_SUBMASK = 0xff00
}
 Socket states. More...
enum  ESokRet {
  KSOK_RET_SUCCESS = 0, KSOK_RET_UNKNOWN_ERROR = 1, KSOK_RET_BAD_PARAMETERS = 2, KSOK_ADDR_NOT_FOUND = 3,
  KSOK_RET_DISCONNECTED = 4, KSOK_RET_BAD_STATUS = 5, KSOK_RET_TIMEOUT = 6, KSOK_RET_SEND_ECHEC = 7,
  KSOK_RET_NOT_INIT = 8
}
 Return codes. More...

Functions

KTL_API KSocket_KSocket_new (KString sFile, KInt32 iLine)
 Allocates a KSocket structure.
KTL_API void KSocket_delete (KSocket **pSocket)
 Deletes a KSocket structure.
KTL_API ESokRet KSocket_connect (KSocket *pSocket, KCString sServer, KUInt16 iPort)
 Connects a socket to a server.
KTL_API ESokRet KSocket_disconnect (KSocket *pSocket)
 Socket disconnection.
KTL_API KCString KSocket_getServer (KSocket *pSocket)
 Returns the server associated to the given socket.
KTL_API KUInt16 KSocket_getPort (KSocket *pSocket)
 Returns the port associated to the given socket.
KTL_API ESokStatus KSocket_getStatus (KSocket *pSocket)
 Returns the current state of a socket.
KTL_API ESokRet _KSocket_waitStatus (KSocket *pSocket, ESokStatus eStatus, KString sFile, KInt32 iLine)
 Waits that a socket reaches a particular state. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". This function is blocking.
KTL_API ESokRet _KSocket_waitStatusForTime (KSocket *pSocket, ESokStatus eStatus, KUInt32 imsec, KString sFile, KInt32 iLine)
 Waits that a socket reaches a particular state before time elapsed. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". If the time is elapsed before status changed, the following code is returned "KSOK_RET_TIMEOUT".
KTL_API KUInt64 KSocket_availableBytes (KSocket *pSocket)
 Gets the bytes number of available data in read mode.
KTL_API ESokRet _KSocket_readAll (KSocket *pSocket, KUChar **pBuffer, KUInt64 *pReadBytes, KString sFile, KInt32 iLine)
 Reads data available in the socket.
KTL_API ESokRet KSocket_readBytes (KSocket *pSocket, KUChar *pBuffer, KUInt64 iBytesToRead, KUInt64 *pReadBytes)
 Reads a maximum bytes number of data.
KTL_API ESokRet KSocket_send (KSocket *pSocket, const KUChar *pBuffer, KUInt64 iBytesToSend)
 Sending data. Blocking function.
KTL_API ESokRet KSocket_testConnection (KSocket *pSocket, KUInt32 iMSec)
 A function for testing connexion.


Detailed Description

Socket Management Functions.

Version:
KToolLib-1.0
Author:
Fabien Gallot
Date:
31/07/2009
Note:
Copyright © 2008-2010 iKlax Media SAS (www.iklaxmedia.com). All rights reserved.

Define Documentation

 
#define KSocket_new  )     _KSocket_new (__K_FILE__, __K_LINE__)
 

Allocates a KSocket structure.

Returns:
the pointer to the KSocket structure correctly initialized if successful otherwise knull

#define KSocket_readAll pSocket,
pBuffer,
pReadBytes   )     _KSocket_readAll(pSocket, pBuffer, pReadBytes, __K_FILE__, __K_LINE__)
 

Reads data available in the socket.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
pBuffer the pointers to unsigned characters where data is stored
pReadBytes the bytes maximum number to be read
Returns:
an ESokRet code

#define KSocket_waitStatus pSocket,
eStatus   )     _KSocket_waitStatus (pSocket, eStatus, __K_FILE__, __K_LINE__)
 

Waits that a socket reaches a particular state. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". This function is blocking.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
eStatus the socket state to be waited for
Returns:
an ESokRet code

#define KSocket_waitStatusForTime pSocket,
eStatus,
imsec   )     _KSocket_waitStatusForTime(pSocket, eStatus, imsec, __K_FILE__, __K_LINE__)
 

Waits that a socket reaches a particular state before time elapsed. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". If the time is elapsed before status changed, the following code is returned "KSOK_RET_TIMEOUT".

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
eStatus the socket state to be waited for
imsec the maximum number of milliseconds to be waited for
Returns:
an ESokRet code


Enumeration Type Documentation

enum ESokRet
 

Return codes.

Enumeration values:
KSOK_RET_SUCCESS  Task correctly realized.
KSOK_RET_UNKNOWN_ERROR  Unknown error.
KSOK_RET_BAD_PARAMETERS  Wrong parameters.
KSOK_ADDR_NOT_FOUND  URL not found.
KSOK_RET_DISCONNECTED  Server disconnection.
KSOK_RET_BAD_STATUS  Socket incompatible state with task.
KSOK_RET_TIMEOUT  Timeout.
KSOK_RET_SEND_ECHEC  Sending data failed.
KSOK_RET_NOT_INIT  Not initialized socket.

enum ESokStatus
 

Socket states.

Enumeration values:
KSOK_STATUS_NOT_INIT  Non initialized socket. A socket should be in this state after a call to the "KSocket_new" function.
KSOK_STATUS_WAIT_CONNECTION  The socket is waiting for connexion.
KSOK_STATUS_WAIT_DISCONNECT  The socket is waiting for disconnection.
KSOK_STATUS_CONNECTED  Socket connected to a server.
KSOK_STATUS_DISCONNECTED  Socket disconnected.
KSOK_STATUS_AVAILABLE_DATA  Data available for read operations.
KSOK_STATUS_MASK  Mask used for the general status.
KSOK_STATUS_SUBMASK  Mask used for sub-status.


Function Documentation

KTL_API KSocket* _KSocket_new KString  sFile,
KInt32  iLine
 

Allocates a KSocket structure.

Parameters:
sFile the file name where this function is called
iLine the line number where this function is called
Returns:
the pointer to the KSocket structure correctly initialized if successful otherwise knull

KTL_API ESokRet _KSocket_readAll KSocket pSocket,
KUChar **  pBuffer,
KUInt64 pReadBytes,
KString  sFile,
KInt32  iLine
 

Reads data available in the socket.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
pBuffer the pointers to unsigned characters where data is stored
pReadBytes the bytes maximum number to be read
sFile the file name where this function is called
iLine the line number where this function is called
Returns:
an ESokRet code

KTL_API ESokRet _KSocket_waitStatus KSocket pSocket,
ESokStatus  eStatus,
KString  sFile,
KInt32  iLine
 

Waits that a socket reaches a particular state. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". This function is blocking.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
eStatus the socket state to be waited for
sFile the file name where this function is called
iLine the line number where this function is called
Returns:
an ESokRet code

KTL_API ESokRet _KSocket_waitStatusForTime KSocket pSocket,
ESokStatus  eStatus,
KUInt32  imsec,
KString  sFile,
KInt32  iLine
 

Waits that a socket reaches a particular state before time elapsed. In disconnection cases, the following code is returned "KSOK_RET_DISCONNECTED". If the time is elapsed before status changed, the following code is returned "KSOK_RET_TIMEOUT".

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
eStatus the socket state to be waited for
imsec the maximum number of milliseconds to be waited for
sFile the file name where this function is called
iLine the line number where this function is called
Returns:
an ESokRet code

KTL_API KUInt64 KSocket_availableBytes KSocket pSocket  ) 
 

Gets the bytes number of available data in read mode.

Parameters:
pSocket the pointer to the KSocket structure correcly initialized
Returns:
the bytes maximum number of available data in read mode if successful otherwise 0

KTL_API ESokRet KSocket_connect KSocket pSocket,
KCString  sServer,
KUInt16  iPort
 

Connects a socket to a server.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
sServer the string that identifies the server to be connected
iPort the port number used for the connexion
Returns:
an ESokRet code

KTL_API void KSocket_delete KSocket **  pSocket  ) 
 

Deletes a KSocket structure.

Parameters:
pSocket the pointers to the KSocket structure to be deleted

KTL_API ESokRet KSocket_disconnect KSocket pSocket  ) 
 

Socket disconnection.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
Returns:
an ESokRet code

KTL_API KUInt16 KSocket_getPort KSocket pSocket  ) 
 

Returns the port associated to the given socket.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
Returns:
the port number of the socket if successful otherwise 0

KTL_API KCString KSocket_getServer KSocket pSocket  ) 
 

Returns the server associated to the given socket.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
Returns:
the string that identifies the server if successful otherwise knull

KTL_API ESokStatus KSocket_getStatus KSocket pSocket  ) 
 

Returns the current state of a socket.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
Returns:
an ESokStatus code

KTL_API ESokRet KSocket_readBytes KSocket pSocket,
KUChar pBuffer,
KUInt64  iBytesToRead,
KUInt64 pReadBytes
 

Reads a maximum bytes number of data.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
pBuffer the pointers to unsigned characters where data is stored
iBytesToRead the bytes maximum number to be read
pReadBytes the pointer to the real number of read bytes
Returns:
an ESokRet

KTL_API ESokRet KSocket_send KSocket pSocket,
const KUChar pBuffer,
KUInt64  iBytesToSend
 

Sending data. Blocking function.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
pBuffer the pointers to unsigned characters where data is stored
iBytesToSend the bytes number of data to be sent
Returns:
an ESokRet code

KTL_API ESokRet KSocket_testConnection KSocket pSocket,
KUInt32  iMSec
 

A function for testing connexion.

Parameters:
pSocket the pointer to the KSocket structure correctly initialized
iMSec the maximum number of milliseconds to be waited for
Returns:
an ESokRet code


Generated on Tue Mar 9 10:49:30 2010 for iKlax Tools Library (KToolLib) by doxygen 1.3.8