60#define SU_WAIT_CMP(x, y) \
61 (((x).ident - (y).ident) ? ((x).ident - (y).ident) : ((x).flags - (y).flags))
64#define SU_WAIT_IN (EVFILT_READ)
66#define SU_WAIT_OUT (EVFILT_WRITE)
68#define SU_WAIT_CONNECT (EVFILT_WRITE)
70#define SU_WAIT_ERR (EV_ERROR)
72#define SU_WAIT_HUP (EV_EOF)
74#define SU_WAIT_ACCEPT (EVFILT_READ)
77#define SU_WAIT_FOREVER (-1)
79#define SU_WAIT_TIMEOUT (-2)
82#define SU_WAIT_INIT { INVALID_SOCKET, 0, 0, 0, 0, NULL }
85#define SU_WAIT_MAX (0x7fffffff)
87#elif SU_HAVE_POLL || DOCUMENTATION_ONLY
89#define SU_WAIT_CMP(x, y) \
90 (((x).fd - (y).fd) ? ((x).fd - (y).fd) : ((x).events - (y).events))
93#define SU_WAIT_IN (POLLIN)
95#define SU_WAIT_OUT (POLLOUT)
97#define SU_WAIT_CONNECT (POLLOUT)
99#define SU_WAIT_ERR (POLLERR)
101#define SU_WAIT_HUP (POLLHUP)
103#define SU_WAIT_ACCEPT (POLLIN)
106#define SU_WAIT_FOREVER (-1)
108#define SU_WAIT_TIMEOUT (-2)
111#define SU_WAIT_INIT { INVALID_SOCKET, 0, 0 }
114#define SU_WAIT_MAX (0x7fffffff)
118#define SU_WAIT_CMP(x, y) ((intptr_t)(x) - (intptr_t)(y))
120#define SU_WAIT_IN (FD_READ)
121#define SU_WAIT_OUT (FD_WRITE)
122#define SU_WAIT_CONNECT (FD_CONNECT)
123#define SU_WAIT_ERR (0)
124#define SU_WAIT_HUP (FD_CLOSE)
125#define SU_WAIT_ACCEPT (FD_ACCEPT)
127#define SU_WAIT_FOREVER (WSA_INFINITE)
128#define SU_WAIT_TIMEOUT (WSA_WAIT_TIMEOUT)
130#define SU_WAIT_INIT NULL
132#define SU_WAIT_MAX (64)
142#define POLLRDNORM 0x040
143#define POLLRDBAND 0x080
144#define POLLWRNORM 0x100
145#define POLLWRBAND 0x200
151#define POLLNVAL 0x020
153#define SU_WAIT_CMP(x, y) \
154 (((x).fd - (y).fd) ? ((x).fd - (y).fd) : ((x).events - (y).events))
156#define SU_WAIT_IN POLLIN
157#define SU_WAIT_OUT POLLOUT
158#define SU_WAIT_CONNECT POLLOUT
159#define SU_WAIT_ERR POLLERR
160#define SU_WAIT_HUP POLLHUP
161#define SU_WAIT_ACCEPT POLLIN
162#define SU_WAIT_FOREVER (-1)
163#define SU_WAIT_TIMEOUT (-2)
165#define SU_WAIT_INIT { INVALID_SOCKET, 0, 0 }
168#define SU_WAIT_MAX (0x7fffffff)
193typedef unsigned long int nfds_t;
200int poll (
struct pollfd *__fds, nfds_t __nfds,
int __timeout);
205typedef int su_success_t;
212#ifndef SU_ROOT_MAGIC_T
223#define SU_ROOT_MAGIC_T void
238#ifndef SU_WAKEUP_ARG_T
249#define SU_WAKEUP_ARG_T void
286#ifndef SU_PREPOLL_MAGIC_T
297#define SU_PREPOLL_MAGIC_T void
323#error SU_TIMER_T defined
326#ifndef SU_TIMER_ARG_T
330#define SU_TIMER_ARG_T void
344#ifndef SU_TIMER_QUEUE_T
345#define SU_TIMER_QUEUE_T su_timer_t *
348typedef SU_TIMER_QUEUE_T su_timer_queue_t;
363#define SU_TASK_R_INIT {{ NULL, NULL }}
366typedef _su_task_t
const *_su_task_r;
375#define SU_MSG_ARG_T void
394#define SU_MSG_R_INIT { NULL }
412#define SU_CLONE_T struct su_clone_s
419#define SU_CLONE_R_INIT {NULL}
438#if !HAVE_WIN32 && (SU_HAVE_POLL || HAVE_SELECT)
452 __attribute__((__malloc__));
465 int index,
int socket,
int events);
494 __attribute__((__malloc__));
498 __attribute__((__malloc__));
514SOFIAPUBFUN int su_timer_expire(su_timer_queue_t *
const,
538 int (*function)(
void *),
void *arg,
568 return msg && *msg != NULL;
571#define su_msg_is_non_null(msg) ((msg) && (*(msg)) != NULL)
592typedef su_port_t *su_port_create_f(
void);
593typedef int su_clone_start_f(
su_root_t *parent,
601SOFIAPUBFUN su_port_create_f su_default_port_create;
604SOFIAPUBFUN su_port_create_f su_wsaevent_port_create;
607SOFIAPUBFUN su_port_create_f su_devpoll_port_create;
609SOFIAPUBFUN su_clone_start_f su_default_clone_start;
612SOFIAPUBFUN su_clone_start_f su_wsaevent_clone_start;
615SOFIAPUBFUN su_clone_start_f su_devpoll_clone_start;
int su_root_size_hint
Hint for number of registered fds in su_root.
Definition su_root.c:118
Time in seconds and microsecondcs.
Definition su_time.h:57
Socket and network address interface.
int su_socket_t
Socket descriptor type.
Definition su.h:128
#define SOFIAPUBFUN
SOFIAPUBFUN declares an exported function.
Definition su_config.h:66
#define SOFIAPUBVAR
SOFIAPUBVAR declares an exported variable.
Definition su_config.h:68
Time types and functions.
int64_t su_dur64_t
Time offset (duration) in nanoseconds.
Definition su_time.h:50
long su_duration_t
Time difference in microseconds.
Definition su_time.h:70
uint64_t su_time64_t
Time in nanoseconds.
Definition su_time.h:44
su_task_r su_root_task(su_root_t const *root)
Get task reference.
Definition su_root.c:958
struct su_root_t su_root_t
Root object type.
Definition su_wait.h:210
SU_WAKEUP_ARG_T su_wakeup_arg_t
Wakeup callback argument type.
Definition su_wait.h:261
int su_clone_resume(su_clone_r)
Resume a clone.
Definition su_port.c:413
void su_msg_save(su_msg_r msg, su_msg_r msg0)
Save a message.
Definition su_root.c:1208
su_time_t su_timer_latest(su_timer_t const *t)
Return when the timer has been last expired.
Definition su_timer.c:356
int su_root_register(su_root_t *, su_wait_t *, su_wakeup_f, su_wakeup_arg_t *, int priority)
Register a su_wait_t object.
Definition su_root.c:644
void su_wait_init(su_wait_t dst[1])
Initialize a wait object.
Definition su_wait.c:106
int su_timer_is_set(su_timer_t const *t)
Check if the timer has been set.
Definition su_timer.c:339
void(* su_root_deinit_f)(su_root_t *, su_root_magic_t *)
Clone finalization function type.
Definition su_wait.h:425
int su_timer_set_interval(su_timer_t *t, su_timer_f, su_timer_arg_t *, su_duration_t)
Set the timer for the given interval.
Definition su_timer.c:374
int su_msg_send(su_msg_r msg)
Send a message.
Definition su_root.c:1325
int(* su_wakeup_f)(su_root_magic_t *, su_wait_t *, su_wakeup_arg_t *arg)
Wakeup callback function pointer type.
Definition su_wait.h:268
su_time64_t su_root_stamp64(su_root_t const *)
Get cached timestamp.
Definition su_root.c:748
su_task_r su_msg_from(su_msg_cr msg)
Get sending task.
Definition su_root.c:1279
su_timer_t * su_timer_create(su_task_r const, su_duration_t msec))
Create a timer.
Definition su_timer.c:297
int su_root_multishot(su_root_t *root, int multishot)
Set multishot mode.
Definition su_root.c:836
su_task_r su_root_parent(su_root_t const *root)
Get parent task reference.
Definition su_root.c:975
int su_msg_report(su_msg_r msg, su_msg_f report)
Add a delivery report function to a message.
Definition su_root.c:1120
struct _GSource * su_root_gsource(su_root_t *self)
Get a GSource.
Definition su_root.c:616
void su_root_destroy(su_root_t *)
Destroy a root object.
Definition su_root.c:501
su_duration_t su_root_sleep(su_root_t *root, su_duration_t)
Run event and message loop for given duration.
Definition su_root.c:916
int su_root_obtain(su_root_t *root)
Obtain the root port from other thread.
Definition su_root.c:1027
#define SU_MSG_ARG_T
Default type of su_msg_t message data.
Definition su_wait.h:375
void su_task_move(su_task_r dst, su_task_r src)
Moves a task handle.
Definition su_root.c:223
SU_ROOT_MAGIC_T su_root_magic_t
Root context pointer type.
Definition su_wait.h:236
void su_timer_destroy(su_timer_t *)
Destroy a timer.
Definition su_timer.c:322
void su_root_run(su_root_t *root)
Run event and message loop.
Definition su_root.c:856
int su_timer_set(su_timer_t *, su_timer_f, su_timer_arg_t *)
Set the timer for the default interval.
Definition su_timer.c:396
struct pollfd su_wait_t
Wait object.
Definition su_wait.h:184
void su_msg_function(su_root_magic_t *magic, su_msg_r msg, su_msg_arg_t *arg)
Message delivery function type.
Definition su_wait.h:397
int(* su_root_init_f)(su_root_t *, su_root_magic_t *)
Clone initialization function type.
Definition su_wait.h:422
su_root_t * su_timer_root(su_timer_t const *)
Get the root object owning the timer.
Definition su_timer.c:650
_su_task_t su_task_r[1]
Task reference type.
Definition su_wait.h:360
int su_msg_create(su_msg_r msg, su_task_r const to, su_task_r const from, su_msg_f wakeup, isize_t size)
Allocates a message of given size.
Definition su_root.c:1097
void su_msg_remove_refs(su_msg_cr msg)
Remove references to 'from' and 'to' tasks from a message.
Definition su_root.c:1305
#define SU_ROOT_MAGIC_T
Default type of application context for su_root_t.
Definition su_wait.h:223
SU_PREPOLL_MAGIC_T su_prepoll_magic_t
Root context pointer type.
Definition su_wait.h:310
#define SU_TIMER_ARG_T
Default type of timer expiration callback function argument type.
Definition su_wait.h:330
su_duration_t su_root_get_max_defer(su_root_t const *self)
Get maximum defer time.
Definition su_root.c:723
struct su_msg_s su_msg_t
Message type.
Definition su_wait.h:382
int su_root_set_max_defer(su_root_t *, su_duration_t max_defer)
Set maximum defer time.
Definition su_root.c:703
su_root_magic_t * su_root_magic(su_root_t *root)
Get context pointer.
Definition su_root.c:607
int su_root_yield(su_root_t *root)
Check wait events in callbacks that take lots of time.
Definition su_root.c:941
su_msg_function * su_msg_f
Message delivery function pointer type.
Definition su_wait.h:405
void su_task_copy(su_task_r dst, su_task_r const src)
Duplicates a task handle.
Definition su_root.c:198
SU_CLONE_T * su_clone_r[1]
Clone reference.
Definition su_wait.h:416
int su_root_deregister(su_root_t *, int)
Remove a su_wait_t registration.
Definition su_root.c:786
int su_task_execute(su_task_r const task, int(*function)(void *), void *arg, int *return_value)
Execute the function by task thread.
Definition su_root.c:366
su_duration_t su_root_step(su_root_t *root, su_duration_t timeout)
Process events, timers and messages.
Definition su_root.c:896
int su_root_threading(su_root_t *self, int enable)
Set threading option.
Definition su_root.c:585
int su_root_has_thread(su_root_t *root)
Check if a thread has obtained the root.
Definition su_root.c:1045
int su_wait_destroy(su_wait_t *dst)
Destroy a wait object.
Definition su_wait.c:185
void su_clone_wait(su_root_t *root, su_clone_r clone)
Stop a clone and wait until it is has completed.
Definition su_port.c:369
int su_msg_deinitializer(su_msg_r msg, su_msg_deinit_function *)
Add a deinitializer function to a message.
Definition su_root.c:1143
int su_root_set_magic(su_root_t *self, su_root_magic_t *magic)
Set the context pointer.
Definition su_root.c:567
su_task_r su_msg_to(su_msg_cr msg)
Get destination task.
Definition su_root.c:1296
int su_root_eventmask(su_root_t *, int index, int socket, int events)
Set mask for a registered event.
Definition su_root.c:810
int su_root_remove_prepoll(su_root_t *root)
Remove a pre-poll callback.
Definition su_root.c:996
su_task_r const su_task_null
NULL task.
Definition su_root.c:133
su_msg_t *const su_msg_cr[1]
Constant reference to su_msg.
Definition su_wait.h:391
void(* su_timer_f)(su_root_magic_t *magic, su_timer_t *t, su_timer_arg_t *arg)
Timeout function type.
Definition su_wait.h:340
int su_msg_reply(su_msg_r reply, su_msg_cr msg, su_msg_f wakeup, isize_t size)
Allocates a reply message of given size.
Definition su_root.c:1165
SU_TIMER_ARG_T su_timer_arg_t
Timer callback argument type.
Definition su_wait.h:337
struct su_port_s su_port_t
Port type.
Definition su_wait.h:355
void su_clone_stop(su_clone_r)
Stop the clone.
Definition su_port.c:348
int su_task_cmp(su_task_r const, su_task_r const)
Compare two tasks with each other.
Definition su_root.c:241
int su_wait_events(su_wait_t *wait, su_socket_t s)
Get events.
Definition su_wait.c:271
int su_root_add_prepoll(su_root_t *root, su_prepoll_f *, su_prepoll_magic_t *)
Add a pre-poll callback.
Definition su_root.c:984
int su_timer_run(su_timer_t *, su_timer_f, su_timer_arg_t *)
Set the timer for regular intervals.
Definition su_timer.c:444
int su_msg_new(su_msg_r msg, size_t size)
Allocate a su message of given size.
Definition su_root.c:1069
int su_root_release(su_root_t *root)
Release the root port for other threads.
Definition su_root.c:1009
int su_wait_create(su_wait_t *dst, su_socket_t s, int events)
Create a wait object.
Definition su_wait.c:132
int su_clone_start(su_root_t *root, su_clone_r, su_root_magic_t *magic, su_root_init_f, su_root_deinit_f)
Start a clone task.
Definition su_port.c:288
su_root_t * su_root_clone(su_root_t *root, su_root_magic_t *magic))
Create a a new root object sharing port/thread with existing one.
Definition su_root.c:433
int su_root_unregister(su_root_t *, su_wait_t *, su_wakeup_f, su_wakeup_arg_t *)
Unregister a su_wait_t object.
Definition su_root.c:671
SU_MSG_ARG_T su_msg_arg_t
Message argument type.
Definition su_wait.h:379
struct su_timer_s su_timer_t
Timer object type.
Definition su_wait.h:334
void su_prepoll_f(su_prepoll_magic_t *, su_root_t *)
Pre-poll callback function prototype.
Definition su_wait.h:317
void su_msg_deinit_function(su_msg_arg_t *arg)
Message deinitializer function type.
Definition su_wait.h:402
int su_task_wakeup(su_task_r const task)
Wakeup a task.
Definition su_root.c:356
su_root_t * su_task_root(su_task_r const self)
Get root pointer attached to a task handle.
Definition su_root.c:302
su_dur64_t su_root_stamp64_offset(su_root_t const *)
Get cached offset between monotonic timestamps and UTC time.
Definition su_root.c:767
#define SU_PREPOLL_MAGIC_T
Default type of application context for prepoll function.
Definition su_wait.h:297
@ su_pri_first
Elevated priority.
Definition su_wait.h:274
@ su_pri_normal
Normal priority.
Definition su_wait.h:273
@ su_pri_realtime
Real-time priority.
Definition su_wait.h:275
su_timer_queue_t * su_task_timers(su_task_r const self)
Return the timer list associated with given task.
Definition su_root.c:326
#define SU_WAKEUP_ARG_T
Default type of wakeup function argument type .
Definition su_wait.h:249
void su_msg_destroy(su_msg_r msg)
Destroys an unsent message.
Definition su_root.c:1225
int su_task_is_running(su_task_r const)
Tests if a task is running.
Definition su_root.c:269
char const * su_root_name(su_root_t *self)
Get instance name.
Definition su_root.c:549
int su_timer_deferrable(su_timer_t *t, int value)
Change timer as deferrable (or as undeferrable).
Definition su_timer.c:674
int su_timer_reset(su_timer_t *)
Reset the timer.
Definition su_timer.c:498
int su_wait_mask(su_wait_t *dst, su_socket_t s, int events)
Set event mask.
Definition su_wait.c:299
void su_root_break(su_root_t *root)
Terminate event loop.
Definition su_root.c:872
void su_port_prefer(su_port_create_f *f, su_clone_start_f *)
Explicitly set the preferred su_port_t implementation.
Definition su_port.c:102
isize_t su_msg_size(su_msg_cr msg)
Get size of message data area.
Definition su_root.c:1263
int su_wait(su_wait_t waits[], unsigned n, su_duration_t timeout)
Wait for multiple events.
Definition su_wait.c:222
int su_msg_send_to(su_msg_r msg, su_task_r const to, su_msg_f wakeup)
Send message to the to_task and mark from_task as sender.
Definition su_root.c:1347
su_msg_arg_t * su_msg_data(su_msg_cr msg)
Gets a pointer to the message data area.
Definition su_root.c:1254
int su_clone_pause(su_clone_r)
Pause a clone.
Definition su_port.c:386
void su_task_deinit(su_task_r task)
Destroy a task handle.
Definition su_root.c:164
su_task_r su_task_init(su_task_r task)
Initialize a task handle with su_task_null.
Definition su_root.c:151
su_root_t * su_root_create(su_root_magic_t *magic))
Create a reactor object.
Definition su_root.c:407
su_task_r su_clone_task(su_clone_r)
Get reference to a clone task.
Definition su_port.c:323
su_msg_t * su_msg_r[1]
Message reference type.
Definition su_wait.h:385
su_timer_queue_t * su_task_deferrable(su_task_r const task)
Return the queue for deferrable timers associated with given task.
Definition su_root.c:339
void su_clone_forget(su_clone_r)
Forget the clone.
Definition su_port.c:336
int su_timer_set_for_ever(su_timer_t *, su_timer_f, su_timer_arg_t *)
Set the timer for regular intervals.
Definition su_timer.c:475