34 #include <sys/epoll.h> 35 #include <sys/syslog.h> 52 #define DLT_EPOLL_TIMEOUT_MSEC 1000 72 dlt_log(LOG_CRIT,
"Creation of epoll instance failed!\n");
95 if ((pEvent ==
NULL) || (daemon ==
NULL) || (daemon_local ==
NULL))
105 nfds = epoll_wait(pEvent->
epfd,
119 "epoll_wait() failed: %s\n",
128 for (i = 0 ; i < nfds ; i++)
130 struct epoll_event *ev = &pEvent->
events[i];
137 if (con && con->receiver)
140 fd = con->receiver->fd;
150 if ((ev->events != EPOLLIN) && (ev->events != EPOLLOUT))
167 "Unable to find function for %d handle type.\n",
181 "Processing from %d handle type failed!\n",
232 while ((temp !=
NULL) && (temp->
id !=
id))
253 if (ev ==
NULL || to_remove ==
NULL)
260 while (*curr && (*curr != to_remove))
262 curr = &(*curr)->
next;
268 dlt_log(LOG_CRIT,
"Connection not found for removal.\n");
273 *curr = (*curr)->
next;
315 while (*temp !=
NULL)
317 temp = &(*temp)->
next;
341 if (!evhdl || !con || !con->
receiver)
345 "%s: wrong parameters (%p %p).\n",
360 "Deactivate connection type: %d\n",
364 if (epoll_ctl(evhdl->
epfd,
369 dlt_log(LOG_ERR,
"epoll_ctl() in deactivate failed!\n");
379 struct epoll_event ev;
381 ev.data.ptr = (
void *)con->
id;
385 "Activate connection type: %d\n",
390 if (epoll_ctl(evhdl->
epfd,
395 dlt_log(LOG_ERR,
"epoll_ctl() in activate failed!\n");
404 "Unknown connection status: %d\n",
434 if (!evhdl || !connection || !connection->
receiver) {
435 dlt_log(LOG_ERR,
"Wrong parameters when registering connection.\n");
476 if (evhdl ==
NULL || daemon_local ==
NULL)
488 dlt_log(LOG_ERR,
"Connection not found for unregistration.\n");
500 dlt_log(LOG_CRIT,
"Unregistering more client than registered!\n");
508 dlt_log(LOG_ERR,
"Unable to unregister event.\n");
DltConnection * dlt_event_handler_find_connection(DltEventHandler *ev, int fd)
Find connection with a specific fd in the connection list.
struct epoll_event events[DLT_EPOLL_MAX_EVENTS]
int dlt_event_handler_unregister_connection(DltEventHandler *evhdl, DltDaemonLocal *daemon_local, int fd)
Unregisters a connection from the event handler and destroys it.
struct DltConnection * next
DltConnectionStatus status
void dlt_event_handler_cleanup_connections(DltEventHandler *ev)
Destroy the connection list.
DltReturnValue dlt_log(int prio, char *s)
uintptr_t DltConnectionId
#define DLT_EPOLL_MAX_EVENTS
void * dlt_connection_get_callback(DltConnection *con)
Get the callback from a specific connection.
void dlt_connection_destroy(DltConnection *to_destroy)
Destroys a connection.
DltConnection * connections
int dlt_event_handler_register_connection(DltEventHandler *evhdl, DltDaemonLocal *daemon_local, DltConnection *connection, int mask)
Registers a connection for event handling and takes its ownership.
int dlt_connection_check_activate(DltEventHandler *evhdl, DltConnection *con, int activation_type)
Check for connection activation.
#define DLT_EPOLL_TIMEOUT_MSEC
STATIC void dlt_daemon_add_connection(DltEventHandler *ev, DltConnection *connection)
Add a new connection to the list.
static char str[DLT_DAEMON_TEXTBUFSIZE]
DltConnection * dlt_event_handler_find_connection_by_id(DltEventHandler *ev, DltConnectionId id)
Find connection with a specific id in the connection list.
STATIC int dlt_daemon_remove_connection(DltEventHandler *ev, DltConnection *to_remove)
Remove a connection from the list and destroy it.
int dlt_daemon_prepare_event_handling(DltEventHandler *ev)
Prepare the event handler.
#define DLT_DAEMON_TEXTBUFSIZE
int dlt_daemon_handle_event(DltEventHandler *pEvent, DltDaemon *daemon, DltDaemonLocal *daemon_local)
Catch and process incoming events.