nanohttp-socket.h File Reference

Go to the source code of this file.

Classes

struct  hsocket_t

Defines

#define HSOCKET_ERROR   1000
#define HSOCKET_ERROR_CREATE   (HSOCKET_ERROR + 1)
#define HSOCKET_ERROR_GET_HOSTNAME   (HSOCKET_ERROR + 2)
#define HSOCKET_ERROR_CONNECT   (HSOCKET_ERROR + 3)
#define HSOCKET_ERROR_SEND   (HSOCKET_ERROR + 4)
#define HSOCKET_ERROR_RECEIVE   (HSOCKET_ERROR + 5)
#define HSOCKET_ERROR_BIND   (HSOCKET_ERROR + 6)
#define HSOCKET_ERROR_LISTEN   (HSOCKET_ERROR + 7)
#define HSOCKET_ERROR_ACCEPT   (HSOCKET_ERROR + 8)
#define HSOCKET_ERROR_NOT_INITIALIZED   (HSOCKET_ERROR + 9)
#define HSOCKET_ERROR_IOCTL   (HSOCKET_ERROR + 10)
#define HSOCKET_ERROR_SSLCLOSE   (HSOCKET_ERROR + 11)
#define HSOCKET_ERROR_SSLCTX   (HSOCKET_ERROR + 11)

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)


Define Documentation

#define HSOCKET_ERROR_SSLCLOSE   (HSOCKET_ERROR + 11)
 

Todo:
move the next two items to nanohttp-ssl.h

#define HSOCKET_ERROR_SSLCTX   (HSOCKET_ERROR + 11)
 


Function Documentation

herror_t hsocket_accept struct hsocket_t sock,
struct hsocket_t dest
 

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
 

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  ) 
 

e Close a socket connection.

Parameters:
sock the socket to close

void hsocket_free struct hsocket_t sock  ) 
 

Destroys and releases a given socket.

Parameters:
sock the socket to destroy

int hsocket_get_timeout void   ) 
 

Get the socket read/write timeout.

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

herror_t hsocket_init struct hsocket_t sock  ) 
 

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  ) 
 

Set 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   ) 
 

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

See also:
hssl_module_destroy

herror_t hsocket_module_init int  argc,
char **  argv
 

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

Returns:
This function should always return H_OK.

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

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
 

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
 

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
 

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  ) 
 

Set the socket read/write timeout.

Parameters:
secs Timeout in seconds.
See also:
hsocket_get_timeout


Generated on Thu Jan 25 23:36:00 2007 for csoap by  doxygen 1.4.6