mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-01 05:22:25 +07:00
Handle UEV_HUP properly in examples and unit tests
If an I/O watcher callback fails to read(), returning zero, we check events for UEV_HUP to detect EOF or socket remote end shutdown(). Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+9
-1
@@ -43,16 +43,24 @@ struct js_event {
|
||||
*/
|
||||
static void joystick_cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
if (UEV_ERROR == events) {
|
||||
warnx("Spurious problem with the joystick watcher, restarting.");
|
||||
uev_io_start(w);
|
||||
}
|
||||
|
||||
if (read(w->fd, &e, sizeof(e)) < 0) {
|
||||
len = read(w->fd, &e, sizeof(e));
|
||||
if (len < 0) {
|
||||
warn("Failed reading joystick event");
|
||||
return;
|
||||
}
|
||||
|
||||
if (len == 0 || UEV_HUP == events) {
|
||||
warn("Joystick disconnected");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.type) {
|
||||
case 1:
|
||||
printf("Button %d %s\n", e.number, e.value ? "pressed" : "released");
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ void process_stdin(uev_t *w, void *arg, int events)
|
||||
return;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
if (len == 0 || UEV_HUP == events) {
|
||||
warnx("Connection closed.");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user