forked from open62541/open62541
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventloop_posix.h
109 lines (80 loc) · 3.1 KB
/
eventloop_posix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2021 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
* Copyright 2021 (c) Fraunhofer IOSB (Author: Jan Hermes)
*/
#ifndef UA_EVENTLOOP_POSIX_H_
#define UA_EVENTLOOP_POSIX_H_
#include <open62541/config.h>
#include <open62541/plugin/eventloop.h>
#if defined(UA_ARCHITECTURE_POSIX) || defined(UA_ARCHITECTURE_WIN32)
#include "common/ua_timer.h"
#include "open62541_queue.h"
/* epoll_pwait returns bogus data with the tc compiler */
#if defined(__linux__) && !defined(__TINYC__)
# define UA_HAVE_EPOLL
# include <sys/epoll.h>
#endif
_UA_BEGIN_DECLS
/* POSIX events are based on sockets / file descriptors. The EventSources can
* register their fd in the EventLoop so that they are considered by the
* EventLoop dropping into "poll" to wait for events. */
/* TODO: Move the macro-forest from /arch/<arch>/ua_architecture.h */
#define UA_FD UA_SOCKET
#define UA_INVALID_FD UA_INVALID_SOCKET
struct UA_RegisteredFD;
typedef struct UA_RegisteredFD UA_RegisteredFD;
/* Bitmask to be used for the UA_FDCallback event argument */
#define UA_FDEVENT_IN 1
#define UA_FDEVENT_OUT 2
#define UA_FDEVENT_ERR 4
typedef void (*UA_FDCallback)(UA_EventSource *es, UA_RegisteredFD *rfd, short event);
struct UA_RegisteredFD {
UA_DelayedCallback dc; /* Used for async closing. Must be the first member
* because the rfd is freed by the delayed callback
* mechanism. */
LIST_ENTRY(UA_RegisteredFD) es_pointers; /* Register FD in the EventSource */
UA_FD fd;
short listenEvents; /* UA_FDEVENT_IN | UA_FDEVENT_OUT*/
UA_EventSource *es; /* Backpointer to the EventSource */
UA_FDCallback callback;
void *application;
void *context;
};
typedef struct {
UA_EventLoop eventLoop;
/* Timer */
UA_Timer timer;
/* Linked List of Delayed Callbacks */
UA_DelayedCallback *delayedCallbacks;
/* Flag determining whether the eventloop is currently within the
* "run" method */
UA_Boolean executing;
#if defined(UA_HAVE_EPOLL)
UA_FD epollfd;
#else
/* Explicit list of file descriptors */
size_t fdsSize;
UA_RegisteredFD **fds;
#endif
#if UA_MULTITHREADING >= 100
UA_Lock elMutex;
#endif
} UA_EventLoopPOSIX;
/* The following functions differ between epoll and normal select */
/* Register to start receiving events */
UA_StatusCode
UA_EventLoopPOSIX_registerFD(UA_EventLoopPOSIX *el, UA_RegisteredFD *rfd);
/* Modify the events that the fd listens on */
UA_StatusCode
UA_EventLoopPOSIX_modifyFD(UA_EventLoopPOSIX *el, UA_RegisteredFD *rfd);
/* Deregister but do not close the fd. No further events are received. */
void
UA_EventLoopPOSIX_deregisterFD(UA_EventLoopPOSIX *el, UA_RegisteredFD *rfd);
UA_StatusCode
UA_EventLoopPOSIX_pollFDs(UA_EventLoopPOSIX *el, UA_DateTime listenTimeout);
_UA_END_DECLS
#endif /* defined(UA_ARCHITECTURE_POSIX) || defined(UA_ARCHITECTURE_WIN32) */
#endif /* UA_EVENTLOOP_POSIX_H_ */