libiec61850  1.2.0
hal_socket.h
Go to the documentation of this file.
1 /*
2  * socket_hal.h
3  *
4  * Copyright 2013, 2014 Michael Zillgith
5  *
6  * This file is part of libIEC61850.
7  *
8  * libIEC61850 is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * libIEC61850 is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * See COPYING file for the complete license text.
22  */
23 
24 #ifndef SOCKET_HAL_H_
25 #define SOCKET_HAL_H_
26 
27 #include <stdint.h>
28 #include <stdbool.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
49 typedef struct sServerSocket* ServerSocket;
50 
52 typedef struct sSocket* Socket;
53 
55 typedef struct sHandleSet* HandleSet;
56 
62 HandleSet
63 Handleset_new(void);
64 
71 void
72 Handleset_addSocket(HandleSet self, const Socket sock);
73 
86 int
87 Handleset_waitReady(HandleSet self, unsigned int timeoutMs);
88 
94 void
95 Handleset_destroy(HandleSet self);
96 
107 ServerSocket
108 TcpServerSocket_create(const char* address, int port);
109 
110 
111 void
112 ServerSocket_listen(ServerSocket self);
113 
128 Socket
129 ServerSocket_accept(ServerSocket self);
130 
131 
141 void
142 ServerSocket_setBacklog(ServerSocket self, int backlog);
143 
153 void
154 ServerSocket_destroy(ServerSocket self);
155 
163 Socket
164 TcpSocket_create(void);
165 
172 void
173 Socket_setConnectTimeout(Socket self, uint32_t timeoutInMs);
174 
193 bool
194 Socket_connect(Socket self, const char* address, int port);
195 
212 int
213 Socket_read(Socket self, uint8_t* buf, int size);
214 
224 int
225 Socket_write(Socket self, uint8_t* buf, int size);
226 
238 char*
239 Socket_getPeerAddress(Socket self);
240 
251 void
252 Socket_destroy(Socket self);
253 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif /* SOCKET_HAL_H_ */
void ServerSocket_listen(ServerSocket self)
Socket ServerSocket_accept(ServerSocket self)
accept a new incoming connection (non-blocking)
int Socket_read(Socket self, uint8_t *buf, int size)
read from socket to local buffer (non-blocking)
void ServerSocket_destroy(ServerSocket self)
destroy a server socket instance
bool Socket_connect(Socket self, const char *address, int port)
connect to a server
struct sHandleSet * HandleSet
Definition: hal_socket.h:55
ServerSocket TcpServerSocket_create(const char *address, int port)
Create a new TcpServerSocket instance.
HandleSet Handleset_new(void)
Create a new connection handle set (HandleSet)
int Socket_write(Socket self, uint8_t *buf, int size)
send a message through the socket
struct sServerSocket * ServerSocket
Definition: hal_socket.h:49
void Socket_setConnectTimeout(Socket self, uint32_t timeoutInMs)
set the timeout to establish a new connection
int Handleset_waitReady(HandleSet self, unsigned int timeoutMs)
wait for a socket to become ready
struct sSocket * Socket
Definition: hal_socket.h:52
Socket TcpSocket_create(void)
create a TCP client socket
void ServerSocket_setBacklog(ServerSocket self, int backlog)
set the maximum number of pending connection in the queue
char * Socket_getPeerAddress(Socket self)
Get the address of the peer application (IP address and port number)
void Handleset_addSocket(HandleSet self, const Socket sock)
add a socket to an existing handle set
void Handleset_destroy(HandleSet self)
destroy the HandleSet instance
void Socket_destroy(Socket self)
destroy a socket (close the socket if a connection is established)