ソースの整理中ですが、利用はできます。 大きなファイルはできないかもしれません。

Dependencies:   EthernetInterface HttpServer TextLCD expatlib mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Fork of giken9_HTMLServer_Sample by Yasushi TAUCHI

Embed: (wiki syntax)

« Back to documentation index

sockets.c File Reference

sockets.c File Reference

Sockets BSD-Like API module. More...

Go to the source code of this file.

Functions

void lwip_socket_init (void)
 Initialize this module.
static struct lwip_sock * get_socket (int s)
 Map a externally used socket index to the internal socket representation.
static struct lwip_sock * tryget_socket (int s)
 Same as get_socket but doesn't set errno.
static int alloc_socket (struct netconn *newconn, int accepted)
 Allocate a new socket for a given netconn.
static void free_socket (struct lwip_sock *sock, int is_tcp)
 Free a socket.
int lwip_listen (int s, int backlog)
 Set a socket into listen mode.
int lwip_sendto (int s, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)

Variables

static struct lwip_sock sockets [NUM_SOCKETS]
 The global array of available sockets.
static struct lwip_select_cb * select_cb_list
 The global list of tasks waiting for select.
static volatile int select_cb_ctr
 This counter is increased from lwip_select when the list is chagned and checked in event_callback to see if it has changed.
static const int err_to_errno_table []
 Table to quickly map an lwIP error (err_t) to a socket error by using -err as an index.

Detailed Description

Sockets BSD-Like API module.

Definition in file sockets.c.


Function Documentation

static int alloc_socket ( struct netconn newconn,
int  accepted 
) [static]

Allocate a new socket for a given netconn.

Parameters:
newconnthe netconn for which to allocate a socket
accepted1 if socket has been created by accept(), 0 if socket has been created by socket()
Returns:
the index of the new socket; -1 on error

Definition at line 243 of file sockets.c.

static void free_socket ( struct lwip_sock *  sock,
int  is_tcp 
) [static]

Free a socket.

The socket's netconn must have been delete before!

Parameters:
sockthe socket to free
is_tcp!= 0 for TCP sockets, used to free lastdata

Definition at line 280 of file sockets.c.

static struct lwip_sock* get_socket ( int  s ) [static, read]

Map a externally used socket index to the internal socket representation.

Parameters:
sexternally used socket index
Returns:
struct lwip_sock for the socket or NULL if not found

Definition at line 195 of file sockets.c.

int lwip_listen ( int  s,
int  backlog 
)

Set a socket into listen mode.

The socket may not have been used for another connection previously.

Parameters:
sthe socket to set to listening mode
backlog(ATTENTION: needs TCP_LISTEN_BACKLOG=1)
Returns:
0 on success, non-zero on failure

Definition at line 521 of file sockets.c.

int lwip_sendto ( int  s,
const void *  data,
size_t  size,
int  flags,
const struct sockaddr *  to,
socklen_t  tolen 
)

Go through the readset and writeset lists and see which socket of the sockets set in the sets has events. On return, readset, writeset and exceptset have the sockets enabled that had events.

exceptset is not used for now!!!

Parameters:
maxfdp1the highest socket index in the sets
readset_in,:set of sockets to check for read events
writeset_in,:set of sockets to check for write events
exceptset_in,:set of sockets to check for error events
readset_out,:set of sockets that had read events
writeset_out,:set of sockets that had write events
exceptset_out,:set os sockets that had error events
Returns:
number of sockets that had events (read/write/exception) (>= 0)

Processing exceptset is not yet implemented.

Callback registered in the netconn layer for each socket-netconn. Processes recvevent (data available) and wakes up tasks waiting for select.

Unimplemented: Close one end of a full-duplex connection. Currently, the full connection is closed.

A minimal implementation of fcntl. Currently only the commands F_GETFL and F_SETFL are implemented. Only the flag O_NONBLOCK is implemented.

Definition at line 788 of file sockets.c.

void lwip_socket_init ( void   )

Initialize this module.

This function has to be called before any other functions in this module!

Definition at line 184 of file sockets.c.

static struct lwip_sock* tryget_socket ( int  s ) [static, read]

Same as get_socket but doesn't set errno.

Parameters:
sexternally used socket index
Returns:
struct lwip_sock for the socket or NULL if not found

Definition at line 223 of file sockets.c.


Variable Documentation

const int err_to_errno_table[] [static]
Initial value:
 {
  0,             
  ENOMEM,        
  ENOBUFS,       
  EWOULDBLOCK,   
  EHOSTUNREACH,  
  EINPROGRESS,   
  EINVAL,        
  EWOULDBLOCK,   
  EADDRINUSE,    
  EALREADY,      
  ECONNABORTED,  
  ECONNRESET,    
  ENOTCONN,      
  ENOTCONN,      
  EIO,           
  -1,            
}

Table to quickly map an lwIP error (err_t) to a socket error by using -err as an index.

Definition at line 135 of file sockets.c.

volatile int select_cb_ctr [static]

This counter is increased from lwip_select when the list is chagned and checked in event_callback to see if it has changed.

Definition at line 131 of file sockets.c.

struct lwip_select_cb* select_cb_list [static]

The global list of tasks waiting for select.

Definition at line 128 of file sockets.c.

struct lwip_sock sockets[NUM_SOCKETS] [static]

The global array of available sockets.

Definition at line 126 of file sockets.c.