EVE 1.0
Berkeley sockets emulation
Collaboration diagram for Berkeley sockets emulation:

Data Structures

struct  sockaddr
 
struct  in_addr
 
struct  sockaddr_in
 

Macros

#define AF_INET   2
 
#define SOCK_STREAM   1
 
#define SOCK_DGRAM   2
 
#define IPPROTO_TCP   6
 
#define IPPROTO_UDP   17
 
#define SOL_SOCKET   1
 
#define SO_RCVTIMEO   20
 
#define SO_SNDTIMEO   21
 
#define TCP_NODELAY   1
 
#define FIONBIO   0x5421
 
#define HTONS(hostshort)   UIP_HTONS(hostshort)
 

Typedefs

typedef uint16_t sa_family_t
 
typedef uint32_t socklen_t
 

Functions

static uint16_t htons (uint16_t hostshort)
 
int socket (int domain, int type, int protocol)
 
int bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 
int listen (int sockfd, int backlog)
 
int accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 
int connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 
int closesocket (int sockfd)
 
ssize_t recv (int sockfd, void *buf, size_t len, int flags)
 
int poll_recv (int sockfd, uint32_t timeout)
 
ssize_t send (int sockfd, const void *buf, size_t len, int flags)
 
int poll_send (int sockfd, uint32_t timeout)
 
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
 
int ioctlsocket (int sockfd, int request, const void *opt)
 
int setsockopt (int sockfd, int level, int request, const void *opt, socklen_t length)
 

Detailed Description

Macro Definition Documentation

#define AF_INET   2

INET address family

Definition at line 89 of file rtos.h.

#define SOCK_STREAM   1

Stream socket type

Definition at line 90 of file rtos.h.

#define SOCK_DGRAM   2

Datagram socket type

Definition at line 91 of file rtos.h.

#define IPPROTO_TCP   6

TCP protocol

Definition at line 92 of file rtos.h.

#define IPPROTO_UDP   17

UDP protocol

Definition at line 93 of file rtos.h.

#define SOL_SOCKET   1

setsockopt() socket options

Definition at line 94 of file rtos.h.

#define SO_RCVTIMEO   20

recv() timeout

Definition at line 95 of file rtos.h.

#define SO_SNDTIMEO   21

send() timeout

Definition at line 96 of file rtos.h.

#define TCP_NODELAY   1

Disable Nagle's algorithm

Definition at line 97 of file rtos.h.

#define FIONBIO   0x5421

Async. socket IOCTL

Definition at line 98 of file rtos.h.

#define HTONS (   hostshort)    UIP_HTONS(hostshort)

Host to network order

Parameters
hostshortHost-order short value
Returns
Network-order short value

Definition at line 810 of file rtos.h.

Typedef Documentation

typedef uint16_t sa_family_t

Socket address family type

Definition at line 773 of file rtos.h.

typedef uint32_t socklen_t

Socket address length type

Definition at line 774 of file rtos.h.

Function Documentation

static uint16_t htons ( uint16_t  hostshort)
inlinestatic

Host to network order

Parameters
hostshortHost-order short value
Returns
Network-order short value

Definition at line 818 of file rtos.h.

References accept(), backlog, bind(), closesocket(), connect(), ioctlsocket(), listen(), poll_recv(), poll_send(), recv(), select(), send(), setsockopt(), socket(), and UIP_HTONS.

int socket ( int  domain,
int  type,
int  protocol 
)

Creates an endpoint for communication and returns a descriptor for the socket.

Parameters
domainThe protocol family of the created socket.
typeSOCK_STREAM or SOCK_DGRAM
protocolThe actual transport protocol to use. 0 or IPPROTO_xxx
Returns
-1 if an error occurred. Otherwise, it returns an integer representing the newly assigned descriptor.

Referenced by htons().

int bind ( int  sockfd,
const struct sockaddr addr,
socklen_t  addrlen 
)

Assigns a socket to an address.

Parameters
sockfdA descriptor representing the socket to perform the bind on.
addrA pointer to a sockaddr structure representing the address to bind to.
addrlenThe size of the sockaddr structure, pointed by addr.
Returns
0 on success or -1 if an error occurs.

