GithubHelp home page GithubHelp logo

coderjie / libuev Goto Github PK

View Code? Open in Web Editor NEW

This project forked from troglobit/libuev

0.0 1.0 0.0 461 KB

Lightweight event loop library for Linux

Home Page: https://github.com/troglobit/libuev/blob/master/examples/joystick.c

License: MIT License

Makefile 2.88% Shell 0.06% M4 0.73% C 96.33%

libuev's Introduction

libuEv | Simple event loop for Linux

Travis Status Coverity Status

NOTE: Incompatible failure mode changes in v2.0 compared to v1.x!

Introduction

libuEv is a simple event loop in the style of the more established libevent, libev and the venerable Xt(3) event loop. The u (micro) in the name refers to both the small feature set and the small size overhead impact of the library.

Failure mode changes introduced in v2.0 may affect users of v1.x, See the ChangeLog for the full details.

The API documentation is available as a separate document.

Example

Notice below how watcher UEV_ERROR conditions must be handled by each callback. I/O watchers must also check for UEV_HUP. Both errors are usually fatal, libuEv makes sure to stop each watcher before a callback runs, leaving it up to the callback to take appropriate action.

#include <stdio.h>
#include <uev/uev.h>

static void cb(uev_t *w, void *arg, int events)
{
    if (UEV_ERROR == events) {
        puts("Problem with timer, attempting to restart.");
        uev_timer_start(w);
    }
	puts("Every other second");
}

int main(void)
{
	uev_t timer;
	uev_ctx_t ctx;

	uev_init(&ctx);
	/* Set up a timer watcher to call cb() every other second */
	uev_timer_init(&ctx, &timer, cb, NULL, 2 * 1000, 2 * 1000);

	return uev_run(&ctx, 0);
}

Build & Install

libuEv use the GNU configure and build system. To try out the bundled examples, use the --enable-examples switch to the configure script. There is also a limited unit test suite that can be useful to learn how the library works.

./configure
make -j5
make test
sudo make install-strip
sudo ldconfig

The resulting .so file is ~14 kiB.

Origin & References

libuEv originates from LibUEvent by Flemming Madsen, but with a rewritten and much cleaner API. It is now more similar to the famous libev by Mark Lehmann. Another library inspiring this project is picoev by Oku Kazuho.

libuEv is developed and maintained by Joachim Nilsson. It is built for and developed on GNU/Linux systems, patches to support *BSD and its kqueue interface are most welcome.

libuev's People

Contributors

troglobit avatar martijn81 avatar villains avatar vonj avatar tisyang avatar

Watchers

静心沉淀 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.