Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

socket.h File Reference

socket.h File Reference

Socket API. More...

Go to the source code of this file.

Data Structures

struct  _SocketQueueItem
 Receive queue item. More...
struct  _Socket
 Structure describing a socket. More...
struct  SocketEventDesc
 Structure describing socket events. More...

Typedefs

typedef struct _SocketQueueItem SocketQueueItem
 Receive queue item.

Enumerations

enum  SocketType
 

Socket types.

More...
enum  SocketIpProtocol
 

IP protocols.

More...
enum  SocketEthProtocol
 

Ethernet protocols.

More...
enum  SocketFlags
 

Flags used by I/O functions.

More...
enum  SocketShutdownFlags
 

Flags used by shutdown function.

More...
enum  SocketEvent
 

Socket events.

More...
enum  HostType
 

Host types.

More...
enum  HostnameResolver
 

Name resolution protocols.

More...

Functions

error_t socketInit (void)
 Socket related initialization.
Socket * socketOpen (uint_t type, uint_t protocol)
 Create a socket (UDP or TCP)
error_t socketSetTimeout (Socket *socket, systime_t timeout)
 Set timeout value for blocking operations.
error_t socketSetTxBufferSize (Socket *socket, size_t size)
 Specify the size of the send buffer.
error_t socketSetRxBufferSize (Socket *socket, size_t size)
 Specify the size of the receive buffer.
error_t socketBindToInterface (Socket *socket, NetInterface *interface)
 Bind a socket to a particular network interface.
error_t socketBind (Socket *socket, const IpAddr *localIpAddr, uint16_t localPort)
 Associate a local address with a socket.
error_t socketConnect (Socket *socket, const IpAddr *remoteIpAddr, uint16_t remotePort)
 Establish a connection to a specified socket.
error_t socketListen (Socket *socket, uint_t backlog)
 Place a socket in the listening state.
Socket * socketAccept (Socket *socket, IpAddr *clientIpAddr, uint16_t *clientPort)
 Permit an incoming connection attempt on a socket.
error_t socketSend (Socket *socket, const void *data, size_t length, size_t *written, uint_t flags)
 Send data to a connected socket.
error_t socketSendTo (Socket *socket, const IpAddr *destIpAddr, uint16_t destPort, const void *data, size_t length, size_t *written, uint_t flags)
 Send a datagram to a specific destination.
error_t socketReceive (Socket *socket, void *data, size_t size, size_t *received, uint_t flags)
 Receive data from a connected socket.
error_t socketReceiveFrom (Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, void *data, size_t size, size_t *received, uint_t flags)
 Receive a datagram from a connectionless socket.
error_t socketReceiveEx (Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags)
 Receive a datagram.
error_t socketGetLocalAddr (Socket *socket, IpAddr *localIpAddr, uint16_t *localPort)
 Retrieve the local address for a given socket.
error_t socketGetRemoteAddr (Socket *socket, IpAddr *remoteIpAddr, uint16_t *remotePort)
 Retrieve the address of the peer to which a socket is connected.
error_t socketShutdown (Socket *socket, uint_t how)
 Disable reception, transmission, or both.
void socketClose (Socket *socket)
 Close an existing socket.
error_t socketPoll (SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout)
 Wait for one of a set of sockets to become ready to perform I/O.
error_t socketRegisterEvents (Socket *socket, OsEvent *event, uint_t eventMask)
 Subscribe to the specified socket events.
error_t socketUnregisterEvents (Socket *socket)
 Unsubscribe previously registered events.
error_t socketGetEvents (Socket *socket, uint_t *eventFlags)
 Retrieve event flags for a specified socket.
error_t getHostByName (NetInterface *interface, const char_t *name, IpAddr *ipAddr, uint_t flags)
 Resolve a host name into an IP address.

Detailed Description

Socket API.

License

Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author:
Oryx Embedded SARL (www.oryx-embedded.com)
Version:
1.7.6

Definition in file socket.h.


Typedef Documentation

Receive queue item.


Enumeration Type Documentation

Name resolution protocols.

Definition at line 175 of file socket.h.

