mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-22 20:11:59 +00:00
1 parent
ee74602502
commit
1450e7e48a
1 file changed
+11
-21
@@ -49,11 +49,10 @@ the wall clock changes, either via NTP or user input.
|
|||||||
protect you against this problem, unless you stick to relative timers.
|
protect you against this problem, unless you stick to relative timers.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callback example, arg comes from the watcher's *_init() function,
|
* Callback example, arg comes from the watcher's *_init() function,
|
||||||
* w->fd holds the file descriptor or socket, and events is set by
|
* w->fd holds the file descriptor or socket, and events is set by
|
||||||
* libuEv to indicate status: UEV_HUP, UEV_READ and/or UEV_WRITE
|
* libuEv to indicate status: UEV_HUP, UEV_READ and/or UEV_WRITE
|
||||||
*/
|
*/
|
||||||
void callback (uev_t *w, void *arg, int events);
|
void callback (uev_t *w, void *arg, int events);
|
||||||
|
|
||||||
@@ -85,7 +84,6 @@ protect you against this problem, unless you stick to relative timers.
|
|||||||
int uev_signal_set (uev_t *w, int signo); /* Change signal to wait for */
|
int uev_signal_set (uev_t *w, int signo); /* Change signal to wait for */
|
||||||
int uev_signal_start(uev_t *w); /* Restart a stopped signal watcher */
|
int uev_signal_start(uev_t *w); /* Restart a stopped signal watcher */
|
||||||
int uev_signal_stop (uev_t *w); /* Stop signal watcher */
|
int uev_signal_stop (uev_t *w); /* Stop signal watcher */
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -96,11 +94,9 @@ is achieved by calling `uev_init()` with a pointer to a (thread) local
|
|||||||
`uev_ctx_t` variable.
|
`uev_ctx_t` variable.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
uev_ctx_t ctx;
|
uev_ctx_t ctx;
|
||||||
|
|
||||||
uev_init(&ctx);
|
|
||||||
|
|
||||||
|
uev_init(&ctx);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +110,6 @@ with the `uev_ctx_t` context, the callback, and an optional argument.
|
|||||||
Here is a signal example:
|
Here is a signal example:
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
void cleanup_exit(uev_t *w, void *arg, int events)
|
void cleanup_exit(uev_t *w, void *arg, int events)
|
||||||
{
|
{
|
||||||
/* Graceful exit, with optional cleanup ... */
|
/* Graceful exit, with optional cleanup ... */
|
||||||
@@ -122,17 +117,16 @@ Here is a signal example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
uev_t sigterm_watcher;
|
uev_t sigterm_watcher;
|
||||||
|
.
|
||||||
|
.
|
||||||
.
|
.
|
||||||
.
|
|
||||||
.
|
|
||||||
uev_signal_init(&ctx, &sigterm_watcher, cleanup_exit, NULL, SIGTERM);
|
uev_signal_init(&ctx, &sigterm_watcher, cleanup_exit, NULL, SIGTERM);
|
||||||
.
|
.
|
||||||
.
|
.
|
||||||
.
|
.
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -145,9 +139,7 @@ used to integrate [libuEv][] into another event loop.
|
|||||||
In this example we set `flags` to none:
|
In this example we set `flags` to none:
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
uev_run(&ctx, UEV_NONE);
|
uev_run(&ctx, UEV_NONE);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
With `flags` set to `UEV_ONCE` the event loop returns as soon as it has
|
With `flags` set to `UEV_ONCE` the event loop returns as soon as it has
|
||||||
@@ -217,7 +209,6 @@ Here follows a very brief example to illustrate how one can use libuEv
|
|||||||
to act upon joystick input.
|
to act upon joystick input.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -265,7 +256,6 @@ to act upon joystick input.
|
|||||||
|
|
||||||
return uev_run(&ctx, 0);
|
return uev_run(&ctx, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To build the example, follow installation instructions below, then save
|
To build the example, follow installation instructions below, then save
|
||||||
|
|||||||
Reference in new issue
Block a user