Referenced by htons().

int listen ( int  sockfd,
int  backlog 
)

Prepares a socket for incoming connections.

Parameters
sockfdA socket descriptor.
backlogThe number of pending connections that can be queued up at any one time (ignored by the current implementation).
Returns
0 on success or -1 if an error occurs.

Referenced by htons().

int accept ( int  sockfd,
struct sockaddr addr,
socklen_t addrlen 
)

Creates a new socket for an incoming connection.

Parameters
sockfdA descriptor representing the listening socket.
addrA pointer to a sockaddr structure to receive the client's address information.
addrlenA pointer to a variable, containing size of the sockaddr structure. Updated by the call.

Referenced by htons().

int connect ( int  sockfd,
const struct sockaddr addr,
socklen_t  addrlen 
)

Establishes a communication link towards a remote host.

Parameters
sockfdA local socket descriptor
addrA pointer to a sockaddr structure representing the address of the remote host.
addrlenThe size of the sockaddr structure, pointed by addr.
Returns
0 on success or -1 if an error occurs.

Referenced by htons().

int closesocket ( int  sockfd)

Closes a socket desctiptor.

Parameters
sockfdA socket descriptor
Returns
0 on success or -1 if an error occurs.

Referenced by htons().

ssize_t recv ( int  sockfd,
void *  buf,
size_t  len,
int  flags 
)

Receives data from a socket

Parameters
sockfdA socket descriptor.
bufThe buffer to be filled by data
lenLength of the buffer.
flagsIgnored in the current implementation
Returns
Amount of bytes received or -1 if an error occurs.

Referenced by htons().

int poll_recv ( int  sockfd,
uint32_t  timeout 
)

Waits for a socket becomes available for data reading

If this function returns 0 for a socket, then a consequent recv() call will not block and will not return EWOULDBLOCK.

Parameters
sockfdA socket descriptor.
timeoutTimeout in system ticks.
Returns
0 if the socket becomes available, or -1 if not.

Referenced by htons().

ssize_t send ( int  sockfd,
const void *  buf,
size_t  len,
int  flags 
)

Sends data into a socket

Parameters
sockfdA socket descriptor.
bufThe buffer to be sent
lenLength of the buffer.
flagsIgnored in the current implementation
Returns
Amount of bytes sent or -1 if an error occurs.

Referenced by htons(), and uip_process().

int poll_send ( int  sockfd,
uint32_t  timeout 
)

Waits for a socket becomes available for data sending

If thiss function returns 0 for a socket, then a consequent send() call will not block and will not return EWOULDBLOCK.

Parameters
sockfdA socket descriptor.
timeoutTimeout in system ticks.
Returns
0 if the socket becomes available, or -1 if not.

Referenced by htons().

int select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
struct timeval *  timeout 
)

Synchronous I/O multiplexing

Parameters
nfdsThe highest-numbered socket descriptor plus 1.
readfdsset of sockets, watched for read, updated on return.
writefdsset of sockets, watched for write, updated on return.
exceptfdsset of sockets, watched for exception, updated on return.
timeouttimeout. Infinite if NULL.
Returns
the total number of bits set in the readfds, writefds, exceptfds.

Referenced by htons().

int ioctlsocket ( int  sockfd,
int  request,
const void *  opt 
)

Controls socket options (IOCTL ones).

Parameters
sockfdA socket descriptor.
requestIOCTL request (so far FIONBIO is the only supported)
optThe option value
Returns
0
1 int opt = 1;
2 ioctlsocket(fd, FIONBIO, &opt);

Referenced by htons().

int setsockopt ( int  sockfd,
int  level,
int  request,
const void *  opt,
socklen_t  length 
)

Controls socket options (setsockopt ones).

Parameters
sockfdA socket descriptor.
levelOption level (SOL_SOCKET, IPPROTO_TCP)
requestThe option name (SO_RCVTIMEO, SO_SNDTIMEO, TCP_NODELAY)
optThe option value
lengthLength of the option
Returns
0
1 struct timeval tv;
2 tv.tv_sec = 30;
3 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
4 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
5 
6 int flag = 1;
7 setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));

Referenced by htons().