Barracuda Application Server C/C++ Reference
NO

Detailed Description

Socket Library.


The Socket Example Lib (selib.h/selib.c) is a basic module that provides a platform agnostic socket API.

Collaboration diagram for selib:

Macros

#define INFINITE_TMO   (~((U32)0))
 Infinite wait time option for socket read functions.
 
#define SOCKET   int
 The SOCKET object/handle is an 'int' when using a BSD compatible TCP/IP stack. More...
 

Functions

int se_connect (SOCKET *sock, const char *address, U16 port)
 Initializes a SOCKET object connected to a remote host/address at a given port. More...
 
int se_bind (SOCKET *sock, U16 port)
 Initializes a SOCKET object bound to a local port, ready to accept client connections. More...
 
int se_accept (SOCKET **listenSock, U32 timeout, SOCKET **outSock)
 Waits for remote connections on the server SOCKET object 'listenSock', initialized by function se_bind, and initializes socket object 'outSock' to represent the new connection. More...
 
void se_close (SOCKET *sock)
 Close a connected socket connection.
 
int se_sockValid (SOCKET *sock)
 Returns TRUE if socket is valid (connected).
 
S32 se_send (SOCKET *sock, const void *buf, U32 len)
 Sends data to the connected peer.
 
S32 se_recv (SOCKET *sock, void *buf, U32 len, U32 timeout)
 Waits for data sent by peer. More...
 
void mainTask (SeCtx *ctx)
 Main entry for all example programs.
 

Macro Definition Documentation

◆ SOCKET

#define SOCKET   int

The SOCKET object/handle is an 'int' when using a BSD compatible TCP/IP stack.

Non BSD compatible TCP IP stacks must set the macro NO_BSD_SOCK and define the SOCKET object. See the header file selib.h for details.

Function Documentation

◆ se_accept()

int se_accept ( SOCKET **  listenSock,
U32  timeout,
SOCKET **  outSock 
)

Waits for remote connections on the server SOCKET object 'listenSock', initialized by function se_bind, and initializes socket object 'outSock' to represent the new connection.

Returns
  • 1 Success
  • 0 timeout
  • -1 error

◆ se_bind()

int se_bind ( SOCKET sock,
U16  port 
)

Initializes a SOCKET object bound to a local port, ready to accept client connections.

Returns
Zero on success. Error codes returned:
  • -1 Cannot create socket: Fatal
  • -2 Cannot listen: Fatal
  • -3 Cannot bind: socket in use

◆ se_connect()

int se_connect ( SOCKET sock,
const char *  address,
U16  port 
)

Initializes a SOCKET object connected to a remote host/address at a given port.

Returns
Zero on success. Error codes returned:
  • -1 Cannot create socket: Fatal
  • -2 Cannot resolve 'address'
  • -3 Cannot connect

◆ se_recv()

S32 se_recv ( SOCKET sock,
void *  buf,
U32  len,
U32  timeout 
)

Waits for data sent by peer.

Parameters
sockthe SOCKET object.
bufis the data to send.
lenis the 'buf' length.
timeoutin milliseconds. The timeout can be set to INFINITE_TMO.
Returns
the length of the data read, zero on timeout, or a negative value on error.