C library for SOAP (Simple Object Access Protocol)


Socket wrapper
[nanoHTTP]


Modules

 Generic socket errors

Data Structures

struct  hsocket_t

Functions

herror_t hsocket_module_init (int argc, char **argv)
void hsocket_module_destroy (void)
herror_t hsocket_init (struct hsocket_t *sock)
void hsocket_free (struct hsocket_t *sock)
herror_t hsocket_open (struct hsocket_t *sock, const char *host, int port, int ssl)
void hsocket_close (struct hsocket_t *sock)
herror_t hsocket_bind (struct hsocket_t *sock, unsigned short port)
herror_t hsocket_listen (struct hsocket_t *sock)
herror_t hsocket_accept (struct hsocket_t *sock, struct hsocket_t *dest)
herror_t hsocket_send (struct hsocket_t *sock, const unsigned char *bytes, int size)
herror_t hsocket_send_string (struct hsocket_t *sock, const char *str)
int hsocket_select_recv (int sock, char *buf, size_t len)
herror_t hsocket_recv (struct hsocket_t *sock, unsigned char *buffer, int size, int force, int *len)
int hsocket_get_timeout (void)
void hsocket_set_timeout (int secs)

Function Documentation

herror_t hsocket_accept ( struct hsocket_t *  sock,
struct hsocket_t *  dest 
)

This function accepts an incoming socket request. Note that this function will not return until a socket connection is ready.

Parameters:
sock the socket which listents to a port
dest the destination socket which will be created
Returns:
H_OK if success. One of the followings if fails:
  • HSOCKET_ERROR_NOT_INITIALIZED
  • HSOCKET_ERROR_ACCEPT

herror_t hsocket_bind ( struct hsocket_t *  sock,
unsigned short  port 
)

This function binds a socket to a given port number. After bind you can call hsocket_listen() to listen to the port.

Parameters:
sock socket to use.
port port number to bind to
Returns:
H_OK on success. One of the followings if fails:
  • HSOCKET_ERROR_CREATE
  • HSOCKET_ERROR_BIND
See also:
hsocket_listen()

void hsocket_close ( struct hsocket_t *  sock  ) 

This function closes a socket connection.

Parameters:
sock the socket to close

void hsocket_free ( struct hsocket_t *  sock  ) 

This function destroys and releases a given socket.

Parameters:
sock the socket to destroy

int hsocket_get_timeout ( void   ) 

This function gets the socket read/write timeout.

Returns:
The socket timeout in seconds.
See also:
hsocket_set_timeout()

herror_t hsocket_init ( struct hsocket_t *  sock  ) 

This function initializes a given socket object. This function (or hsokcet_init_ssl) should be called for every socket before using it.

Parameters:
sock the destination socket to initialize.
Returns:
This function should always return H_OK.
See also:
hssl_module_init()

herror_t hsocket_listen ( struct hsocket_t *  sock  ) 

This function sets the socket to the listen mode. You must bind the socket to a port with hsocket_bind() before you can listen to the port.

Parameters:
sock the socket to use
Returns:
H_OK if success. One of the followings if fails:<
  • HSOCKET_ERROR_NOT_INITIALIZED
  • HSOCKET_ERROR_LISTEN

void hsocket_module_destroy ( void   ) 

This function destroys the socket modul. This should be called after finishing an application.

See also:
hssl_module_init()

herror_t hsocket_module_init ( int  argc,
char **  argv 
)

This function iitializes the socket modul. This should be called only once for an application.

Returns:
This function should always return H_OK.
See also:
hssl_module_destroy()

herror_t hsocket_open ( struct hsocket_t *  sock,
const char *  host,
int  port,
int  ssl 
)

This function connects to a given host. The hostname can be an IP number or a humen readable hostname.

Parameters:
sock the destonation socket object to use
host hostname
port port number to connect to
ssl whether to open a SSL connection
Returns:
H_OK if success. One of the followings if fails:
  • HSOCKET_ERROR_CREATE
  • HSOCKET_ERROR_GET_HOSTNAME
  • HSOCKET_ERROR_CONNECT

herror_t hsocket_recv ( struct hsocket_t *  sock,
unsigned char *  buffer,
int  size,
int  force,
int *  len 
)

This function reads data from the socket.

Parameters:
sock the socket to read data from
buffer the buffer to use to save the readed bytes
size the maximum size of bytes to read
force if force is 1 then hsocket_read() will wait until maximum size of bytes (size parameter) was readed. Otherwise this function will not wait and will return with the bytes quequed on the socket.
Returns:
This function will return -1 if an read error was occured. Otherwise the return value is the size of bytes readed from the socket.

int hsocket_select_recv ( int  sock,
char *  buf,
size_t  len 
)

herror_t hsocket_send ( struct hsocket_t *  sock,
const unsigned char *  bytes,
int  size 
)

This function sends data throught the socket.

Parameters:
sock the socket to use to send the data
bytes bytes to send
size size of memory to sent pointed by bytes.
Returns:
H_OK if success. One of the followings if fails:
  • HSOCKET_ERROR_NOT_INITIALIZED
  • HSOCKET_ERROR_SEND

herror_t hsocket_send_string ( struct hsocket_t *  sock,
const char *  str 
)

This function sends a string throught the socket

Parameters:
sock the socket to use to send the data
str the null terminated string to sent
Returns:
H_OK on success. One of the followings if fails:
  • HSOCKET_ERROR_NOT_INITIALIZED
  • HSOCKET_ERROR_SEND

void hsocket_set_timeout ( int  secs  ) 

This function sets the socket read/write timeout.

Parameters:
secs Timeout in seconds.
See also:
hsocket_get_timeout()


csoap project homepage: http://csoap.sourceforge.net