Maxim Integrated High-Speed Microcontroller Users Guide: Network Microcontroller Supplement User Manual

Page 198

Advertising
background image

High-Speed Microcontroller User’s

Guide: Network Microcontroller

Supplement

198

listen

Description:

int listen(
int s,

/* socket on which to listen for connections */

int backlog);

/* maximum queue length for pending connections */

The

listen function listens for connections on the specified socket. It creates a queue of length backlog; backlog is the max-

imum number of pending new incoming connections (max.16). This function returns a success/failure code. To move an

incoming connection request from the queue to an established state,

accept must be called. It is generally required to use

bind to assign a local name to a socket before invoking listen.

accept

Description:

int accept(

int s,

/* socket on which to accept a pending connection */

struct sockaddr *addr,

/* address for new socket connection */

int addrlen);

/* length of addr structure */

The

accept function accepts a TCP connection on the specified socket. This function moves the first pending new incoming

connection request from the listen queue into the established state. It assigns a new local socket (connection endpoint) to the

connection and returns its socket handle.

Accept blocks if there are no pending new incoming connection requests. The sock-

et s must first be created by the socket call, bound to an address-using bind, and a listen queue must be created for it using
listen. If addr is not NULL, the remote address is filled in.

recv

Description:

int recv(
int s,

/* socket from which to receive data */

void *buf,

/* pointer to receive data buffer */

int len,

/* maximum number of bytes to receive */

int flags);

/* currently ignored */

The

recv function reads data from a connection-oriented (TCP) socket. This function reads up to len bytes from the socket s,

which must be in a connected state, into the buffer buf. It returns the number of bytes read. The flags parameter is ignored. If

there is no data on the socket, recv blocks infinitely unless a socket timeout is set using

setsockopt.

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

*buf

len

flags

Param0[0]–socket handle #

Param1[0:2]–pointer to TCP data

Param2[0:1]–max bytes to read

Param3–currently ignored

ACC

R1:R0

Return value (= 0 for success)

Number of bytes read

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

*addr

addrlen

Param0[0]–socket handle #

Param1[0:2]–pointer to addr

Param2[0]–size of addr structure

ACC

R0

Return value (= 0 for success)

New socket handle #

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

backlog

Param0[0]–socket handle #

Param1[0]–max queue backlog

ACC

Return value (= 0 for success)

Maxim Integrated

Advertising