Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
socket.c File Reference
Socket API. More...
Go to the source code of this file.
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.
- Version:
- 1.7.6
Definition in file socket.c.
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] interface Underlying network interface (optional parameter) [in] name Name of the host to be resolved [out] ipAddr IP address corresponding to the specified host name [in] flags Set of flags that influences the behavior of this function
- Returns:
- Error code
| Socket* socketAccept | ( | Socket * | socket, |
| IpAddr * | clientIpAddr, | ||
| uint16_t * | clientPort | ||
| ) |
Permit an incoming connection attempt on a socket.
- Parameters:
-
[in] socket Handle to a socket previously placed in a listening state [out] clientIpAddr IP address of the client [out] clientPort Port number used by the client
- Returns:
- Handle to the socket in which the actual connection is made
| error_t socketBindToInterface | ( | Socket * | socket, |
| NetInterface * | interface | ||
| ) |
| void socketClose | ( | Socket * | socket ) |
| error_t socketGetEvents | ( | Socket * | socket, |
| uint_t * | eventFlags | ||
| ) |
| error_t socketInit | ( | void | ) |
| 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] socket Socket to place in the listening state [in] backlog backlog The maximum length of the pending connection queue. If this parameter is zero, then the default backlog value is used instead
- Returns:
- Error code
| Socket* socketOpen | ( | uint_t | type, |
| uint_t | protocol | ||
| ) |
| 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] eventDesc Set of entries specifying the events the user is interested in [in] size Number of entries in the descriptor set [in] extEvent External event that can abort the wait if necessary (optional) [in] timeout Maximum time to wait before returning
- Returns:
- Error code
| error_t socketReceive | ( | Socket * | socket, |
| void * | data, | ||
| size_t | size, | ||
| size_t * | received, | ||
| uint_t | flags | ||
| ) |
Receive data from a connected socket.
- Parameters:
-
[in] socket Handle that identifies a connected socket [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns:
- Error code
| 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] socket Handle that identifies a socket [out] srcIpAddr Source IP address (optional) [out] srcPort Source port number (optional) [out] destIpAddr Destination IP address (optional) [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns:
- Error code
| 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] socket Handle that identifies a socket [out] srcIpAddr Source IP address (optional) [out] srcPort Source port number (optional) [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns:
- Error code
| 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] socket Handle that identifies a connected socket [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of data bytes to send [out] written Actual number of bytes written (optional parameter) [in] flags Set of flags that influences the behavior of this function
- Returns:
- Error code
| 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] socket Handle that identifies a socket [in] destIpAddr IP address of the target host [in] destPort Target port number [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of data bytes to send [out] written Actual number of bytes written (optional parameter) [in] flags Set of flags that influences the behavior of this function
- Returns:
- Error code
| error_t socketSetRxBufferSize | ( | Socket * | socket, |
| size_t | size | ||
| ) |
| error_t socketSetTimeout | ( | Socket * | socket, |
| systime_t | timeout | ||
| ) |
| error_t socketSetTxBufferSize | ( | Socket * | socket, |
| size_t | size | ||
| ) |
| 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] socket Handle to a socket [in] how Flag that describes what types of operation will no longer be allowed
- Returns:
- Error code
Generated on Tue Jul 12 2022 17:10:22 by
1.7.2