A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 /*
ram54288 0:a7a43371b306 2 * Copyright (c) 2016 ARM Limited. All rights reserved.
ram54288 0:a7a43371b306 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:a7a43371b306 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:a7a43371b306 5 * not use this file except in compliance with the License.
ram54288 0:a7a43371b306 6 * You may obtain a copy of the License at
ram54288 0:a7a43371b306 7 *
ram54288 0:a7a43371b306 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:a7a43371b306 9 *
ram54288 0:a7a43371b306 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:a7a43371b306 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:a7a43371b306 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:a7a43371b306 13 * See the License for the specific language governing permissions and
ram54288 0:a7a43371b306 14 * limitations under the License.
ram54288 0:a7a43371b306 15 */
ram54288 0:a7a43371b306 16
ram54288 0:a7a43371b306 17
ram54288 0:a7a43371b306 18 #ifndef _PAL_SOCKET_H
ram54288 0:a7a43371b306 19 #define _PAL_SOCKET_H
ram54288 0:a7a43371b306 20
ram54288 0:a7a43371b306 21 #ifdef __cplusplus
ram54288 0:a7a43371b306 22 extern "C" {
ram54288 0:a7a43371b306 23 #endif
ram54288 0:a7a43371b306 24
ram54288 0:a7a43371b306 25 #include "pal.h"
ram54288 0:a7a43371b306 26 //! PAL network socket API
ram54288 0:a7a43371b306 27 //! pal network sockets configurations options:
ram54288 0:a7a43371b306 28 //! set PAL_NET_TCP_AND_TLS_SUPPORT to true TCP is supported by the platform and is required
ram54288 0:a7a43371b306 29 //! set PAL_NET_ASYNCHRONOUS_SOCKET_API to true if asynchronous socket API supported by the platform and is required : CURRENTLY MANDATORY
ram54288 0:a7a43371b306 30 //! set PAL_NET_DNS_SUPPORT to true if you DNS url lookup API is supported.
ram54288 0:a7a43371b306 31
ram54288 0:a7a43371b306 32 typedef uint32_t palSocketLength_t; /*! length of data */
ram54288 0:a7a43371b306 33 typedef void* palSocket_t; /*! PAL socket handle type */
ram54288 0:a7a43371b306 34
ram54288 0:a7a43371b306 35 #define PAL_NET_MAX_ADDR_SIZE 32 // check if we can make this more efficient
ram54288 0:a7a43371b306 36
ram54288 0:a7a43371b306 37 typedef struct palSocketAddress {
ram54288 0:a7a43371b306 38 unsigned short addressType; /*! address family for the socket*/
ram54288 0:a7a43371b306 39 char addressData[PAL_NET_MAX_ADDR_SIZE]; /*! address (based on protocol)*/
ram54288 0:a7a43371b306 40 } palSocketAddress_t; /*! address data structure with enough room to support IPV4 and IPV6*/
ram54288 0:a7a43371b306 41
ram54288 0:a7a43371b306 42 typedef struct palNetInterfaceInfo{
ram54288 0:a7a43371b306 43 char interfaceName[16]; //15 + ‘\0’
ram54288 0:a7a43371b306 44 palSocketAddress_t address;
ram54288 0:a7a43371b306 45 uint32_t addressSize;
ram54288 0:a7a43371b306 46 } palNetInterfaceInfo_t;
ram54288 0:a7a43371b306 47
ram54288 0:a7a43371b306 48 typedef enum {
ram54288 0:a7a43371b306 49 PAL_AF_UNSPEC = 0,
ram54288 0:a7a43371b306 50 PAL_AF_INET = 2, /*! Internet IP Protocol */
ram54288 0:a7a43371b306 51 PAL_AF_INET6 = 10, /*! IP version 6 */
ram54288 0:a7a43371b306 52 } palSocketDomain_t;/*! network domains supported by PAL*/
ram54288 0:a7a43371b306 53
ram54288 0:a7a43371b306 54 typedef enum {
ram54288 0:a7a43371b306 55 #if PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:a7a43371b306 56 PAL_SOCK_STREAM = 1, /*! stream socket */
ram54288 0:a7a43371b306 57 PAL_SOCK_STREAM_SERVER = 99, /*! stream socket */
ram54288 0:a7a43371b306 58 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:a7a43371b306 59 PAL_SOCK_DGRAM = 2 /*! datagram socket */
ram54288 0:a7a43371b306 60 } palSocketType_t;/*! socket types supported by PAL */
ram54288 0:a7a43371b306 61
ram54288 0:a7a43371b306 62
ram54288 0:a7a43371b306 63 typedef enum {
ram54288 0:a7a43371b306 64 PAL_SO_REUSEADDR = 0x0004, /*! allow local address reuse */
ram54288 0:a7a43371b306 65 #if PAL_NET_TCP_AND_TLS_SUPPORT // socket options below supported only if TCP is supported.
ram54288 0:a7a43371b306 66 PAL_SO_KEEPALIVE = 0x0008, /*! keep TCP connection open even if idle using periodic messages*/
ram54288 0:a7a43371b306 67 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:a7a43371b306 68 PAL_SO_SNDTIMEO = 0x1005, /*! send timeout */
ram54288 0:a7a43371b306 69 PAL_SO_RCVTIMEO = 0x1006, /*! receive timeout */
ram54288 0:a7a43371b306 70 } palSocketOptionName_t;/*! socket options supported by PAL */
ram54288 0:a7a43371b306 71
ram54288 0:a7a43371b306 72 #define PAL_NET_DEFAULT_INTERFACE 0xFFFFFFFF
ram54288 0:a7a43371b306 73
ram54288 0:a7a43371b306 74 #define PAL_IPV4_ADDRESS_SIZE 4
ram54288 0:a7a43371b306 75 #define PAL_IPV6_ADDRESS_SIZE 16
ram54288 0:a7a43371b306 76
ram54288 0:a7a43371b306 77 typedef uint8_t palIpV4Addr_t[PAL_IPV4_ADDRESS_SIZE];
ram54288 0:a7a43371b306 78 typedef uint8_t palIpV6Addr_t[PAL_IPV6_ADDRESS_SIZE];
ram54288 0:a7a43371b306 79
ram54288 0:a7a43371b306 80 typedef struct pal_timeVal{
ram54288 0:a7a43371b306 81 int32_t pal_tv_sec; /*! seconds */
ram54288 0:a7a43371b306 82 int32_t pal_tv_usec; /*! microseconds */
ram54288 0:a7a43371b306 83 } pal_timeVal_t;
ram54288 0:a7a43371b306 84
ram54288 0:a7a43371b306 85
ram54288 0:a7a43371b306 86 /*! Register a network interface for use with PAL sockets - must be called before other socket functions - most APIs will not work before a single interface is added.
ram54288 0:a7a43371b306 87 * @param[in] networkInterfaceContext of the network interface to be added (OS specific , e.g. in MbedOS this is the NetworkInterface object pointer for the network adapter [note: we assume connect has already been called on this]) - if not available use NULL .
ram54288 0:a7a43371b306 88 * @param[out] InterfaceIndex will contain the index assigned to the interface in case it has been assigned successfully. this index can be used when creating a socket to bind the socket to the interface.
ram54288 0:a7a43371b306 89 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 90 */
ram54288 0:a7a43371b306 91 palStatus_t pal_registerNetworkInterface(void* networkInterfaceContext, uint32_t* interfaceIndex);
ram54288 0:a7a43371b306 92
ram54288 0:a7a43371b306 93 /*! set a port to a palSocketAddress_t
ram54288 0:a7a43371b306 94 * setting it can be done either directly or via the palSetSockAddrIPV4Addr or palSetSockAddrIPV6Addr functions
ram54288 0:a7a43371b306 95 * @param[in,out] address the address to set
ram54288 0:a7a43371b306 96 * @param[in] port the port number to set
ram54288 0:a7a43371b306 97 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 98 \note for the socket to be set correctly the addressType field of the address must be set correctly.
ram54288 0:a7a43371b306 99 */
ram54288 0:a7a43371b306 100 palStatus_t pal_setSockAddrPort(palSocketAddress_t* address, uint16_t port);
ram54288 0:a7a43371b306 101
ram54288 0:a7a43371b306 102 /*! set an ipV4 address to a palSocketAddress_t and also set the addressType to ipv4
ram54288 0:a7a43371b306 103 * @param[in,out] address the address to set
ram54288 0:a7a43371b306 104 * @param[in] ipV4Addr the address value to set
ram54288 0:a7a43371b306 105 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 106 */
ram54288 0:a7a43371b306 107 palStatus_t pal_setSockAddrIPV4Addr(palSocketAddress_t* address, palIpV4Addr_t ipV4Addr);
ram54288 0:a7a43371b306 108
ram54288 0:a7a43371b306 109 /*! set an ipV6 address to a palSocketAddress_t and also set the addressType to ipv6
ram54288 0:a7a43371b306 110 * @param[in,out] address the address to set
ram54288 0:a7a43371b306 111 * @param[in] ipV6Addr the address value to set
ram54288 0:a7a43371b306 112 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 113 */
ram54288 0:a7a43371b306 114 palStatus_t pal_setSockAddrIPV6Addr(palSocketAddress_t* address, palIpV6Addr_t ipV6Addr);
ram54288 0:a7a43371b306 115
ram54288 0:a7a43371b306 116 /*! get an ipV4 address from a palSocketAddress_t
ram54288 0:a7a43371b306 117 * @param[in] address the address to set
ram54288 0:a7a43371b306 118 * @param[out] ipV4Addr the address that is set in the address
ram54288 0:a7a43371b306 119 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 120 */
ram54288 0:a7a43371b306 121 palStatus_t pal_getSockAddrIPV4Addr(const palSocketAddress_t* address, palIpV4Addr_t ipV4Addr);
ram54288 0:a7a43371b306 122
ram54288 0:a7a43371b306 123 /*! get an ipV6 address from a palSocketAddress_t
ram54288 0:a7a43371b306 124 * @param[in] address the address to set
ram54288 0:a7a43371b306 125 * @param[out] ipV6Addr the address that is set in the address
ram54288 0:a7a43371b306 126 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 127 */
ram54288 0:a7a43371b306 128 palStatus_t pal_getSockAddrIPV6Addr(const palSocketAddress_t* address, palIpV6Addr_t ipV6Addr);
ram54288 0:a7a43371b306 129
ram54288 0:a7a43371b306 130 /*! get a port from a palSocketAddress_t
ram54288 0:a7a43371b306 131 * @param[in] address the address to set
ram54288 0:a7a43371b306 132 * @param[out] port the port that is set in the address
ram54288 0:a7a43371b306 133 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 134 */
ram54288 0:a7a43371b306 135 palStatus_t pal_getSockAddrPort(const palSocketAddress_t* address, uint16_t* port);
ram54288 0:a7a43371b306 136
ram54288 0:a7a43371b306 137 /*! get a network socket
ram54288 0:a7a43371b306 138 * @param[in] domain the domain for the created socket (see palSocketDomain_t for supported types)
ram54288 0:a7a43371b306 139 * @param[in] type the type for the created socket (see palSocketType_t for supported types)
ram54288 0:a7a43371b306 140 * @param[in] nonBlockingSocket if true the socket created is created as non-blocking (i.e. with O_NONBLOCK set)
ram54288 0:a7a43371b306 141 * @param[in] interfaceNum the number of the network interface used for this socket (info in interfaces supported via pal_getNumberOfNetInterfaces and pal_getNetInterfaceInfo ), choose PAL_NET_DEFAULT_INTERFACE for default interface.
ram54288 0:a7a43371b306 142 * @param[out] socket socket is returned through this output parameter
ram54288 0:a7a43371b306 143 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 144 */
ram54288 0:a7a43371b306 145 palStatus_t pal_socket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palSocket_t* socket);
ram54288 0:a7a43371b306 146
ram54288 0:a7a43371b306 147 /*! get options for a given network socket
ram54288 0:a7a43371b306 148 * @param[in] socket the socket for which to get options
ram54288 0:a7a43371b306 149 * @param[in] optionName for which we are setting the option (see enum PAL_NET_SOCKET_OPTION for supported types)
ram54288 0:a7a43371b306 150 * @param[out] optionValue the buffer holding the option value returned by the function
ram54288 0:a7a43371b306 151 * @param[in, out] optionLength the size of the buffer provided for optionValue when calling the function after the call it will contain the length of data actually written to the optionValue buffer.
ram54288 0:a7a43371b306 152 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 153 */
ram54288 0:a7a43371b306 154 palStatus_t pal_getSocketOptions(palSocket_t socket, palSocketOptionName_t optionName, void* optionValue, palSocketLength_t* optionLength);
ram54288 0:a7a43371b306 155
ram54288 0:a7a43371b306 156 /*! set options for a given network socket
ram54288 0:a7a43371b306 157 * @param[in] socket the socket for which to get options
ram54288 0:a7a43371b306 158 * @param[in] optionName for which we are setting the option (see enum PAL_NET_SOCKET_OPTION for supported types)
ram54288 0:a7a43371b306 159 * @param[in] optionValue the buffer holding the option value to set for the given option
ram54288 0:a7a43371b306 160 * @param[in] optionLength the size of the buffer provided for optionValue
ram54288 0:a7a43371b306 161 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 162 */
ram54288 0:a7a43371b306 163 palStatus_t pal_setSocketOptions(palSocket_t socket, int optionName, const void* optionValue, palSocketLength_t optionLength);
ram54288 0:a7a43371b306 164
ram54288 0:a7a43371b306 165 /*! bind a given socket to a local address
ram54288 0:a7a43371b306 166 * @param[in] socket the socket to bind
ram54288 0:a7a43371b306 167 * @param[in] myAddress the address to which to bind
ram54288 0:a7a43371b306 168 * @param[in] addressLength the length of the address passed in myAddress
ram54288 0:a7a43371b306 169 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 170 */
ram54288 0:a7a43371b306 171 palStatus_t pal_bind(palSocket_t socket, palSocketAddress_t* myAddress, palSocketLength_t addressLength);
ram54288 0:a7a43371b306 172
ram54288 0:a7a43371b306 173 /*! receive a payload from the given socket
ram54288 0:a7a43371b306 174 * @param[in] socket the socket to receive from [we expect sockets passed to this function to be of type PAL_SOCK_DGRAM ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 175 * @param[out] buffer the buffer for the payload data
ram54288 0:a7a43371b306 176 * @param[in] length of the buffer for the payload data
ram54288 0:a7a43371b306 177 * @param[out] from the address which sent the payload
ram54288 0:a7a43371b306 178 * @param[in, out] fromLength the length of the 'from' address, after completion will contain the amount of data actually written to the from address
ram54288 0:a7a43371b306 179 * @param[out] bytesReceived after the call will contain the actual amount of payload data received to the buffer
ram54288 0:a7a43371b306 180 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 181 */
ram54288 0:a7a43371b306 182 palStatus_t pal_receiveFrom(palSocket_t socket, void* buffer, size_t length, palSocketAddress_t* from, palSocketLength_t* fromLength, size_t* bytesReceived);
ram54288 0:a7a43371b306 183
ram54288 0:a7a43371b306 184 /*! send a payload to the given address using the given socket
ram54288 0:a7a43371b306 185 * @param[in] socket the socket to use for sending the payload [we expect sockets passed to this function to be of type PAL_SOCK_DGRAM ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 186 * @param[in] buffer the buffer for the payload data
ram54288 0:a7a43371b306 187 * @param[in] length of the buffer for the payload data
ram54288 0:a7a43371b306 188 * @param[in] to the address to which to payload should be sent
ram54288 0:a7a43371b306 189 * @param[in] toLength the length of the 'to' address
ram54288 0:a7a43371b306 190 * @param[out] bytesSent after the call will contain the actual amount of payload data sent
ram54288 0:a7a43371b306 191 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 192 */
ram54288 0:a7a43371b306 193 palStatus_t pal_sendTo(palSocket_t socket, const void* buffer, size_t length, const palSocketAddress_t* to, palSocketLength_t toLength, size_t* bytesSent);
ram54288 0:a7a43371b306 194
ram54288 0:a7a43371b306 195 /*! close a network socket
ram54288 0:a7a43371b306 196 * @param[in,out] socket release and zero socket pointed to by given pointer.
ram54288 0:a7a43371b306 197 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 198 \note recieves palSocket_t* and not palSocket_t so that it can zero the socket to avoid re-use.
ram54288 0:a7a43371b306 199 */
ram54288 0:a7a43371b306 200 palStatus_t pal_close(palSocket_t* socket);
ram54288 0:a7a43371b306 201
ram54288 0:a7a43371b306 202 /*! get the number of current network interfaces
ram54288 0:a7a43371b306 203 * @param[out] numInterfaces will hold the number of interfaces after a successful call
ram54288 0:a7a43371b306 204 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 205 */
ram54288 0:a7a43371b306 206 palStatus_t pal_getNumberOfNetInterfaces(uint32_t* numInterfaces);
ram54288 0:a7a43371b306 207
ram54288 0:a7a43371b306 208 /*! get information regarding the socket at the index/interface number given (this number is returned when registering the socket)
ram54288 0:a7a43371b306 209 * @param[in] interfaceNum the number of the interface to get information for.
ram54288 0:a7a43371b306 210 * @param[out] interfaceInfo will be set to the information for the given interface number.
ram54288 0:a7a43371b306 211 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 212 */
ram54288 0:a7a43371b306 213 palStatus_t pal_getNetInterfaceInfo(uint32_t interfaceNum, palNetInterfaceInfo_t* interfaceInfo);
ram54288 0:a7a43371b306 214
ram54288 0:a7a43371b306 215
ram54288 0:a7a43371b306 216 #define PAL_NET_SOCKET_SELECT_MAX_SOCKETS 8
ram54288 0:a7a43371b306 217 #define PAL_NET_SOCKET_SELECT_RX_BIT (1)
ram54288 0:a7a43371b306 218 #define PAL_NET_SOCKET_SELECT_TX_BIT (2)
ram54288 0:a7a43371b306 219 #define PAL_NET_SOCKET_SELECT_ERR_BIT (4)
ram54288 0:a7a43371b306 220
ram54288 0:a7a43371b306 221 #define PAL_NET_SELECT_IS_RX(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_RX_BIT) != 0) /*! check if RX bit is set in select result for a given socket index*/
ram54288 0:a7a43371b306 222 #define PAL_NET_SELECT_IS_TX(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_TX_BIT) != 0) /*! check if TX bit is set in select result for a given socket index*/
ram54288 0:a7a43371b306 223 #define PAL_NET_SELECT_IS_ERR(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_ERR_BIT) != 0) /*! check if ERR bit is set in select result for a given socket index*/
ram54288 0:a7a43371b306 224
ram54288 0:a7a43371b306 225 /*! check if one or more (up to PAL_NET_SOCKET_SELECT_MAX_SOCKETS) sockets given has data available for reading/writing/error, the function will block until data is available for one of the given sockets or the timeout expires.
ram54288 0:a7a43371b306 226 To use the function: set the sockets you want to check in the socketsToCheck array and set a timeout, when it returns the socketStatus output will indicate the status of each socket passed in.
ram54288 0:a7a43371b306 227 * @param[in] socketsToCheck on input: the array of up to 8 sockets handles to check.
ram54288 0:a7a43371b306 228 * @param[in] numberOfSockets the number of sockets set in the input socketsToCheck array.
ram54288 0:a7a43371b306 229 * @param[in] timeout the amount of time till timeout if no socket activity is detected
ram54288 0:a7a43371b306 230 * @param[out] socketStatus will provide information on each socket in the input array indicating which event was set (none, rx, tx, err) check for desired event using macros.
ram54288 0:a7a43371b306 231 * @param[out] numberOfSocketsSet is the total number of sockets set in all three data sets (tx, rx, err)after the function completes
ram54288 0:a7a43371b306 232 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 233 \note the entry in index x in the socketStatus array corresponds to the socket at index x in the sockets to check array.
ram54288 0:a7a43371b306 234 */
ram54288 0:a7a43371b306 235 palStatus_t pal_socketMiniSelect(const palSocket_t socketsToCheck[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t numberOfSockets, pal_timeVal_t* timeout,
ram54288 0:a7a43371b306 236 uint8_t palSocketStatus[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t* numberOfSocketsSet);
ram54288 0:a7a43371b306 237
ram54288 0:a7a43371b306 238
ram54288 0:a7a43371b306 239 #if PAL_NET_TCP_AND_TLS_SUPPORT // functionality below supported only in case TCP is supported.
ram54288 0:a7a43371b306 240
ram54288 0:a7a43371b306 241
ram54288 0:a7a43371b306 242 /*! use given socket to listed for incoming connections, may also limit queue of incoming connections.
ram54288 0:a7a43371b306 243 * @param[in] socket the socket to listen on [we expect sockets passed to this function to be of type PAL_SOCK_STREAM_SERVER ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 244 * @param[in] backlog the amount connections of pending connections which can be saved for the socket
ram54288 0:a7a43371b306 245 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 246 */
ram54288 0:a7a43371b306 247 palStatus_t pal_listen(palSocket_t socket, int backlog);
ram54288 0:a7a43371b306 248
ram54288 0:a7a43371b306 249 /*! accept a connection on the given socket
ram54288 0:a7a43371b306 250 * @param[in] socket the socket on which to accept the connection (prerequisite: socket already created and bind and listen have been called on it ) [we expect sockets passed to this function to be of type PAL_SOCK_STREAM_SERVER ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 251 * @param[out] address the source address of the incoming connection
ram54288 0:a7a43371b306 252 * @param[in, out] addressLen the length of the address field on input, the length of the data returned on output.
ram54288 0:a7a43371b306 253 * @param[out] acceptedSocket the socket of the accepted connection will be returned here if connection accepted successfully.
ram54288 0:a7a43371b306 254
ram54288 0:a7a43371b306 255 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 256 */
ram54288 0:a7a43371b306 257 palStatus_t pal_accept(palSocket_t socket, palSocketAddress_t* address, palSocketLength_t* addressLen, palSocket_t* acceptedSocket);
ram54288 0:a7a43371b306 258
ram54288 0:a7a43371b306 259 /*! open a connection from the given socket to the given address
ram54288 0:a7a43371b306 260 * @param[in] socket the socket to use for connection to the given address [we expect sockets passed to this function to be of type PAL_SOCK_STREAM ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 261 * @param[in] address the destination address of the connection
ram54288 0:a7a43371b306 262 * @param[in] addressLen the length of the address field
ram54288 0:a7a43371b306 263 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 264 */
ram54288 0:a7a43371b306 265 palStatus_t pal_connect(palSocket_t socket, const palSocketAddress_t* address, palSocketLength_t addressLen);
ram54288 0:a7a43371b306 266
ram54288 0:a7a43371b306 267 /*! receive data from the given connected socket
ram54288 0:a7a43371b306 268 * @param[in] socket the connected socket on which to receive data [we expect sockets passed to this function to be of type PAL_SOCK_STREAM ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 269 * @param[out] buf the output buffer for the message data
ram54288 0:a7a43371b306 270 * @param[in] len the length of the input data buffer
ram54288 0:a7a43371b306 271 * @param[out] recievedDataSize the length of the data actually received
ram54288 0:a7a43371b306 272 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 273 */
ram54288 0:a7a43371b306 274 palStatus_t pal_recv(palSocket_t socket, void* buf, size_t len, size_t* recievedDataSize);
ram54288 0:a7a43371b306 275
ram54288 0:a7a43371b306 276 /*! send a given buffer via the given connected socket
ram54288 0:a7a43371b306 277 * @param[in] socket the connected socket on which to send data [we expect sockets passed to this function to be of type PAL_SOCK_STREAM ( the implementation may support other types as well) ]
ram54288 0:a7a43371b306 278 * @param[in] buf the output buffer for the message data
ram54288 0:a7a43371b306 279 * @param[in] len the length of the input data buffer
ram54288 0:a7a43371b306 280 * @param[out] sentDataSize the length of the data sent
ram54288 0:a7a43371b306 281 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 282 */
ram54288 0:a7a43371b306 283 palStatus_t pal_send(palSocket_t socket, const void* buf, size_t len, size_t* sentDataSize);
ram54288 0:a7a43371b306 284
ram54288 0:a7a43371b306 285
ram54288 0:a7a43371b306 286 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:a7a43371b306 287
ram54288 0:a7a43371b306 288
ram54288 0:a7a43371b306 289 #if PAL_NET_ASYNCHRONOUS_SOCKET_API
ram54288 0:a7a43371b306 290
ram54288 0:a7a43371b306 291 /*! callback function called when an even happens an asynchronous socket for which it was set using the pal_asynchronousSocket.
ram54288 0:a7a43371b306 292 */
ram54288 0:a7a43371b306 293 typedef void(*palAsyncSocketCallback_t)();
ram54288 0:a7a43371b306 294
ram54288 0:a7a43371b306 295 /*! get an asynchronous network socket
ram54288 0:a7a43371b306 296 * @param[in] domain the domain for the created socket (see enum palSocketDomain_t for supported types)
ram54288 0:a7a43371b306 297 * @param[in] type the type for the created socket (see enum palSocketType_t for supported types)
ram54288 0:a7a43371b306 298 * @param[in] nonBlockingSocket if true the socket created is created as non-blocking (i.e. with O_NONBLOCK set)
ram54288 0:a7a43371b306 299 * @param[in] interfaceNum the number of the network interface used for this socket (info in interfaces supported via pal_getNumberOfNetInterfaces and pal_getNetInterfaceInfo ), choose PAL_NET_DEFAULT_INTERFACE for default interface.
ram54288 0:a7a43371b306 300 * @param[in] callback a callback function that will be called when any supported event happens to the given asynchronous socket (see palAsyncSocketCallbackType enum for the types of events supported)
ram54288 0:a7a43371b306 301 * @param[out] socket socket is returned through this output parameter
ram54288 0:a7a43371b306 302 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:a7a43371b306 303 */
ram54288 0:a7a43371b306 304 palStatus_t pal_asynchronousSocket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palAsyncSocketCallback_t callback, palSocket_t* socket);
ram54288 0:a7a43371b306 305
ram54288 0:a7a43371b306 306 #endif
ram54288 0:a7a43371b306 307
ram54288 0:a7a43371b306 308 #if PAL_NET_DNS_SUPPORT
ram54288 0:a7a43371b306 309
ram54288 0:a7a43371b306 310 /*! this function will translate from a URL to a palSocketAddress_t which can be used with pal sockets. It supports both IP address as strings and URLs (using DNS lookup).
ram54288 0:a7a43371b306 311 * @param[in] url the URL (or IP address sting) to be translated into a palSocketAddress_t.
ram54288 0:a7a43371b306 312 * @param[out] address the address for the output of the translation.
ram54288 0:a7a43371b306 313 */
ram54288 0:a7a43371b306 314 palStatus_t pal_getAddressInfo(const char* url, palSocketAddress_t* address, palSocketLength_t* addressLength);
ram54288 0:a7a43371b306 315
ram54288 0:a7a43371b306 316 #endif
ram54288 0:a7a43371b306 317
ram54288 0:a7a43371b306 318 #ifdef __cplusplus
ram54288 0:a7a43371b306 319 }
ram54288 0:a7a43371b306 320 #endif
ram54288 0:a7a43371b306 321 #endif //_PAL_SOCKET_H
ram54288 0:a7a43371b306 322
ram54288 0:a7a43371b306 323