enum HostType

Host types.

Definition at line 163 of file socket.h.

Ethernet protocols.

Definition at line 95 of file socket.h.

Socket events.

Definition at line 143 of file socket.h.

Flags used by I/O functions.

Definition at line 108 of file socket.h.

IP protocols.

Definition at line 81 of file socket.h.

Flags used by shutdown function.

Definition at line 131 of file socket.h.

enum SocketType

Socket types.

Definition at line 67 of file socket.h.


Function Documentation

error_t getHostByName ( NetInterface *  interface,
const char_t *  name,
IpAddr ipAddr,
uint_t  flags 
)

Resolve a host name into an IP address.

Parameters:
[in]interfaceUnderlying network interface (optional parameter)
[in]nameName of the host to be resolved
[out]ipAddrIP address corresponding to the specified host name
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 1049 of file socket.c.

Socket* socketAccept ( Socket *  socket,
IpAddr clientIpAddr,
uint16_t *  clientPort 
)

Permit an incoming connection attempt on a socket.

Parameters:
[in]socketHandle to a socket previously placed in a listening state
[out]clientIpAddrIP address of the client
[out]clientPortPort number used by the client
Returns:
Handle to the socket in which the actual connection is made

Definition at line 457 of file socket.c.

error_t socketBind ( Socket *  socket,
const IpAddr localIpAddr,
uint16_t  localPort 
)

Associate a local address with a socket.

Parameters:
[in]socketHandle to a socket
[in]localIpAddrLocal address to assign to the bound socket
[in]localPortLocal port number to assign to the bound socket
Returns:
Error code

Definition at line 331 of file socket.c.

error_t socketBindToInterface ( Socket *  socket,
NetInterface *  interface 
)

Bind a socket to a particular network interface.

Parameters:
[in]socketHandle to a socket
[in]interfaceNetwork interface to be used
Returns:
Error code

Definition at line 309 of file socket.c.

void socketClose ( Socket *  socket )

Close an existing socket.

Parameters:
[in]socketHandle identifying the socket to close

Definition at line 797 of file socket.c.

error_t socketConnect ( Socket *  socket,
const IpAddr remoteIpAddr,
uint16_t  remotePort 
)

Establish a connection to a specified socket.

Parameters:
[in]socketHandle to an unconnected socket
[in]remoteIpAddrIP address of the remote host
[in]remotePortRemote port number that will be used to establish the connection
Returns:
Error code

Definition at line 357 of file socket.c.

error_t socketGetEvents ( Socket *  socket,
uint_t *  eventFlags 
)

Retrieve event flags for a specified socket.

Parameters:
[in]socketHandle that identifies a socket
[out]eventFlagsLogic OR of events in the signaled state
Returns:
Error code

Definition at line 1016 of file socket.c.

error_t socketGetLocalAddr ( Socket *  socket,
IpAddr localIpAddr,
uint16_t *  localPort 
)

Retrieve the local address for a given socket.

Parameters:
[in]socketHandle that identifies a socket
[out]localIpAddrLocal IP address (optional)
[out]localPortLocal port number (optional)
Returns:
Error code

Definition at line 703 of file socket.c.

error_t socketGetRemoteAddr ( Socket *  socket,
IpAddr remoteIpAddr,
uint16_t *  remotePort 
)

Retrieve the address of the peer to which a socket is connected.

Parameters:
[in]socketHandle that identifies a socket
[out]remoteIpAddrIP address of the remote host (optional)
[out]remotePortRemote port number (optional)
Returns:
Error code

Definition at line 730 of file socket.c.

error_t socketInit ( void   )

Socket related initialization.

Returns:
Error code

Definition at line 54 of file socket.c.

error_t socketListen ( Socket *  socket,
uint_t  backlog 
)

Place a socket in the listening state.

Place a socket in a state in which it is listening for an incoming connection

Parameters:
[in]socketSocket to place in the listening state
[in]backlogbacklog The maximum length of the pending connection queue. If this parameter is zero, then the default backlog value is used instead
Returns:
Error code

