Mistake on this page? Email us
pal_plat_network.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2016, 2017 ARM Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 
18 #ifndef _PAL_PLAT_SOCKET_H
19 #define _PAL_PLAT_SOCKET_H
20 
21 #include "pal.h"
22 #include "pal_network.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
44 palStatus_t pal_plat_socketsInit(void* context);
45 
55 palStatus_t pal_plat_registerNetworkInterface(void* networkInterfaceContext, uint32_t* interfaceIndex);
56 
61 palStatus_t pal_plat_unregisterNetworkInterface(uint32_t interfaceIndex);
62 
70 
80 palStatus_t pal_plat_setSocketOptions(palSocket_t socket, int optionName, const void* optionValue, palSocketLength_t optionLength);
81 
90 palStatus_t pal_plat_setSocketOptionsWithLevel(palSocket_t socket, palSocketOptionLevelName_t optionLevel, int optionName, const void* optionValue, palSocketLength_t optionLength);
91 
97 palStatus_t pal_plat_isNonBlocking(palSocket_t socket, bool* isNonBlocking);
98 
106 
116 palStatus_t pal_plat_receiveFrom(palSocket_t socket, void* buffer, size_t length, palSocketAddress_t* from, palSocketLength_t* fromLength, size_t* bytesReceived);
117 
127 palStatus_t pal_plat_sendTo(palSocket_t socket, const void* buffer, size_t length, const palSocketAddress_t* to, palSocketLength_t toLength, size_t* bytesSent);
128 
135 
142 palStatus_t pal_plat_getNumberOfNetInterfaces(uint32_t* numInterfaces);
143 
149 palStatus_t pal_plat_getNetInterfaceInfo(uint32_t interfaceNum, palNetInterfaceInfo_t* interfaceInfo);
150 
151 #if PAL_NET_TCP_AND_TLS_SUPPORT // The functionality below is supported only if TCP is supported.
152 
153 #if PAL_NET_SERVER_SOCKET_API
154 
162 palStatus_t pal_plat_listen(palSocket_t socket, int backlog);
163 
173 palStatus_t pal_plat_accept(palSocket_t socket, palSocketAddress_t* address, palSocketLength_t* addressLen, palSocket_t* acceptedSocket, palAsyncSocketCallback_t callback, void* callbackArgument);
174 
175 #endif // PAL_NET_SERVER_SOCKET_API
176 
183 palStatus_t pal_plat_connect(palSocket_t socket, const palSocketAddress_t* address, palSocketLength_t addressLen);
184 
192 palStatus_t pal_plat_recv(palSocket_t socket, void* buf, size_t len, size_t* recievedDataSize);
193 
201 palStatus_t pal_plat_send(palSocket_t socket, const void* buf, size_t len, size_t* sentDataSize);
202 
209 palStatus_t pal_plat_setConnectionStatusCallback(uint32_t interfaceIndex, connectionStatusCallback callback, void *client_arg);
210 
211 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
212 
221 palStatus_t pal_plat_asynchronousSocket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palAsyncSocketCallback_t callback, void* callbackArgument , palSocket_t* socket);
222 
223 #if PAL_NET_DNS_SUPPORT
224 #if (PAL_DNS_API_VERSION == 0) || (PAL_DNS_API_VERSION == 1)
225 
231 palStatus_t pal_plat_getAddressInfo(const char* hostname, palSocketAddress_t* address, palSocketLength_t* addressLength);
232 
233 #elif (PAL_DNS_API_VERSION == 2) || (PAL_DNS_API_VERSION == 3)
234 #if (PAL_DNS_API_VERSION == 3)
235 
241 palStatus_t pal_plat_getDNSAddress(palAddressInfo_t *addrInfo, uint16_t index, palSocketAddress_t *addr);
242 
247 int pal_plat_getDNSCount(palAddressInfo_t *addrInfo);
248 
252 void pal_plat_freeAddrInfo(palAddressInfo_t* addrInfo);
253 
256 palStatus_t pal_plat_free_addressinfoAsync(palDNSQuery_t queryHandle);
257 #endif
258 
262 palStatus_t pal_plat_getAddressInfoAsync(pal_asyncAddressInfo_t* info);
263 
267 palStatus_t pal_plat_cancelAddressInfoAsync(palDNSQuery_t queryHandle);
268 #else
269  #error "Please specify the platform PAL_DNS_API_VERSION 0, 1, 2 or 3."
270 #endif // PAL_DNS_API_VERSION
271 
272 #endif // PAL_NET_DNS_SUPPORT
273 
283 uint8_t pal_plat_getRttEstimate();
284 
294 uint16_t pal_plat_getStaggerEstimate(uint16_t data_amount);
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 #endif //_PAL_PLAT_SOCKET_H
PAL. This file contains the general API to initiate and destroy the PAL component. This is part of the PAL service API.
palStatus_t pal_plat_isNonBlocking(palSocket_t socket, bool *isNonBlocking)
Check if a socket is non-blocking.
palStatus_t pal_plat_asynchronousSocket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palAsyncSocketCallback_t callback, void *callbackArgument, palSocket_t *socket)
Get an asynchronous network socket.
uint16_t pal_plat_getStaggerEstimate(uint16_t data_amount)
This function returns the stagger estimate for registration in seconds.
PAL network. This file contains the network APIs and it is a part of the PAL service API...
palStatus_t pal_plat_getNumberOfNetInterfaces(uint32_t *numInterfaces)
Get the number of current network interfaces.
uint32_t palSocketLength_t
The length of data.
Definition: pal_network.h:43
void * palSocket_t
PAL socket handle type.
Definition: pal_network.h:44
palStatus_t pal_plat_sendTo(palSocket_t socket, const void *buffer, size_t length, const palSocketAddress_t *to, palSocketLength_t toLength, size_t *bytesSent)
Send a payload to an address using a specific socket.
palSocketOptionLevelName_t
Socket protocol level options supported by PAL.
Definition: pal_network.h:102
palStatus_t pal_plat_registerNetworkInterface(void *networkInterfaceContext, uint32_t *interfaceIndex)
Register a network interface for use with PAL sockets.
palStatus_t pal_plat_setSocketOptions(palSocket_t socket, int optionName, const void *optionValue, palSocketLength_t optionLength)
Set options for a network socket.
palStatus_t pal_plat_socketsTerminate(void *context)
Socket termination.
palSocketType_t
Socket types supported by PAL.
Definition: pal_network.h:79
Definition: pal_network.h:59
palStatus_t pal_plat_receiveFrom(palSocket_t socket, void *buffer, size_t length, palSocketAddress_t *from, palSocketLength_t *fromLength, size_t *bytesReceived)
Receive a payload from a socket.
uint8_t pal_plat_getRttEstimate()
This function returns the round-trip estimate for packet in seconds.
palStatus_t pal_plat_close(palSocket_t *socket)
Close a network socket.
palStatus_t pal_plat_socketsInit(void *context)
Initialize sockets.
void(* connectionStatusCallback)(palNetworkStatus_t status, void *client_arg)
Definition: pal_network.h:115
palStatus_t pal_plat_getNetInterfaceInfo(uint32_t interfaceNum, palNetInterfaceInfo_t *interfaceInfo)
Get information regarding a socket at a specific interface number.
void(* palAsyncSocketCallback_t)(void *)
The type of the callback function passed when creating asynchronous sockets.
Definition: pal_network.h:284
palStatus_t pal_plat_unregisterNetworkInterface(uint32_t interfaceIndex)
palStatus_t pal_plat_bind(palSocket_t socket, palSocketAddress_t *myAddress, palSocketLength_t addressLength)
Bind a socket to a local address.
int32_t palStatus_t
Definition: pal_types.h:55
palSocketDomain_t
Network domains supported by PAL.
Definition: pal_network.h:66
Definition: pal_network.h:48
palStatus_t pal_plat_setSocketOptionsWithLevel(palSocket_t socket, palSocketOptionLevelName_t optionLevel, int optionName, const void *optionValue, palSocketLength_t optionLength)
Set the value for a socket option on a network socket.