Kenji Arai / TYBLE16_mbedlized_os5_several_examples_1st

Dependencies:   nRF51_Vdd TextLCD BME280

Embed: (wiki syntax)

« Back to documentation index

socket.h File Reference

socket.h File Reference

Socket API definitions. More...

Go to the source code of this file.

Data Structures

struct  socket
 Socket structure. More...
struct  inet_pcb_s
 Internet protocol control block. More...

Typedefs

typedef struct socket socket_t
 Socket structure.
typedef struct inet_pcb_s inet_pcb_t
 Internet protocol control block.

Functions

void socket_init (void)
 Initialize API.
error_t socket_create (socket_family_t family, socket_type_t type, uint8_t protocol, int8_t *sid, uint16_t port, void(*passed_fptr)(void *), bool buffer_type)
 Allocate a socket.
error_t socket_up (buffer_t *buf)
 Push a buffer to a socket.
int16_t socket_buffer_sendmsg (int8_t sid, buffer_t *buf, const struct ns_msghdr *msg, int flags)
 Write a data buffer to a socket.
void socket_release (socket_t *socket)
 Release a socket (detaching from application)
inet_pcb_tsocket_inet_pcb_free (inet_pcb_t *inet_pcb)
 Free reserved inet_pcb.
struct
protocol_interface_info_entry * 
socket_interface_determine (const socket_t *socket, buffer_t *buf)
 Determine interface based on socket_id and address.
uint16_t socket_generate_random_port (uint8_t protocol)
 Generate random port number between RANDOM_PORT_NUMBER_START and RANDOM_PORT_NUMBER_END.

Variables

const uint8_t ns_in6addr_any [16]
 IPv6 wildcard address IN_ANY.

Detailed Description

Socket API definitions.

Socket API functions and relevant structures.

Definition in file socket.h.


Typedef Documentation

typedef struct inet_pcb_s inet_pcb_t

Internet protocol control block.

typedef struct socket socket_t

Socket structure.


Function Documentation

int16_t socket_buffer_sendmsg ( int8_t  sid,
buffer_t buf,
const struct ns_msghdr *  msg,
int  flags 
)

Write a data buffer to a socket.

Used by the application to send data with meta data from msg

Data will be taken either from buf if non-NULL else from msg->msg_iov.

Using buf is not permitted for stream sockets.

Parameters:
sidsocket id
bufpointer to buffer is plain buffer with payload only - all metadata ignored
msgpointer to message-specific data message name define destination address and control message define ancillary data
Returns:
0 Ok done
-1 Unsupported socket or message parameter
-5 Socket not properly connected
-6 Packet too short

Mark Socket id to buffer meta data

Allocate random port if port is not defined.

Set socket configured parameters

validate Message name and Parse Ancillary Data when Message header is shared.

Validate message name (destination) and set address to buffer

Set interface id when it is configured >0

Select outgoing interface for this message

Link-specific configuration

Set Hop Limit

Flow label set

Select source address for this message

Definition at line 994 of file ns_socket.c.

error_t socket_create ( socket_family_t  family,
socket_type_t  type,
uint8_t  protocol,
int8_t *  sid,
uint16_t  port,
void(*)(void *)  passed_fptr,
bool  buffer_type 
)

Allocate a socket.

Parameters:
sidpointer to socket ID which will contain socket ID
portlisten port for socket
Returns:
eOK socket opened
eFALSE no free sockets
eBUSY port reserved

Definition at line 498 of file ns_socket.c.

uint16_t socket_generate_random_port ( uint8_t  protocol )

Generate random port number between RANDOM_PORT_NUMBER_START and RANDOM_PORT_NUMBER_END.

Returns:
random port number

Definition at line 78 of file ns_socket.c.

inet_pcb_t* socket_inet_pcb_free ( inet_pcb_t inet_pcb )

Free reserved inet_pcb.

Definition at line 1441 of file ns_socket.c.

void socket_init ( void   )

Initialize API.

Definition at line 261 of file ns_socket.c.

struct protocol_interface_info_entry* socket_interface_determine ( const socket_t socket,
buffer_t buf 
) [read]

Determine interface based on socket_id and address.

Definition at line 1505 of file ns_socket.c.

void socket_release ( socket_t socket )

Release a socket (detaching from application)

We are either releasing directly from an application close (ID being freed, reference being removed from ID table), or indirectly - a pending socket attached to a listening socket being closed.

Parameters:
socketsocket pointer

Definition at line 279 of file ns_socket.c.

error_t socket_up ( buffer_t buf )

Push a buffer to a socket.

Used by the protocol core to push buffers to sockets.

To determine the socket to send to, transport layer must ensure either: a) buf->socket_id already filled in, or b) buf->options.type is socket family (IPv6/Local) buf->options.code is protocol (IPv6=NH,Local=n/a)

Parameters:
bufbuffer to push
Returns:
eOK socket opened
eFALSE no socket found
eBUSY socket full

Definition at line 851 of file ns_socket.c.


Variable Documentation

const uint8_t ns_in6addr_any[16]

IPv6 wildcard address IN_ANY.

Definition at line 46 of file socket_api.c.