Definition at line 420 of file socket.c.

Socket* socketOpen ( uint_t  type,
uint_t  protocol 
)

Create a socket (UDP or TCP)

Parameters:
[in]typeType specification for the new socket
[in]protocolProtocol to be used
Returns:
Handle referencing the new socket

Definition at line 92 of file socket.c.

error_t socketPoll ( SocketEventDesc eventDesc,
uint_t  size,
OsEvent extEvent,
systime_t  timeout 
)

Wait for one of a set of sockets to become ready to perform I/O.

The socketPoll function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O

Parameters:
[in,out]eventDescSet of entries specifying the events the user is interested in
[in]sizeNumber of entries in the descriptor set
[in]extEventExternal event that can abort the wait if necessary (optional)
[in]timeoutMaximum time to wait before returning
Returns:
Error code

Definition at line 857 of file socket.c.

error_t socketReceive ( Socket *  socket,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive data from a connected socket.

Parameters:
[in]socketHandle that identifies a connected socket
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 584 of file socket.c.

error_t socketReceiveEx ( Socket *  socket,
IpAddr srcIpAddr,
uint16_t *  srcPort,
IpAddr destIpAddr,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive a datagram.

Parameters:
[in]socketHandle that identifies a socket
[out]srcIpAddrSource IP address (optional)
[out]srcPortSource port number (optional)
[out]destIpAddrDestination IP address (optional)
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 625 of file socket.c.

error_t socketReceiveFrom ( Socket *  socket,
IpAddr srcIpAddr,
uint16_t *  srcPort,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive a datagram from a connectionless socket.

Parameters:
[in]socketHandle that identifies a socket
[out]srcIpAddrSource IP address (optional)
[out]srcPortSource port number (optional)
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 604 of file socket.c.

error_t socketRegisterEvents ( Socket *  socket,
OsEvent event,
uint_t  eventMask 
)

Subscribe to the specified socket events.

Parameters:
[in]socketHandle that identifies a socket
[in]eventEvent object used to receive notifications
[in]eventMaskLogic OR of the requested socket events
Returns:
Error code

Definition at line 936 of file socket.c.

error_t socketSend ( Socket *  socket,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Send data to a connected socket.

Parameters:
[in]socketHandle that identifies a connected socket
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of data bytes to send
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 490 of file socket.c.

error_t socketSendTo ( Socket *  socket,
const IpAddr destIpAddr,
uint16_t  destPort,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Send a datagram to a specific destination.

Parameters:
[in]socketHandle that identifies a socket
[in]destIpAddrIP address of the target host
[in]destPortTarget port number
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of data bytes to send
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 511 of file socket.c.

error_t socketSetRxBufferSize ( Socket *  socket,
size_t  size 
)

Specify the size of the receive buffer.

Parameters:
[in]socketHandle to a socket
[in]sizeDesired buffer size in bytes
Returns:
Error code

Definition at line 275 of file socket.c.

error_t socketSetTimeout ( Socket *  socket,
systime_t  timeout 
)

Set timeout value for blocking operations.

Parameters:
[in]socketHandle to a socket
[in]timeoutMaximum time to wait
Returns:
Error code

Definition at line 216 of file socket.c.

error_t socketSetTxBufferSize ( Socket *  socket,
size_t  size 
)

Specify the size of the send buffer.

Parameters:
[in]socketHandle to a socket
[in]sizeDesired buffer size in bytes
Returns:
Error code

Definition at line 241 of file socket.c.

error_t socketShutdown ( Socket *  socket,
uint_t  how 
)

Disable reception, transmission, or both.

Note that socketShutdown() does not close the socket, and resources attached to the socket will not be freed until socketClose() is invoked

Parameters:
[in]socketHandle to a socket
[in]howFlag that describes what types of operation will no longer be allowed
Returns:
Error code

Definition at line 760 of file socket.c.

error_t socketUnregisterEvents ( Socket *  socket )

Unsubscribe previously registered events.

Parameters:
[in]socketHandle that identifies a socket
Returns:
Error code

Definition at line 990 of file socket.c.