picoos-net  1.xxxx
Functions
Socket API

Functions

void netInit (void)
 
UosFile * netSockAlloc (NetSockState initialState)
 
void netSockFree (UosFile *sock)
 
UosFile * netSockCreateUDP (uip_ipaddr_t *ip, int port)
 
UosFile * netSockCreateTCPServer (int port)
 
int netSockBind (UosFile *sock, int port)
 
void netSockListen (UosFile *sock)
 
UosFile * netSockAccept (UosFile *listenSocket, uip_ipaddr_t *peer)
 
UosFile * netSockCreateTCP (uip_ipaddr_t *ip, int port)
 
int netSockConnect (UosFile *sock, uip_ipaddr_t *ip, int port)
 
void netSockAcceptHookSet (NetSockAcceptHook hook)
 
int netSockTimeout (UosFile *sock, UINT_t timeout)
 
int netSockRead (UosFile *sock, void *data, uint16_t max, uint16_t timeout)
 
int netSockReadLine (UosFile *sock, void *data, uint16_t max, uint16_t timeout)
 
void telnetInit (NetTelnet *state, int sock)
 
void telnetWrite (NetTelnet *conn, char *data)
 
void telnetFlush (NetTelnet *conn)
 
int telnetReadLine (NetTelnet *conn, char *data, int max, int timeout)
 

Detailed Description

Function Documentation

§ netInit()

void netInit ( void  )

Initialize socket layer. Before calling this Ethernet and IP address setup must be performed using uip_setethaddr and uip_sethostaddr.

After initializing network interface function starts a thread for main loop, which performs necessary uIP services for socket layer.

§ netSockAlloc()

UosFile* netSockAlloc ( NetSockState  initialState)

Allocate a new socket descriptor by searching for a free one in socket table.

§ netSockFree()

void netSockFree ( UosFile *  sock)

Free a new socket descriptor.

§ netSockCreateUDP()

UosFile* netSockCreateUDP ( uip_ipaddr_t *  ip,
int  port 
)

Create new UDP socket. This is the same as netSockUdpCreate() in previous versions.

§ netSockCreateTCPServer()

UosFile* netSockCreateTCPServer ( int  port)

Create a server socket, for listening incoming connections. This is same as netSockServerCreate in previous versions.

§ netSockBind()

int netSockBind ( UosFile *  sock,
int  port 
)

Bind server socket to given port before listening on it.

§ netSockListen()

void netSockListen ( UosFile *  sock)

Start listening for incoming connections. Port is set during netSockServerCreate().

§ netSockAccept()

UosFile* netSockAccept ( UosFile *  listenSocket,
uip_ipaddr_t *  peer 
)

Accept new incoming connection.

§ netSockCreateTCP()

UosFile* netSockCreateTCP ( uip_ipaddr_t *  ip,
int  port 
)

Create new client connection to given IP address and port. This replaces netSockConnect call in previous library versions.

§ netSockConnect()

int netSockConnect ( UosFile *  sock,
uip_ipaddr_t *  ip,
int  port 
)

Connect socket (udp or tcp) to given IP and port. This works like BSD connect() now. To get functionality similar to previous library versions, use netSockCrateTCP().

§ netSockAcceptHookSet()

void netSockAcceptHookSet ( NetSockAcceptHook  hook)

Set accept hook function to handling incoming connections. After accept hook is called by main loop it is responsible for handling the connection. Usually a new pico]OS thread is created to process data.

Accept hook should not block.

Accept hook provides functionality that is similar to unix accept().

§ netSockTimeout()

int netSockTimeout ( UosFile *  sock,
UINT_t  timeout 
)

Set read timeout for socket.

§ netSockRead()

int netSockRead ( UosFile *  sock,
void *  data,
uint16_t  max,
uint16_t  timeout 
)

Read data from socket. Similar to unix read(). Function blocks until data is available.

§ netSockReadLine()

int netSockReadLine ( UosFile *  sock,
void *  data,
uint16_t  max,
uint16_t  timeout 
)

Read a line (terminated by CR or NL) from socket.

§ telnetInit()

void telnetInit ( NetTelnet *  state,
int  sock 
)

Initialize telnet protocol state machine for given socket connection.

§ telnetWrite()

void telnetWrite ( NetTelnet *  conn,
char *  data 
)

Write data using telnet protocol.

§ telnetFlush()

void telnetFlush ( NetTelnet *  conn)

Flush data. Causes immediate sending of data that has been buffered.

§ telnetReadLine()

int telnetReadLine ( NetTelnet *  conn,
char *  data,
int  max,
int  timeout 
)

Read a line from socket using telnet protocol. Handly when writing CLI servers.