lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
hal_socket.h
Go to the documentation of this file.
1 /*
2  * socket_hal.h
3  *
4  * Copyright 2013-2021 Michael Zillgith
5  *
6  * This file is part of Platform Abstraction Layer (libpal)
7  * for libiec61850, libmms, and lib60870.
8  */
9 
10 #ifndef SOCKET_HAL_H_
11 #define SOCKET_HAL_H_
12 
13 #include "hal_base.h"
14 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
44 typedef struct sServerSocket* ServerSocket;
45 
46 typedef struct sUdpSocket* UdpSocket;
47 
49 typedef struct sSocket* Socket;
50 
52 typedef struct sHandleSet* HandleSet;
53 
55 typedef enum
56 {
57  SOCKET_STATE_CONNECTING = 0,
58  SOCKET_STATE_FAILED = 1,
59  SOCKET_STATE_CONNECTED = 2
60 } SocketState;
61 
62 
68 PAL_API HandleSet
70 
74 PAL_API void
76 
83 PAL_API void
85 
89 void
91 
107 PAL_API int
108 Handleset_waitReady(HandleSet self, unsigned int timeoutMs);
109 
115 PAL_API void
117 
128 PAL_API ServerSocket
129 TcpServerSocket_create(const char* address, int port);
130 
131 PAL_API UdpSocket
132 UdpSocket_create(void);
133 
134 PAL_API bool
135 UdpSocket_bind(UdpSocket self, const char* address, int port);
136 
137 PAL_API bool
138 UdpSocket_sendTo(UdpSocket self, const char* address, int port, uint8_t* msg, int msgSize);
139 
151 PAL_API int
152 UdpSocket_receiveFrom(UdpSocket self, char* address, int maxAddrSize, uint8_t* msg, int msgSize);
153 
154 
155 PAL_API void
156 ServerSocket_listen(ServerSocket self);
157 
172 PAL_API Socket
174 
185 PAL_API void
186 Socket_activateTcpKeepAlive(Socket self, int idleTime, int interval, int count);
187 
197 PAL_API void
199 
209 PAL_API void
211 
219 PAL_API Socket
221 
228 PAL_API void
229 Socket_setConnectTimeout(Socket self, uint32_t timeoutInMs);
230 
242 PAL_API bool
243 Socket_bind(Socket self, const char* srcAddress, int srcPort);
244 
263 PAL_API bool
264 Socket_connect(Socket self, const char* address, int port);
265 
266 PAL_API bool
267 Socket_connectAsync(Socket self, const char* address, int port);
268 
269 PAL_API SocketState
270 Socket_checkAsyncConnectState(Socket self);
271 
288 PAL_API int
289 Socket_read(Socket self, uint8_t* buf, int size);
290 
300 PAL_API int
301 Socket_write(Socket self, uint8_t* buf, int size);
302 
303 PAL_API char*
304 Socket_getLocalAddress(Socket self);
305 
317 PAL_API char*
319 
334 PAL_API char*
335 Socket_getPeerAddressStatic(Socket self, char* peerAddressString);
336 
347 PAL_API void
349 
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* SOCKET_HAL_H_ */
PAL_API HandleSet Handleset_new(void)
Create a new connection handle set (HandleSet)
PAL_API bool Socket_bind(Socket self, const char *srcAddress, int srcPort)
bind a socket to a particular IP address and port (for TcpSocket)
PAL_API ServerSocket TcpServerSocket_create(const char *address, int port)
Create a new TcpServerSocket instance.
PAL_API char * Socket_getPeerAddress(Socket self)
Get the address of the peer application (IP address and port number)
PAL_API int Socket_write(Socket self, uint8_t *buf, int size)
send a message through the socket
PAL_API int UdpSocket_receiveFrom(UdpSocket self, char *address, int maxAddrSize, uint8_t *msg, int msgSize)
Receive data from UDP socket (store data and (optionally) the IP address of the sender.
PAL_API Socket TcpSocket_create(void)
create a TCP client socket
PAL_API void Handleset_addSocket(HandleSet self, const Socket sock)
add a socket to an existing handle set
PAL_API int Socket_read(Socket self, uint8_t *buf, int size)
read from socket to local buffer (non-blocking)
PAL_API int Handleset_waitReady(HandleSet self, unsigned int timeoutMs)
wait for a socket to become ready
PAL_API bool Socket_connect(Socket self, const char *address, int port)
connect to a server
PAL_API void Socket_destroy(Socket self)
destroy a socket (close the socket if a connection is established)
struct sHandleSet * HandleSet
Definition: hal_socket.h:52
PAL_API char * Socket_getPeerAddressStatic(Socket self, char *peerAddressString)
Get the address of the peer application (IP address and port number)
PAL_API Socket ServerSocket_accept(ServerSocket self)
accept a new incoming connection (non-blocking)
PAL_API void ServerSocket_setBacklog(ServerSocket self, int backlog)
set the maximum number of pending connections in the queue
struct sSocket * Socket
Definition: hal_socket.h:49
PAL_API void Socket_activateTcpKeepAlive(Socket self, int idleTime, int interval, int count)
active TCP keep alive for socket and set keep alive parameters
PAL_API void ServerSocket_destroy(ServerSocket self)
destroy a server socket instance
PAL_API void Handleset_reset(HandleSet self)
Reset the handle set for reuse.
PAL_API void Handleset_destroy(HandleSet self)
destroy the HandleSet instance
PAL_API void Socket_setConnectTimeout(Socket self, uint32_t timeoutInMs)
set the timeout to establish a new connection
SocketState
Definition: hal_socket.h:56
struct sServerSocket * ServerSocket
Definition: hal_socket.h:44
void Handleset_removeSocket(HandleSet self, const Socket sock)
remove a socket from an existing handle set