mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-23 11:24:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf5e729dd3 | ||
|
|
352baa8270 | ||
|
|
8721566d74 | ||
|
|
a8d8705c34 | ||
|
|
4c03342c77 | ||
|
|
c1fe3be3e7 | ||
|
|
861bf14d71 | ||
|
|
395d2df573 | ||
|
|
2132ab1bd5 | ||
|
|
d62ae8f041 | ||
|
|
1b1397b4ee | ||
|
|
7bf5c8d8d7 | ||
|
|
1374661d4b | ||
|
|
694e2b5ab9 | ||
|
|
c2751af452 | ||
|
|
1ce9fde395 | ||
|
|
7e9f8c4913 | ||
|
|
dd09c7c3a9 | ||
|
|
fe04723353 | ||
|
|
78995951ae | ||
|
|
3adc7a03c0 | ||
|
|
2abeb39fe8 | ||
|
|
1480976724 | ||
|
|
6ffa76c2f8 | ||
|
|
8a4e8c4af6 | ||
|
|
950015715d | ||
|
|
fb6ac1ecac | ||
|
|
0909decabc | ||
|
|
3452fbd381 | ||
|
|
f64561b708 | ||
|
|
b94023faed | ||
|
|
6637804b80 | ||
|
|
361b013da5 | ||
|
|
052b08e0b5 | ||
|
|
ca803bb12f | ||
|
|
6397edc2c4 | ||
|
|
cbd962c5b6 | ||
|
|
1f9558059a | ||
|
|
9e7f6865fc | ||
|
|
3b31079a1c | ||
|
|
63697e9eda | ||
|
|
ce3930f0cf |
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
bench
|
bench
|
||||||
test
|
test
|
||||||
.*.d
|
*.d
|
||||||
*.o
|
*.o
|
||||||
*~
|
*~
|
||||||
libuev.a
|
libuev.a
|
||||||
|
|||||||
+9
-3
@@ -1,7 +1,9 @@
|
|||||||
# Travis CI integration -- https://travis-ci.org/troglobit/libuev
|
# Travis CI integration -- https://travis-ci.org/troglobit/libuev
|
||||||
|
# Defaults to GNU GCC and autotools: ./configure && make && make test
|
||||||
language: c
|
language: c
|
||||||
compiler:
|
|
||||||
- gcc
|
# We don't need to install packages, use dockerized build, quicker
|
||||||
|
sudo: false
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
@@ -18,4 +20,8 @@ addons:
|
|||||||
build_command: "make"
|
build_command: "make"
|
||||||
branch_pattern: dev
|
branch_pattern: dev
|
||||||
|
|
||||||
script: make
|
# We don't use configure, so we must define our own build script.
|
||||||
|
script:
|
||||||
|
- make distclean
|
||||||
|
- make -j5
|
||||||
|
- make test
|
||||||
+97
-18
@@ -3,9 +3,83 @@ Change Log
|
|||||||
|
|
||||||
All notable changes to the project are documented in this file.
|
All notable changes to the project are documented in this file.
|
||||||
|
|
||||||
|
[v1.2.4] - 2015-11-23
|
||||||
|
---------------------
|
||||||
|
|
||||||
[v1.1.0]
|
### Fixes
|
||||||
--------
|
|
||||||
|
- Do not allow `VERSION` to be overloaded by build system.
|
||||||
|
- Make sure we don't inherit `LDFLAGS` from environment.
|
||||||
|
|
||||||
|
|
||||||
|
[v1.2.3] - 2015-09-17
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Very minor release.
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- [README.md][] updates, mostly cleanup and readability improvements
|
||||||
|
- `make test` now runs the test case, on behalf of Travis-CI
|
||||||
|
- Renamed CHANGELOG.md to [ChangeLog.md][]
|
||||||
|
- Dropped [TODO.md][] from distribution archives, only for devs
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Lots of Markdown syntax fixes in both README and ChangeLog
|
||||||
|
- Silence annoying warning from newer GNU ar in Ubuntu 15.10
|
||||||
|
|
||||||
|
|
||||||
|
[v1.2.2] - 2015-08-30
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Minor bugfix release.
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- The `ifdef STATIC` in the Makefile has been removed. Now both the
|
||||||
|
.a and .so libraries are built. The user may then select what to
|
||||||
|
install. This is a change for convenience when using libuEv from
|
||||||
|
a GNU Configure & Build based project.
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix odd data ordering issue on Debian Jessie in new `uev_private_t`
|
||||||
|
- Fix issue #6: Segfault when stopping timer before calling `uev_exit()`
|
||||||
|
|
||||||
|
|
||||||
|
[v1.2.1] - 2015-07-02
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Private data members in `uev.h` have now been moved to a new file
|
||||||
|
called `private.h`. This will hopefully make it easier to understand
|
||||||
|
what a user of libuEv is allowed to play around with. Thanks to @vonj
|
||||||
|
for the discussions around this!
|
||||||
|
- All builds of libuEv now default to use -fPIC, this bloats the code
|
||||||
|
slightly, but ensures that linking works for all use cases, withouth
|
||||||
|
introducing unnecessary complexity.
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix install/uninstall Makefile recipes so they work for both static
|
||||||
|
and dynamic builds. Also, make sure to install all required headers.
|
||||||
|
- Jakob Eriksson noticed that `O_CLOEXEC` does not exist in the Debian 6
|
||||||
|
EGLIBC, but `EPOLL_CLOEXEC` does, and is also what `epoll_create1()`
|
||||||
|
should use. Thank you @vonj!
|
||||||
|
|
||||||
|
|
||||||
|
[v1.2.0] - 2015-06-09
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
API change in event callbacks and fix timers that never start.
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Remove first `uev_ctx_t *` argument in callbacks, incompatible API
|
||||||
|
change! Please update all your callbacks if you upgrade.
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix timers that accidentally broke in [v1.1.0].
|
||||||
|
- Fixes to `bench.c`, it now actually listens to the pipe/socket.
|
||||||
|
|
||||||
|
|
||||||
|
[v1.1.0] - 2015-03-04
|
||||||
|
---------------------
|
||||||
|
|
||||||
Massively improved error handling.
|
Massively improved error handling.
|
||||||
|
|
||||||
@@ -15,7 +89,7 @@ Massively improved error handling.
|
|||||||
all watchers when an error count reaches a MAX value -- handles stale
|
all watchers when an error count reaches a MAX value -- handles stale
|
||||||
descriptors or cases when kernel does not notice updated descriptors.
|
descriptors or cases when kernel does not notice updated descriptors.
|
||||||
- Return error when stopping a watcher fails.
|
- Return error when stopping a watcher fails.
|
||||||
- Update [README.md] with new `uev_*_start()` functions.
|
- Update [README.md][] with new `uev_*_start()` functions.
|
||||||
- Bump dev version to 1.1 due to the number of significant changes.
|
- Bump dev version to 1.1 due to the number of significant changes.
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
@@ -25,8 +99,8 @@ Massively improved error handling.
|
|||||||
- Fix broken link to [v1.0.5] in this file.
|
- Fix broken link to [v1.0.5] in this file.
|
||||||
|
|
||||||
|
|
||||||
[v1.0.5]
|
[v1.0.5] - 2015-02-15
|
||||||
--------
|
---------------------
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- Add `uev_*_start()` functions.
|
- Add `uev_*_start()` functions.
|
||||||
@@ -35,9 +109,9 @@ Massively improved error handling.
|
|||||||
- Renamed `main.c` to `uev.c`
|
- Renamed `main.c` to `uev.c`
|
||||||
- Move examples to `examples/` subdirectory
|
- Move examples to `examples/` subdirectory
|
||||||
- Simplify automatic dependency calculation
|
- Simplify automatic dependency calculation
|
||||||
- Add [TODO.md] for wishlist items
|
- Add [TODO.md][] for wishlist items
|
||||||
- Add [CHANGELOG.md], attempt to align with http://keepachangelog.com
|
- Add [CHANGELOG.md][ChangeLog.md], to align with http://keepachangelog.com
|
||||||
- Further updates to [README.md]
|
- Further updates to [README.md][]
|
||||||
|
|
||||||
|
|
||||||
[v1.0.4] - 2015-01-24
|
[v1.0.4] - 2015-01-24
|
||||||
@@ -49,7 +123,7 @@ Release mainly targeted for [Finit development](https://github.com/troglobit/fin
|
|||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
* `test.c` has been simplified/clarified
|
* `test.c` has been simplified/clarified
|
||||||
* Further updates to [README.md]
|
* Further updates to [README.md][]
|
||||||
* Minor update to Makefile, change how build progress is echoed
|
* Minor update to Makefile, change how build progress is echoed
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +133,7 @@ Release mainly targeted for [Finit development](https://github.com/troglobit/fin
|
|||||||
This is a very minor release, with a strong focus on documentation.
|
This is a very minor release, with a strong focus on documentation.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- [README.md], massively updated
|
- [README.md][], massively updated
|
||||||
- API documentation, updated
|
- API documentation, updated
|
||||||
- Travis CI integration added, https://travis-ci.org/troglobit/libuev
|
- Travis CI integration added, https://travis-ci.org/troglobit/libuev
|
||||||
- Coverity Scan integration, https://scan.coverity.com/projects/3846
|
- Coverity Scan integration, https://scan.coverity.com/projects/3846
|
||||||
@@ -77,8 +151,8 @@ This is a very minor release, with a strong focus on documentation.
|
|||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- Cleanup and rewrite of [README.md] after first audit by @vonj
|
- Cleanup and rewrite of [README.md][] after first audit by @vonj
|
||||||
- Added API and example section to [README.md]
|
- Added API and example section to [README.md][]
|
||||||
- New [joystick.c] example added
|
- New [joystick.c] example added
|
||||||
- `main.c:uev_run()`: Document mysterious flags parameter
|
- `main.c:uev_run()`: Document mysterious flags parameter
|
||||||
|
|
||||||
@@ -97,17 +171,22 @@ First release in the new guise and API.
|
|||||||
- Reindent to use Linux KNF
|
- Reindent to use Linux KNF
|
||||||
- Change library name to libuev
|
- Change library name to libuev
|
||||||
- Lua support removed
|
- Lua support removed
|
||||||
- Make sure to state the [MIT license] correctly in all files
|
- Make sure to state the [MIT license][] correctly in all files
|
||||||
- Import [Niels Provos]' `bench.c`, the [libev version]
|
- Import [Niels Provos][]' `bench.c`, the [libev version][]
|
||||||
|
|
||||||
|
|
||||||
v0.0.1 - 2012-03-17
|
v0.0.1 - 2012-03-17
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
[Initial announcement] of [libuevent] by [Flemming Madsen] to the Lua
|
[Initial announcement][] of [libuevent][] by [Flemming Madsen][] to the
|
||||||
users mailing list.
|
Lua users mailing list.
|
||||||
|
|
||||||
[UNRELEASED]: https://github.com/troglobit/libuev/compare/v1.1,0...HEAD
|
|
||||||
|
[UNRELEASED]: https://github.com/troglobit/libuev/compare/v1.2.3...HEAD
|
||||||
|
[v1.2.3]: https://github.com/troglobit/libuev/compare/v1.2.2...v1.2.3
|
||||||
|
[v1.2.2]: https://github.com/troglobit/libuev/compare/v1.2.1...v1.2.2
|
||||||
|
[v1.2.1]: https://github.com/troglobit/libuev/compare/v1.2.0...v1.2.1
|
||||||
|
[v1.2.0]: https://github.com/troglobit/libuev/compare/v1.1.0...v1.2.0
|
||||||
[v1.1.0]: https://github.com/troglobit/libuev/compare/v1.0.5...v1.1.0
|
[v1.1.0]: https://github.com/troglobit/libuev/compare/v1.0.5...v1.1.0
|
||||||
[v1.0.5]: https://github.com/troglobit/libuev/compare/v1.0.4...v1.0.5
|
[v1.0.5]: https://github.com/troglobit/libuev/compare/v1.0.4...v1.0.5
|
||||||
[v1.0.4]: https://github.com/troglobit/libuev/compare/v1.0.3...v1.0.4
|
[v1.0.4]: https://github.com/troglobit/libuev/compare/v1.0.3...v1.0.4
|
||||||
@@ -117,7 +196,7 @@ users mailing list.
|
|||||||
[v1.0.0]: https://github.com/troglobit/libuev/compare/v0.0.1...v1.0.0
|
[v1.0.0]: https://github.com/troglobit/libuev/compare/v0.0.1...v1.0.0
|
||||||
[TODO.md]: https://github.com/troglobit/libuev/blob/master/TODO.md
|
[TODO.md]: https://github.com/troglobit/libuev/blob/master/TODO.md
|
||||||
[README.md]: https://github.com/troglobit/libuev/blob/master/README.md
|
[README.md]: https://github.com/troglobit/libuev/blob/master/README.md
|
||||||
[CHANGLOG.md]: https://github.com/troglobit/libuev/blob/master/CHANGELOG.md
|
[ChangeLog.md]: https://github.com/troglobit/libuev/blob/master/ChangeLog.md
|
||||||
[joystick.c]: https://github.com/troglobit/libuev/blob/master/joystick.c
|
[joystick.c]: https://github.com/troglobit/libuev/blob/master/joystick.c
|
||||||
[Niels Provos]: http://en.wikipedia.org/wiki/Niels_Provos
|
[Niels Provos]: http://en.wikipedia.org/wiki/Niels_Provos
|
||||||
[MIT license]: http://en.wikipedia.org/wiki/MIT_License
|
[MIT license]: http://en.wikipedia.org/wiki/MIT_License
|
||||||
@@ -1,31 +1,33 @@
|
|||||||
# libuEv main build file
|
# libuEv -- Simple event loop for Linux
|
||||||
#
|
#
|
||||||
# Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
# Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
# Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
# Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# a copy of this software and associated documentation files (the
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
# "Software"), to deal in the Software without restriction, including
|
# in the Software without restriction, including without limitation the rights
|
||||||
# without limitation the rights to use, copy, modify, merge, publish,
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
# permit persons to whom the Software is furnished to do so, subject to
|
# furnished to do so, subject to the following conditions:
|
||||||
# the following conditions:
|
|
||||||
#
|
#
|
||||||
# The above copyright notice and this permission notice shall be
|
# The above copyright notice and this permission notice shall be included in
|
||||||
# included in all copies or substantial portions of the Software.
|
# all copies or substantial portions of the Software.
|
||||||
#
|
#
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
#
|
#
|
||||||
.PHONY: all test clean joystick test examples
|
.PHONY: all test clean joystick test examples bench
|
||||||
|
|
||||||
|
# Figure out root of library, unless used as submodule
|
||||||
|
ROOTDIR ?= $(shell pwd)
|
||||||
|
|
||||||
#VERSION = $(shell git tag -l | tail -1)
|
#VERSION = $(shell git tag -l | tail -1)
|
||||||
VERSION ?= 1.1.0
|
VERSION = 1.2.4
|
||||||
NAME = libuev
|
NAME = libuev
|
||||||
PKG = $(NAME)-$(VERSION)
|
PKG = $(NAME)-$(VERSION)
|
||||||
ARCHIVE = $(PKG).tar.xz
|
ARCHIVE = $(PKG).tar.xz
|
||||||
@@ -33,31 +35,37 @@ ARCHIVE = $(PKG).tar.xz
|
|||||||
CC ?= $(CROSS)gcc
|
CC ?= $(CROSS)gcc
|
||||||
AR ?= $(CROSS)ar
|
AR ?= $(CROSS)ar
|
||||||
STRIP ?= $(CROSS)strip
|
STRIP ?= $(CROSS)strip
|
||||||
CFLAGS += -fPIC -Os
|
MAKE := @$(MAKE)
|
||||||
|
INSTALL := install --backup=off
|
||||||
|
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
|
||||||
|
|
||||||
|
CFLAGS += -fPIC
|
||||||
|
CFLAGS += -Os
|
||||||
CPPFLAGS += -W -Wall -Werror
|
CPPFLAGS += -W -Wall -Werror
|
||||||
|
LDFLAGS = $(EXTRA_LDFLAGS)
|
||||||
ARFLAGS = crus
|
ARFLAGS = crus
|
||||||
JUNK = *~ *.bak *.map .*.d DEADJOE *.gdb *.elf core core.* *.html
|
MAKEFLAGS = --no-print-directory --silent
|
||||||
|
|
||||||
MAKEFLAGS = --no-print-directory
|
|
||||||
|
|
||||||
ROOTDIR ?= $(shell pwd)
|
|
||||||
LIBNAME = $(NAME)
|
|
||||||
prefix ?= /usr/local
|
|
||||||
libdir ?= $(prefix)/lib
|
|
||||||
datadir ?= $(prefix)/share/doc/$(LIBNAME)
|
|
||||||
incdir ?= $(prefix)/include
|
|
||||||
DISTFILES = README CHANGELOG TODO LICENSE
|
|
||||||
HEADER = uev.h
|
|
||||||
|
|
||||||
|
DISTFILES = README ChangeLog LICENSE
|
||||||
|
HEADERS = uev.h private.h queue.h
|
||||||
OBJS := uev.o io.o timer.o signal.o
|
OBJS := uev.o io.o timer.o signal.o
|
||||||
SRCS := $(OBJS:.o=.c)
|
SRCS := $(OBJS:.o=.c)
|
||||||
DEPS := $(SRCS:.c=.d)
|
DEPS := $(SRCS:.c=.d)
|
||||||
|
JUNK = *~ *.bak *.map .*.d *.so* *.a DEADJOE *.gdb *.elf core core.* *.html
|
||||||
|
|
||||||
VER = 1
|
VER = 1
|
||||||
|
LIBNAME = $(NAME)
|
||||||
SOLIB = $(LIBNAME).so.$(VER)
|
SOLIB = $(LIBNAME).so.$(VER)
|
||||||
SYMLIB = $(LIBNAME).so
|
SYMLIB = $(LIBNAME).so
|
||||||
STATICLIB = $(LIBNAME).a
|
STATICLIB = $(LIBNAME).a
|
||||||
TARGET = $(STATICLIB) $(SOLIB)
|
TARGET = $(STATICLIB) $(SOLIB)
|
||||||
|
|
||||||
|
# Default install paths
|
||||||
|
prefix ?= /usr/local
|
||||||
|
libdir ?= $(prefix)/lib
|
||||||
|
datadir ?= $(prefix)/share/doc/$(LIBNAME)
|
||||||
|
incdir ?= $(prefix)/include
|
||||||
|
|
||||||
export STATICLIB JUNK ROOTDIR CFLAGS CPPFLAGS
|
export STATICLIB JUNK ROOTDIR CFLAGS CPPFLAGS
|
||||||
|
|
||||||
# This magic trick looks like a comment, but works on BSD PMake
|
# This magic trick looks like a comment, but works on BSD PMake
|
||||||
@@ -67,45 +75,61 @@ include rules.mk
|
|||||||
# Build rules
|
# Build rules
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(OBJS): Makefile
|
||||||
|
|
||||||
$(SOLIB): Makefile $(OBJS)
|
$(SOLIB): Makefile $(OBJS)
|
||||||
@printf " LINK $@\n"
|
@printf " LINK $@\n"
|
||||||
@$(CC) $(LDFLAGS) -shared -Wl,-soname=$@ -o $@ $(OBJS)
|
@$(CC) $(LDFLAGS) -shared -Wl,-soname=$@ -o $@ $(OBJS)
|
||||||
|
|
||||||
$(STATICLIB): Makefile $(OBJS)
|
$(STATICLIB): Makefile $(OBJS)
|
||||||
@printf " ARCHIVE $@\n"
|
@printf " ARCHIVE $@\n"
|
||||||
@$(AR) $(ARFLAGS) $@ $(OBJS)
|
@$(AR) $(ARFLAGS) $@ $(OBJS) 2>/dev/null
|
||||||
|
|
||||||
install: strip
|
install-exec: all
|
||||||
|
@printf " INSTALL $(DESTDIR)$(libdir)/$(SOLIB)\n"
|
||||||
@install -d $(DESTDIR)$(libdir)
|
@install -d $(DESTDIR)$(libdir)
|
||||||
@install $(SOLIB) $(DESTDIR)$(prefix)/lib/$(SOLIB)
|
@install $(SOLIB) $(DESTDIR)$(libdir)/$(SOLIB)
|
||||||
@install $(STATICLIB) $(DESTDIR)$(prefix)/lib/$(STATICLIB)
|
@ln -sf $(SOLIB) $(DESTDIR)$(libdir)/$(SYMLIB)
|
||||||
@ln -sf $(SOLIB) $(DESTDIR)$(prefix)/lib/$(SYMLIB)
|
|
||||||
@install -d $(DESTDIR)$(incdir)
|
install-dev:
|
||||||
@install -m 0644 $(HEADER) $(DESTDIR)$(incdir)/$(HEADER)
|
@install -d $(DESTDIR)$(incdir)/$(LIBNAME)
|
||||||
@install -d $(DESTDIR)$(datadir)
|
@for file in $(HEADERS); do \
|
||||||
@for file in $(DISTFILES); do \
|
printf " INSTALL $(DESTDIR)$(incdir)/$(LIBNAME)/$$file\n"; \
|
||||||
install -m 0644 $$file $(DESTDIR)$(datadir)/$$file; \
|
install -m 0644 $$file $(DESTDIR)$(incdir)/$(LIBNAME)/$$file; \
|
||||||
done
|
done
|
||||||
|
@printf " INSTALL $(DESTDIR)$(libdir)/$(STATICLIB)\n"
|
||||||
|
@install -d $(DESTDIR)$(libdir)
|
||||||
|
@install $(STATICLIB) $(DESTDIR)$(libdir)/$(STATICLIB)
|
||||||
|
@install -d $(DESTDIR)$(datadir)
|
||||||
|
@for file in $(DISTFILES); do \
|
||||||
|
printf " INSTALL $(DESTDIR)$(datadir)/$$file\n"; \
|
||||||
|
install -m 0644 $$file $(DESTDIR)$(datadir)/$$file; \
|
||||||
|
done
|
||||||
|
|
||||||
|
install: install-exec install-dev
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
-@$(RM) -r $(DESTDIR)$(datadir)
|
-@$(RM) -r $(DESTDIR)$(datadir)
|
||||||
-@$(RM) -r $(DESTDIR)$(incdir)
|
-@$(RM) -r $(DESTDIR)$(incdir)/$(LIBNAME)
|
||||||
-@$(RM) $(DESTDIR)$(prefix)/lib/$(LIBNAME)*
|
-@$(RM) $(DESTDIR)$(libdir)/$(SOLIB)
|
||||||
|
-@$(RM) $(DESTDIR)$(libdir)/$(SYMLIB)
|
||||||
|
-@$(RM) $(DESTDIR)$(libdir)/$(STATICLIB)
|
||||||
|
|
||||||
strip: $(TARGET)
|
strip: $(TARGET)
|
||||||
@printf " STRIP %s\n" $(TARGET)
|
@printf " STRIP %s\n" $(TARGET)
|
||||||
@$(STRIP) --strip-unneeded $(TARGET)
|
@$(STRIP) --strip-unneeded $(TARGET)
|
||||||
@size $(TARGET)
|
@size $(TARGET)
|
||||||
|
|
||||||
bench: Makefile bench.o $(STATICLIB)
|
bench: Makefile $(STATICLIB)
|
||||||
@printf " BENCH %s\n" $(STATICLIB)
|
@printf " RUN %s\n" $@
|
||||||
@$(CC) $(CPPFLAGS) -g -o bench bench.c $(STATICLIB) && ./bench
|
@$(CC) $(CPPFLAGS) -D_GNU_SOURCE -g -o bench bench.c $(STATICLIB) && ./bench
|
||||||
|
|
||||||
examples: all
|
examples: all
|
||||||
@$(MAKE) -C examples
|
@$(MAKE) -C examples
|
||||||
|
|
||||||
test joystick:
|
test joystick: all
|
||||||
@$(MAKE) -C examples $@
|
@$(MAKE) -C examples $@
|
||||||
|
@./examples/$@
|
||||||
|
|
||||||
# Runs Clang scan-build on the whole tree
|
# Runs Clang scan-build on the whole tree
|
||||||
check: clean
|
check: clean
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
libuEv | Simple event loop for Linux
|
libuEv | Simple event loop for Linux
|
||||||
====================================
|
====================================
|
||||||
[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
|
[![Travis Status][]][Travis] [![Coverity Status][]][Coverity Scan]
|
||||||
|
|
||||||
|
|
||||||
Table of Contents
|
Table of Contents
|
||||||
@@ -8,7 +8,11 @@ Table of Contents
|
|||||||
|
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [API](#api)
|
* [API](#api)
|
||||||
* [Example](#example)
|
* [Create an Event Context](#create-an-event-context)
|
||||||
|
* [Register an Event Watcher](#register-an-event-watcher)
|
||||||
|
* [Start Event Loop](#start-event-loop)
|
||||||
|
* [Summary](#summary)
|
||||||
|
* [Joystick Example](#joystick-example)
|
||||||
* [Build & Install](#build--install)
|
* [Build & Install](#build--install)
|
||||||
* [Origin & References](#origin--references)
|
* [Origin & References](#origin--references)
|
||||||
|
|
||||||
@@ -44,13 +48,13 @@ core, even though they run Linux, with multiple threads a program may
|
|||||||
actually run slower! Always profile your program, and if possible, test
|
actually run slower! Always profile your program, and if possible, test
|
||||||
it on different architectures.
|
it on different architectures.
|
||||||
|
|
||||||
[libuEv] is a simple event loop in the style of the more established
|
[libuEv][] is a simple event loop in the style of the more established
|
||||||
[libevent][1], [libev][2] and the venerable [Xt(3)][3] event loop. The
|
[libevent][1], [libev][2] and the venerable [Xt(3)][3] event loop. The
|
||||||
*u* (micro) in the name refers to both the small feature set and the
|
*u* (micro) in the name refers to both the small feature set and the
|
||||||
small size overhead impact of the library. The primary target of
|
small size overhead impact of the library. The primary target of
|
||||||
[libuEv] is a modern Linux system.
|
[libuEv][] is a modern Linux system.
|
||||||
|
|
||||||
Experienced developers may appreciate that [libuEv] is built on top of
|
Experienced developers may appreciate that [libuEv][] is built on top of
|
||||||
modern Linux APIs: epoll, timerfd and signalfd. Note, a certain amount
|
modern Linux APIs: epoll, timerfd and signalfd. Note, a certain amount
|
||||||
of care is needed when dealing with APIs that employ signalfd. For
|
of care is needed when dealing with APIs that employ signalfd. For
|
||||||
details, see [this article][4] at [lwn.net](http://lwn.net).
|
details, see [this article][4] at [lwn.net](http://lwn.net).
|
||||||
@@ -61,17 +65,19 @@ details, see [this article][4] at [lwn.net](http://lwn.net).
|
|||||||
API
|
API
|
||||||
---
|
---
|
||||||
|
|
||||||
Here is the interface to [libuEv]. It handles three different types of
|
The C interface to [libuEv][] is very simple. It handles three different
|
||||||
events: I/O (files, sockets, message queues, etc.), timers, and signals.
|
types of events: I/O (files, sockets, message queues, etc.), timers, and
|
||||||
|
signals. With a slight caveat on signals
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
/* Callback example, arg is passed from watcher's *_init()
|
/* Callback example, arg is passed from watcher's *_init()
|
||||||
* w->fd holds the file descriptor, events is set by libuEv
|
* w->fd holds the file descriptor, events is set by libuEv
|
||||||
* to indicate if any of UEV_READ and/or UEV_WRITE is ready.
|
* to indicate if any of UEV_READ and/or UEV_WRITE is ready.
|
||||||
*/
|
*/
|
||||||
void callback (uev_ctx_t *ctx, uev_t *w, void *arg, int events);
|
void callback (uev_t *w, void *arg, int events);
|
||||||
|
|
||||||
/* Event loop functions, notice use of flags! */
|
/* Event loop: Notice the use of flags! */
|
||||||
int uev_init (uev_ctx_t *ctx);
|
int uev_init (uev_ctx_t *ctx);
|
||||||
int uev_exit (uev_ctx_t *ctx);
|
int uev_exit (uev_ctx_t *ctx);
|
||||||
int uev_run (uev_ctx_t *ctx, int flags); /* UEV_NONE, UEV_ONCE, and/or UEV_NONBLOCK */
|
int uev_run (uev_ctx_t *ctx, int flags); /* UEV_NONE, UEV_ONCE, and/or UEV_NONBLOCK */
|
||||||
@@ -93,35 +99,84 @@ events: I/O (files, sockets, message queues, etc.), timers, and signals.
|
|||||||
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 */
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To be able to set up callbacks to events the developer first need to
|
### Create an Event Context
|
||||||
create an *event context*, achieved by calling `uev_init()` with a
|
|
||||||
pointer to a local `uev_ctx_t` variable.
|
|
||||||
|
|
||||||
Events are monitored by watchers in [libuEv]. A watcher is nothing more
|
To monitor events the developer first creates an *event context*, this
|
||||||
than a mechnism that polls a file descriptor. Register a watcher with a
|
is achieved by calling `uev_init()` with a pointer to a (thread) local
|
||||||
callback to the event context by passing the `uev_ctx_t` variable, along
|
`uev_ctx_t` variable.
|
||||||
with an `uev_t` variable to each event's `_init()` function.
|
|
||||||
|
|
||||||
When all watchers are registered call the event loop with `uev_run()`
|
```C
|
||||||
and the argument to the event context. The `flags` parameter is slightly
|
|
||||||
mysterious, but can be used to integrate [libuEv] into another event loop.
|
uev_ctx_t ctx;
|
||||||
With `flags` set to `UEV_ONCE` the event loop returns after having
|
|
||||||
|
uev_init(&ctx);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Register an Event Watcher
|
||||||
|
|
||||||
|
For each event to be monitored, be it a signal, timer or a file
|
||||||
|
descriptor, a *watcher* must be registered with the event context. The
|
||||||
|
watcher, an `uev_t`, is registered by calling the event type's `_init()`
|
||||||
|
function with the `uev_ctx_t` context, the callback, and an optional
|
||||||
|
argument.
|
||||||
|
|
||||||
|
Here is a signal example:
|
||||||
|
|
||||||
|
```C
|
||||||
|
|
||||||
|
void cleanup_exit(uev_t *w, void *arg, int events)
|
||||||
|
{
|
||||||
|
/* Graceful exit, with optional cleanup ... */
|
||||||
|
uev_exit(w->ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
uev_t sigterm_watcher;
|
||||||
|
.
|
||||||
|
.
|
||||||
|
.
|
||||||
|
uev_signal_init(&ctx, &sigterm_watcher, cleanup_exit, NULL, SIGTERM);
|
||||||
|
.
|
||||||
|
.
|
||||||
|
.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start Event Loop
|
||||||
|
|
||||||
|
When all watchers are registered, call the *event loop* with `uev_run()`
|
||||||
|
and the argument to the event context. The `flags` parameter can be
|
||||||
|
used to integrate [libuEv][] into another event loop.
|
||||||
|
|
||||||
|
In this example we set `flags` to none:
|
||||||
|
|
||||||
|
```C
|
||||||
|
|
||||||
|
uev_run(&ctx, UEV_NONE);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
With `flags` set to `UEV_ONCE` the event loop returns as soon as it has
|
||||||
served the first event. If `flags` is set to `UEV_ONCE | UEV_NONBLOCK`
|
served the first event. If `flags` is set to `UEV_ONCE | UEV_NONBLOCK`
|
||||||
the event loop returns immediately if no event is available.
|
the event loop returns immediately if no event is available.
|
||||||
|
|
||||||
In the case of errors, stream close, or peer shutdown libuEv handles
|
**Note:** libuEv handles many types of errors, stream close, or peer
|
||||||
much internally, but also lets the callback run. This is useful for
|
shutdowns internally, but also lets the callback run. This is useful
|
||||||
stateful connections to be able to detect EOF.
|
for stateful connections to be able to detect EOF.
|
||||||
|
|
||||||
Summary:
|
### Summary
|
||||||
|
|
||||||
1. Prepare an event context with `uev_init()`
|
1. Set up an event context with `uev_init()`
|
||||||
2. Register event callbacks with `uev_io_init()`, `uev_signal_init()`
|
2. Register event callbacks with the event context using
|
||||||
or `uev_timer_init()`
|
`uev_io_init()`, `uev_signal_init()` or `uev_timer_init()`
|
||||||
3. Enter the event loop with `uev_run()`
|
3. Start the event loop with `uev_run()`
|
||||||
4. Leave the event loop with `uev_exit()`, possibly from a callback
|
4. Exit the event loop with `uev_exit()`, possibly from a callback
|
||||||
|
|
||||||
**Note 1:** Make sure to use non-blocking stream I/O! Most hard to find
|
**Note 1:** Make sure to use non-blocking stream I/O! Most hard to find
|
||||||
bugs in event driven applications are due to sockets and files being
|
bugs in event driven applications are due to sockets and files being
|
||||||
@@ -141,61 +196,63 @@ of this, from [finit][6], implementing `run()` as a better replacement
|
|||||||
to `system()`, which sucks anyawy :)
|
to `system()`, which sucks anyawy :)
|
||||||
|
|
||||||
|
|
||||||
Example
|
Joystick Example
|
||||||
-------
|
----------------
|
||||||
|
|
||||||
Here follows a very brief example to illustrate how one can use [libuEv]
|
Here follows a very brief example to illustrate how one can use
|
||||||
to act upon joystick input.
|
[libuEv][] to act upon joystick input.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
#include <err.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "uev.h"
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "uev.h"
|
||||||
|
|
||||||
|
struct js_event {
|
||||||
|
uint32_t time; /* event timestamp in milliseconds */
|
||||||
|
int16_t value; /* value */
|
||||||
|
uint8_t type; /* event type */
|
||||||
|
uint8_t number; /* axis/button number */
|
||||||
|
} e;
|
||||||
|
|
||||||
|
static void joystick_cb(uev_t *w, void *arg, int events)
|
||||||
|
{
|
||||||
|
read (w->fd, &e, sizeof(e));
|
||||||
|
|
||||||
|
switch (e.type) {
|
||||||
|
case 1:
|
||||||
|
if (e.value) printf("Button %d pressed\n", e.number);
|
||||||
|
else printf("Button %d released\n", e.number);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
printf("Joystick axis %d moved, value %d!\n", e.number, e.value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int fd = open("/dev/input/js1", O_RDONLY, O_NONBLOCK);
|
||||||
|
uev_t js1_watcher;
|
||||||
|
uev_ctx_t ctx;
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
errx(errno, "Cannot find a joystick attached.");
|
||||||
|
|
||||||
|
uev_init(&ctx);
|
||||||
|
uev_io_init(&ctx, &js1_watcher, joystick_cb, NULL, fd, UEV_READ);
|
||||||
|
|
||||||
|
puts("Starting, press Ctrl-C to exit.");
|
||||||
|
|
||||||
|
return uev_run(&ctx, 0);
|
||||||
|
}
|
||||||
|
|
||||||
struct js_event {
|
|
||||||
uint32_t time; /* event timestamp in milliseconds */
|
|
||||||
int16_t value; /* value */
|
|
||||||
uint8_t type; /* event type */
|
|
||||||
uint8_t number; /* axis/button number */
|
|
||||||
} e;
|
|
||||||
|
|
||||||
static void joystick_cb(uev_ctx_t *ctx, uev_t *w, void *arg, int events)
|
|
||||||
{
|
|
||||||
read (w->fd, &e, sizeof(e));
|
|
||||||
|
|
||||||
switch (e.type) {
|
|
||||||
case 1:
|
|
||||||
if (e.value) printf("Button %d pressed\n", e.number);
|
|
||||||
else printf("Button %d released\n", e.number);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
printf("Joystick axis %d moved, value %d!\n", e.number, e.value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int fd = open("/dev/input/js1", O_RDONLY, O_NONBLOCK);
|
|
||||||
uev_t js1_watcher;
|
|
||||||
uev_ctx_t ctx;
|
|
||||||
|
|
||||||
if (fd < 0)
|
|
||||||
errx(errno, "Cannot find a joystick attached.");
|
|
||||||
|
|
||||||
uev_init(&ctx);
|
|
||||||
uev_io_init(&ctx, &js1_watcher, joystick_cb, NULL, fd, UEV_READ);
|
|
||||||
|
|
||||||
puts("Starting, press Ctrl-C to exit.");
|
|
||||||
|
|
||||||
return uev_run(&ctx, 0);
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To compile the program, save the code as `joystick.c` and call GCC with
|
To compile the program, save the code as `joystick.c` and call GCC with
|
||||||
@@ -203,12 +260,13 @@ To compile the program, save the code as `joystick.c` and call GCC with
|
|||||||
directory, skips using a Makefile altogether. Alternatively, call the
|
directory, skips using a Makefile altogether. Alternatively, call the
|
||||||
`Makefile` with <kbd>make joystick</kbd> from this directory.
|
`Makefile` with <kbd>make joystick</kbd> from this directory.
|
||||||
|
|
||||||
More complete and relevant example uses of [libuEv] is the TFTP/FTP
|
More complete and relevant example uses of [libuEv][] is the TFTP/FTP
|
||||||
server [uftpd][5], and the Linux `/sbin/init` replacement [finit][6].
|
server [uftpd][5], and the Linux `/sbin/init` replacement [finit][6].
|
||||||
Both use [libuEv] as a GIT submodule.
|
Both use [libuEv][] as a GIT submodule.
|
||||||
|
|
||||||
Also, see the `bench.c` program (<kbd>make bench</kbd> from within the
|
Also see the `bench.c` program (<kbd>make bench</kbd> from within the
|
||||||
library) for [reference benchmarks][7] against libevent and libev.
|
library) for [reference benchmarks][7] against [libevent][1] and
|
||||||
|
[libev][2].
|
||||||
|
|
||||||
|
|
||||||
Build & Install
|
Build & Install
|
||||||
@@ -223,7 +281,7 @@ patches to support *BSD and its kqueue interface.
|
|||||||
* <kbd>make test</kbd>: Test and showcase
|
* <kbd>make test</kbd>: Test and showcase
|
||||||
* <kbd>make install</kbd>: Honors `$prefix` and `$DESTDIR` environment variables
|
* <kbd>make install</kbd>: Honors `$prefix` and `$DESTDIR` environment variables
|
||||||
|
|
||||||
Size of [libuEv]:
|
Size of [libuEv][]:
|
||||||
|
|
||||||
$ make strip
|
$ make strip
|
||||||
CC main.o
|
CC main.o
|
||||||
@@ -245,10 +303,13 @@ Size of [libuEv]:
|
|||||||
Origin & References
|
Origin & References
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
[libuEv] was originally based on [LibUEvent][8] by [Flemming Madsen] but
|
[libuEv][] was originally based on [LibUEvent][8] by [Flemming Madsen]
|
||||||
has been completely rewritten with a much clearer API. Now more similar
|
but has been completely rewritten with a much clearer API. Now more
|
||||||
to the famous [libev][2] by [Mark Lehmann]. Another small event library
|
similar to the famous [libev][2] by [Mark Lehmann][]. Another small
|
||||||
used for inspiration is the very small [Picoev][9] by [Oku Kazuho].
|
event library used for inspiration is the very small [Picoev][9] by
|
||||||
|
[Oku Kazuho][].
|
||||||
|
|
||||||
|
[libuEv][] is developed and maintained by [Joachim Nilsson][].
|
||||||
|
|
||||||
[1]: http://libevent.org
|
[1]: http://libevent.org
|
||||||
[2]: http://software.schmorp.de/pkg/libev.html
|
[2]: http://software.schmorp.de/pkg/libev.html
|
||||||
@@ -263,11 +324,15 @@ used for inspiration is the very small [Picoev][9] by [Oku Kazuho].
|
|||||||
[Travis Status]: https://travis-ci.org/troglobit/libuev.png?branch=master
|
[Travis Status]: https://travis-ci.org/troglobit/libuev.png?branch=master
|
||||||
[Coverity Scan]: https://scan.coverity.com/projects/3846
|
[Coverity Scan]: https://scan.coverity.com/projects/3846
|
||||||
[Coverity Status]: https://scan.coverity.com/projects/3846/badge.svg
|
[Coverity Status]: https://scan.coverity.com/projects/3846/badge.svg
|
||||||
[LibuEV]: https://github.com/troglobit/libuev
|
[LibuEv]: https://github.com/troglobit/libuev
|
||||||
[Oku Kazuho]: https://github.com/kazuho
|
[Oku Kazuho]: https://github.com/kazuho
|
||||||
[Mark Lehmann]: http://software.schmorp.de
|
[Mark Lehmann]: http://software.schmorp.de
|
||||||
[Joachim Nilsson]: http://troglobit.com
|
[Joachim Nilsson]: http://troglobit.com
|
||||||
[Flemming Madsen]: http://www.madsensoft.dk
|
[Flemming Madsen]: http://www.madsensoft.dk
|
||||||
[Dave Zarzycki, Apple]: http://www.youtube.com/watch?v=cD_s6Fjdri8
|
[Dave Zarzycki, Apple]: http://www.youtube.com/watch?v=cD_s6Fjdri8
|
||||||
|
|
||||||
[libuEv] is developed and maintained by [Joachim Nilsson]
|
<!--
|
||||||
|
-- Local Variables:
|
||||||
|
-- mode: markdown
|
||||||
|
-- End:
|
||||||
|
-->
|
||||||
@@ -70,7 +70,7 @@ static int *pipes;
|
|||||||
static uev_t *evio;
|
static uev_t *evio;
|
||||||
static uev_t *evto;
|
static uev_t *evto;
|
||||||
|
|
||||||
static void read_cb(uev_ctx_t *UNUSED(ctx), uev_t *w, void *arg, int UNUSED(events))
|
static void read_cb(uev_t *w, void *arg, int UNUSED(events))
|
||||||
{
|
{
|
||||||
int idx, widx;
|
int idx, widx;
|
||||||
u_char ch;
|
u_char ch;
|
||||||
@@ -96,7 +96,7 @@ static void read_cb(uev_ctx_t *UNUSED(ctx), uev_t *w, void *arg, int UNUSED(even
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timer_cb(uev_ctx_t UNUSED(*ctx), uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events))
|
static void timer_cb(uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
/* nop */
|
/* nop */
|
||||||
}
|
}
|
||||||
@@ -208,16 +208,17 @@ int main(int argc, char **argv)
|
|||||||
if (timers)
|
if (timers)
|
||||||
uev_timer_init(&ctx, &evto[i], timer_cb, NULL, 0, 0);
|
uev_timer_init(&ctx, &evto[i], timer_cb, NULL, 0, 0);
|
||||||
args[i].index = i;
|
args[i].index = i;
|
||||||
uev_io_init(&ctx, &evio[i], read_cb, &args[i], -1, UEV_READ);
|
|
||||||
|
|
||||||
#ifdef USE_PIPES
|
#ifdef USE_PIPES
|
||||||
if (pipe(cp) == -1) {
|
if (pipe2(cp, O_NONBLOCK) == -1) {
|
||||||
#else
|
#else
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
|
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, cp) == -1) {
|
||||||
#endif
|
#endif
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uev_io_init(&ctx, &evio[i], read_cb, &args[i], cp[0], UEV_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
|
|||||||
+16
-17
@@ -2,24 +2,23 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2014-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2014-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
@@ -40,7 +39,7 @@ struct js_event {
|
|||||||
uint8_t number; /* axis/button number */
|
uint8_t number; /* axis/button number */
|
||||||
} e;
|
} e;
|
||||||
|
|
||||||
static void joystick_cb(uev_ctx_t *UNUSED(ctx), uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
static void joystick_cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
if (read (w->fd, &e, sizeof(e)) < 0)
|
if (read (w->fd, &e, sizeof(e)) < 0)
|
||||||
errx(errno, "Failed reading joystick event");
|
errx(errno, "Failed reading joystick event");
|
||||||
|
|||||||
+25
-22
@@ -2,24 +2,23 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2015 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2015 Joachim Nilsson <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
@@ -69,13 +68,13 @@ static int callback(arg_t *arg, int event, void *foo)
|
|||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigsegv_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
static void sigsegv_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
warnx("PID %d caused segfault.", getpid());
|
warnx("PID %d caused segfault.", getpid());
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigchld_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
static void sigchld_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
pid_t pid = waitpid(-1, NULL, WNOHANG);
|
pid_t pid = waitpid(-1, NULL, WNOHANG);
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ static void sigchld_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(ar
|
|||||||
warnx("PID %d exited, bye.", pid);
|
warnx("PID %d exited, bye.", pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void work_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *arg, int UNUSED(events))
|
static void work_cb(uev_t *UNUSED(w), void *arg, int UNUSED(events))
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@@ -102,15 +101,17 @@ static void work_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *arg, int UNU
|
|||||||
if (WIFEXITED(status))
|
if (WIFEXITED(status))
|
||||||
printf("Child exited normally => %d\n", WEXITSTATUS(status));
|
printf("Child exited normally => %d\n", WEXITSTATUS(status));
|
||||||
else if (WCOREDUMP(status))
|
else if (WCOREDUMP(status))
|
||||||
printf("Child crashed!\n");
|
printf("Child crashed! %s\n", DO_SEGFAULT
|
||||||
|
? "As expected, everything is OK."
|
||||||
|
: "This should not happen!");
|
||||||
else
|
else
|
||||||
printf("Child did not exit normally!\n");
|
printf("Child did not exit normally!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exit_cb(uev_ctx_t *ctx, uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
static void exit_cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
printf("Process deadline reached, exiting!\n");
|
printf("Process deadline reached, exiting!\n");
|
||||||
uev_exit(ctx);
|
uev_exit(w->ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -120,6 +121,8 @@ int main(void)
|
|||||||
|
|
||||||
/* Initialize libuEv */
|
/* Initialize libuEv */
|
||||||
uev_init(&ctx);
|
uev_init(&ctx);
|
||||||
|
|
||||||
|
/* Setup callbacks */
|
||||||
uev_signal_init(&ctx, &sigsegv_watcher, sigsegv_cb, NULL, SIGSEGV);
|
uev_signal_init(&ctx, &sigsegv_watcher, sigsegv_cb, NULL, SIGSEGV);
|
||||||
uev_signal_init(&ctx, &sigchld_watcher, sigchld_cb, NULL, SIGCHLD);
|
uev_signal_init(&ctx, &sigchld_watcher, sigchld_cb, NULL, SIGCHLD);
|
||||||
uev_timer_init(&ctx, &timeout_watcher, work_cb, &arg, 400, 0);
|
uev_timer_init(&ctx, &timeout_watcher, work_cb, &arg, 400, 0);
|
||||||
|
|||||||
+23
-24
@@ -3,24 +3,23 @@
|
|||||||
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@@ -40,33 +39,33 @@ static int in, out;
|
|||||||
static int period = 0;
|
static int period = 0;
|
||||||
static uev_t *watchdog;
|
static uev_t *watchdog;
|
||||||
|
|
||||||
static void lifetime_cb(uev_ctx_t *ctx, uev_t UNUSED(*w), void *arg, int UNUSED(events))
|
static void lifetime_cb(uev_t *w, void *arg, int UNUSED(events))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nLifetime exceeded, program completed successfully! (arg:%p)\n", arg);
|
fprintf(stderr, "\nLifetime exceeded, program completed successfully! (arg:%p)\n", arg);
|
||||||
uev_exit(ctx);
|
uev_exit(w->ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The pipe watchdog, if it triggers we haven't received data in time. */
|
/* The pipe watchdog, if it triggers we haven't received data in time. */
|
||||||
static void timeout_cb(uev_ctx_t *ctx, uev_t *UNUSED(w), void *arg, int UNUSED(events))
|
static void timeout_cb(uev_t *w, void *arg, int UNUSED(events))
|
||||||
{
|
{
|
||||||
watchdog = NULL;
|
watchdog = NULL;
|
||||||
fprintf(stderr, "\nTimeout exceeded %p\n", arg);
|
fprintf(stderr, "\nTimeout exceeded %p\n", arg);
|
||||||
|
|
||||||
// uev_timer_stop(w); <-- No need to stop timers with period=0 :)
|
// uev_timer_stop(w); <-- No need to stop timers with period=0 :)
|
||||||
uev_exit(ctx);
|
uev_exit(w->ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void periodic_task(uev_ctx_t UNUSED(*ctx), uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events))
|
static void periodic_task(uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "|");
|
fprintf(stderr, "|");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signal_cb(uev_ctx_t *UNUSED(ctx), uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
static void signal_cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
fprintf(stderr, w->signo == SIGINT ? "^Cv" : "^\v");
|
fprintf(stderr, w->signo == SIGINT ? "^Cv" : "^\v");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pipe_read_cb(uev_ctx_t *UNUSED(ctx), uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events))
|
static void pipe_read_cb(uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
int cnt;
|
int cnt;
|
||||||
char msg[50];
|
char msg[50];
|
||||||
@@ -80,7 +79,7 @@ static void pipe_read_cb(uev_ctx_t *UNUSED(ctx), uev_t UNUSED(*w), void UNUSED(*
|
|||||||
fprintf(stderr, "%.*s.%d ", cnt, msg, cnt);
|
fprintf(stderr, "%.*s.%d ", cnt, msg, cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pipe_write_cb(uev_ctx_t UNUSED(*ctx), uev_t *w, void *arg, int UNUSED(events))
|
static void pipe_write_cb(uev_t *w, void *arg, int UNUSED(events))
|
||||||
{
|
{
|
||||||
my_t *my = arg;
|
my_t *my = arg;
|
||||||
char *msg = "TESTING";
|
char *msg = "TESTING";
|
||||||
|
|||||||
@@ -3,24 +3,23 @@
|
|||||||
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/* libuEv - Private methods and data types, do not use directly!
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBUEV_PRIVATE_H_
|
||||||
|
#define LIBUEV_PRIVATE_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/epoll.h>
|
||||||
|
#include "queue.h" /* OpenBSD queue.h > old GLIBC version */
|
||||||
|
|
||||||
|
/* I/O, timer, or signal watcher */
|
||||||
|
typedef enum {
|
||||||
|
UEV_IO_TYPE = 1,
|
||||||
|
UEV_TIMER_TYPE,
|
||||||
|
UEV_SIGNAL_TYPE,
|
||||||
|
} uev_type_t;
|
||||||
|
|
||||||
|
/* Event mask, used internally only. */
|
||||||
|
#define UEV_EVENT_MASK (UEV_READ | UEV_WRITE)
|
||||||
|
|
||||||
|
/* Main libuEv context type */
|
||||||
|
typedef struct {
|
||||||
|
int running;
|
||||||
|
int fd; /* For epoll() */
|
||||||
|
uint32_t errors;
|
||||||
|
LIST_HEAD(,uev) watchers;
|
||||||
|
} uev_ctx_t;
|
||||||
|
|
||||||
|
/* Forward declare due to dependencys, don't try this at home kids. */
|
||||||
|
struct uev;
|
||||||
|
|
||||||
|
/* This is used to hide all private data members in uev_t */
|
||||||
|
#define uev_private_t \
|
||||||
|
LIST_ENTRY(uev) link; /* For queue.h linked list */ \
|
||||||
|
\
|
||||||
|
int active; \
|
||||||
|
int events; \
|
||||||
|
\
|
||||||
|
/* Watcher callback with optional argument */ \
|
||||||
|
void (*cb)(struct uev *, void *, int); \
|
||||||
|
void *arg; \
|
||||||
|
\
|
||||||
|
/* Timer watchers, time in milliseconds */ \
|
||||||
|
int timeout; \
|
||||||
|
int period; \
|
||||||
|
\
|
||||||
|
/* Signal watchers */ \
|
||||||
|
int signo; \
|
||||||
|
\
|
||||||
|
/* Watcher type */ \
|
||||||
|
uev_type_t
|
||||||
|
|
||||||
|
/* Internal API for dealing with generic watchers */
|
||||||
|
int uev_watcher_init (uev_ctx_t *ctx, struct uev *w, uev_type_t type,
|
||||||
|
void (*cb)(struct uev *, void *, int), void *arg,
|
||||||
|
int fd, int events);
|
||||||
|
int uev_watcher_start(struct uev *w);
|
||||||
|
int uev_watcher_stop (struct uev *w);
|
||||||
|
|
||||||
|
#endif /* LIBUEV_PRIVATE_H_ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* version-control: t
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -3,24 +3,23 @@
|
|||||||
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
@@ -3,24 +3,23 @@
|
|||||||
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -123,11 +122,9 @@ int uev_timer_set(uev_t *w, int timeout, int period)
|
|||||||
msec2tspec(timeout, &time.it_value);
|
msec2tspec(timeout, &time.it_value);
|
||||||
msec2tspec(period, &time.it_interval);
|
msec2tspec(period, &time.it_interval);
|
||||||
timerfd_settime(w->fd, 0, &time, NULL);
|
timerfd_settime(w->fd, 0, &time, NULL);
|
||||||
|
|
||||||
return uev_watcher_start(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return uev_watcher_start(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,12 +154,12 @@ int uev_timer_start(uev_t *w)
|
|||||||
*/
|
*/
|
||||||
int uev_timer_stop(uev_t *w)
|
int uev_timer_stop(uev_t *w)
|
||||||
{
|
{
|
||||||
if (uev_watcher_stop(w))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* Stop kernel timer */
|
/* Stop kernel timer */
|
||||||
uev_timer_set(w, 0, 0);
|
uev_timer_set(w, 0, 0);
|
||||||
|
|
||||||
|
if (uev_watcher_stop(w))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* Close timerfd, will have to be reopened again on reset */
|
/* Close timerfd, will have to be reopened again on reset */
|
||||||
close(w->fd);
|
close(w->fd);
|
||||||
w->fd = -1;
|
w->fd = -1;
|
||||||
|
|||||||
@@ -3,24 +3,23 @@
|
|||||||
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -37,7 +36,7 @@
|
|||||||
|
|
||||||
static int _init(uev_ctx_t *ctx, int close_old)
|
static int _init(uev_ctx_t *ctx, int close_old)
|
||||||
{
|
{
|
||||||
int fd = epoll_create1(O_CLOEXEC);
|
int fd = epoll_create1(EPOLL_CLOEXEC);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -297,7 +296,7 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (w->cb)
|
if (w->cb)
|
||||||
w->cb((struct uev *)ctx, w, w->arg);
|
w->cb(w, w->arg, events[i].events & UEV_EVENT_MASK);
|
||||||
|
|
||||||
if (UEV_TIMER_TYPE == w->type) {
|
if (UEV_TIMER_TYPE == w->type) {
|
||||||
if (!w->timeout)
|
if (!w->timeout)
|
||||||
|
|||||||
@@ -3,33 +3,29 @@
|
|||||||
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
* Copyright (c) 2012 Flemming Madsen <flemming!madsen()madsensoft!dk>
|
||||||
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
* Copyright (c) 2013-2015 Joachim Nilsson <troglobit()gmail!com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* a copy of this software and associated documentation files (the
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* "Software"), to deal in the Software without restriction, including
|
* in the Software without restriction, including without limitation the rights
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
* furnished to do so, subject to the following conditions:
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* included in all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBUEV_UEV_H_
|
#ifndef LIBUEV_UEV_H_
|
||||||
#define LIBUEV_UEV_H_
|
#define LIBUEV_UEV_H_
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "private.h"
|
||||||
#include <sys/epoll.h>
|
|
||||||
|
|
||||||
#include "queue.h" /* OpenBSD queue.h > old GLIBC version */
|
|
||||||
|
|
||||||
/* Max. number of simulateneous events */
|
/* Max. number of simulateneous events */
|
||||||
#define UEV_MAX_EVENTS 10
|
#define UEV_MAX_EVENTS 10
|
||||||
@@ -43,54 +39,18 @@
|
|||||||
#define UEV_ONCE 1
|
#define UEV_ONCE 1
|
||||||
#define UEV_NONBLOCK 2
|
#define UEV_NONBLOCK 2
|
||||||
|
|
||||||
/* I/O, timer, or signal watcher */
|
/* Event watcher */
|
||||||
typedef enum {
|
|
||||||
UEV_IO_TYPE = 1,
|
|
||||||
UEV_TIMER_TYPE,
|
|
||||||
UEV_SIGNAL_TYPE,
|
|
||||||
} uev_type_t;
|
|
||||||
|
|
||||||
/* Forward declare due to dependencys, don't try this at home kids. */
|
|
||||||
struct uev;
|
|
||||||
|
|
||||||
/* Main libuEv context type */
|
|
||||||
typedef struct {
|
|
||||||
int running;
|
|
||||||
int fd; /* For epoll() */
|
|
||||||
uint32_t errors;
|
|
||||||
LIST_HEAD(,uev) watchers;
|
|
||||||
} uev_ctx_t;
|
|
||||||
|
|
||||||
/* I/O event watcher */
|
|
||||||
typedef struct uev {
|
typedef struct uev {
|
||||||
LIST_ENTRY(uev) link; /* For queue.h linked list */
|
/* Private data for libuEv internal engine */
|
||||||
|
uev_private_t type;
|
||||||
|
|
||||||
/* Common to all watchers */
|
/* Public data for users to reference */
|
||||||
uev_ctx_t *ctx;
|
|
||||||
uev_type_t type;
|
|
||||||
int active;
|
|
||||||
int fd;
|
int fd;
|
||||||
int events;
|
uev_ctx_t *ctx;
|
||||||
|
|
||||||
/* Watcher callback with optional argument */
|
|
||||||
void (*cb)(struct uev *, struct uev *, void *);
|
|
||||||
void *arg;
|
|
||||||
|
|
||||||
/* Timer watchers, time in milliseconds */
|
|
||||||
int timeout;
|
|
||||||
int period;
|
|
||||||
|
|
||||||
/* Signal watchers */
|
|
||||||
int signo;
|
|
||||||
} uev_t;
|
} uev_t;
|
||||||
|
|
||||||
/* Generic callback for watchers */
|
/* Generic callback for watchers */
|
||||||
typedef void (uev_cb_t)(uev_ctx_t *ctx, uev_t *w, void *arg, int events);
|
typedef void (uev_cb_t)(uev_t *w, void *arg, int events);
|
||||||
|
|
||||||
/* Private methods, do not use directly! */
|
|
||||||
int uev_watcher_init (uev_ctx_t *ctx, uev_t *w, uev_type_t type, uev_cb_t *cb, void *arg, int fd, int events);
|
|
||||||
int uev_watcher_start (uev_t *w);
|
|
||||||
int uev_watcher_stop (uev_t *w);
|
|
||||||
|
|
||||||
/* Public interface */
|
/* Public interface */
|
||||||
int uev_init (uev_ctx_t *ctx);
|
int uev_init (uev_ctx_t *ctx);
|
||||||
|
|||||||
Reference in new issue
Block a user