Nick Zavaritsky | 6 Oct 17:05 2015

libeio broken in revision 1.139

Hi Marc,

We’ve updated to the latest libeio and we were very upset due to it crashing in etp_poll like crazy.

The problem was due to want_poll/done_poll callbacks missing in the internal etp_pool object, obviously
eio_init isn’t setting them.

Attaching a patch to illustrate the point.

Please have a nice day.
Attachment (libeio.cb.patch): application/octet-stream, 784 bytes
libev mailing list
libev <at>
黄东文 | 18 Sep 10:59 2015

a bug?

hi all:

                   in eio.c ,line num:2209,  has a bug:when goto quit, do you forget to --started?

libev mailing list
libev <at>
Zsbán Ambrus | 9 Sep 11:28 2015

Ecb: unaligned integer load and store support

Code for unaligned integer load and store.  This should eventually go
to libecb.  Be vary of the code, I haven't really tested it, it's
probably full of typos.  Also, no documentation yet.

struct ecb_array_u8_8 { uint8_t ecb_e[8]; };
union ecb_union_u64 { ecb_array_u8_8 ecb_a; uint64_t ecb_v; };
ecb_inline uint64_t ecb_load_u64(const void *ecb_p)
    union ecb_union_u64 ecb_u;
    ecb_u.ecb_a = *(const ecb_array_u8_8 *)ecb_p;
    return ecb_u.ecb_v;
ecb_inline void ecb_store_u64(void *ecb_p, uint64_t ecb_x)
    union ecb_union_u64 ecb_u;
    ecb_u.ecb_v = ecb_x;
    *(ecb_array_u8_8 *)ecb_p = ecb_u.ecb_a;
struct ecb_array_u8_4 { uint8_t ecb_e[4]; };
union ecb_union_u32 { ecb_array_u8_4 ecb_a; uint32_t ecb_v; };
ecb_inline uint32_t ecb_load_u32(const void *ecb_p)
    union ecb_union_u32 ecb_u;
    ecb_u.ecb_a = *(const ecb_array_u8_4 *)ecb_p;
    return ecb_u.ecb_v;
ecb_inline void ecb_store_u32(void *ecb_p, uint32_t ecb_x)
    union ecb_union_u32 ecb_u;
    ecb_u.ecb_v = ecb_x;
    *(ecb_array_u8_4 *)ecb_p = ecb_u.ecb_a;
struct ecb_array_u8_2 { uint8_t ecb_e[2]; };
union ecb_union_u16 { ecb_array_u8_2 ecb_a; uint16_t ecb_v; };
ecb_inline uint16_t ecb_load_u16(const void *ecb_p)
    union ecb_union_u16 ecb_u;
    ecb_u.ecb_a = *(const ecb_array_u8_2 *)ecb_p;
    return ecb_u.ecb_v;
ecb_inline void ecb_store_u16(void *ecb_p, uint16_t ecb_x)
    union ecb_union_u16 ecb_u;
    ecb_u.ecb_v = ecb_x;
    *(ecb_array_u8_2 *)ecb_p = ecb_u.ecb_a;

// -- Ambrus

libev mailing list
libev <at>
Zsbán Ambrus | 5 Sep 01:10 2015

Ecb: alignas and alignof support

I've prepared a patch and test to add alignas and alignof support to
the ecb library.  This is "ecb-alignas0.patch", attached to this mail.

While making this patch, I found out a lot about strange behavior of
certain compilers, but probably not everything, so there may still be

I've made a test program "ecb_align_test.c" that can check some of the
behavior of the patch.  After patching libecb.h, please compile and
run the test program with whatever compiler you have available, and
see if it works.  I recommend that you try to compile it separately as
a C source and a C++ source, because the patch should work in both
cases, but the language and available features differ.  I also
recommend that you build in both a C11 and C99 mode, and both a C++11
(or later) and C++98 mode, if your compiler has such an option.  I
will test with msvc 2013 next week.  The program should compile, and
when ran, print "Alignas test ok." after some other debug information.
If you get a failure, please report on the mailing list, possibly with
a patch.

Some notes about the implementation.
1. I do not check for the version of gcc, because even on a new enough
version there seems to be no way to use alignas or _Alignas in C99 or
C++98 mode.
2. Msvc gives an error to a declaration like __declspec(align(1))
__declspec(align(64)) which is why I insist on no doubled
3. Clang gives a syntax error to a declaration like
__attribute__((unused)) alignas(64) char x; which is why the
documentation insists that ecb_alignas(v) much come before ecb_unused.
4. I don't allow putting the ecb_alignas(v) after a variable name,
because MSC gives a syntax error to a declaration like int x
5. I haven't tried more exotic compilers, or old versions of
compilers, at all.  It's likely that there will be failures on some
compilers other than gcc, clang, msc.

Attachment (ecb-alignas0.patch): text/x-diff, 4676 bytes
Attachment (ecb_align_test.c): text/x-csrc, 2699 bytes
libev mailing list
libev <at>
Denis Denisov | 10 Aug 05:07 2015

libev-4.20, ev.h: fatal error: expected identifier

# cc --version
clang version 3.6.0
Thread model: posix

In file included from /usr/local/include/ev++.h:46:
/usr/local/include/ev.h:240:3: fatal error: expected identifier
  EV_ERROR    = (int)0x80000000  /* sent when an error occurs */
/usr/include/sys/event.h:86:18: note: expanded from macro 'EV_ERROR'
#define EV_ERROR        0x4000          /* error, data contains errno */
1 error generated.
*** Error code 1

[ev.c:4827] -> [ev.c:4821]: (warning) Possible null pointer
dereference: once - otherwise it is redundant to check it against
[ev.c:4828] -> [ev.c:4821]: (warning) Possible null pointer
dereference: once - otherwise it is redundant to check it against
[ev.c:3520]: (warning) Assert statement modifies 'loop_done'.
[ev.c:3522]: (warning) Assert statement modifies 'loop_done'.


Denis Denisov
Attachment (darwin-warning.log): application/octet-stream, 23 KiB
libev mailing list
libev <at>
Thomas Petazzoni | 8 Aug 23:50 2015

[PATCH] Fix SPARCv8 condition

Fix SPARCv8 condition

The define provided by the compiler on SPARCv8 is __sparc_v8__ and not
__sparcv8. From a SPARCv8 gcc:

$ sparc-linux-gcc --version
sparc-linux-gcc (Buildroot 2015.08-git-00497-ge110081) 4.9.3
$ sparc-linux-gcc -dM -E - < /dev/null | grep sparc
#define sparc 1
#define __sparc__ 1
#define __sparc 1
#define __sparc_v8__ 1

Signed-off-by: Thomas Petazzoni <thomas.petazzoni <at>>

Index: b/ev.c
--- a/ev.c
+++ b/ev.c
 <at>  <at>  -649,7 +649,7  <at>  <at> 
       #define ECB_MEMORY_FENCE         __asm__ __volatile__ ("dmb"      : : : "memory")
     #elif __aarch64__
       #define ECB_MEMORY_FENCE         __asm__ __volatile__ ("dmb ish"  : : : "memory")
-    #elif (__sparc || __sparc__) && !__sparcv8
+    #elif (__sparc || __sparc__) && !__sparc_v8__
       #define ECB_MEMORY_FENCE         __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore |
#StoreLoad" : : : "memory")
       #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad"                            : : : "memory")
       #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore             | #StoreStore")


Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering

libev mailing list
libev <at>
Zsbán Ambrus | 8 Aug 18:05 2015

Libecb: notes about alignas and alignof

I'd really like a portable way to use alignof and alignas.  This seems
impossible, especially on old compilers, but I still think libecb
might still try to help in some cases.  I don't know the final
solution of what could be done, so here I'm trying to collect
information about what compilers support what features, and how you
can test them without a configure system.  I'll take alignof and
alignas separately.  These are mostly symmetric, but have differences.

== alignof ==
The C++11 alignof keyword queries the required alignment of a type.

1. The alignof keyword is available in C++11, C++ in starting from gcc
4.8, C++ in clang if __has_feature(cxx_alignas), but not yet in any
version of the MS compiler.
2. The _Alignof keyword, and the macro alignof in <stdalign.h>, is
available in C11, and I don't know the compiler versions.
3. The GCC __alignof__ keyword is available starting from ancient
times (before gcc 3).
4. The MS compiler has an __alignof keyword.
5. The std::alignment_of template in <type_traits> would be a suitable
replacement to alignof, but it's probably only available in C++11
compilers that have alignof anyway.
6. Boost has an implementation of the alignment_of in the TypeTraits
library for some compilers, unknown header and namespace, which might
give some hints if only you could untangle the source code.
7. The boost config module has some macros like BOOST_NO_CXX11_ALIGNAS
that try to tell whether compilers have C++11 alignas, but it's hard
to read the boost source code to find out how this works, and it's
sometimes not precise, so it's useful only as a starting point.

== alignas ==
The alignas specifier is more complicated because it can syntactically
appear in multiple places in the code (qualifying a struct or an
object declaration), and only some of these could be possible on
certain compilers, and also because it can take both a type or a value
as its parameter.  Let me talk about these separately now.

1. The alignas keyword is available in C++11, C++ in starting from gcc
4.8, unknown versions of clang, but not yet in any version of the MS
2. The _Alignas keyword, and the macro alignas in <stdalign.h>, is
available in C11, and I don't know the compiler versions.
3. There's a gcc-specific attribute __attribute__((aligned()))
starting from ancient times (before gcc 3), and can be applied to both
structure and variable definitions.  This takes only an alignment
number parameter, not a type.
4. There's an MS complier attribute __declspec(align()).  I think this
doesn't quite support the full semantics of alignof, but can still
help in some cases.  The MSDN documentation at
"" promises a
lot but is a bit suspicious and haven't been updated for a while.  In
any case, the MS compiler seems to have some strange ideas about
alignment, in particular, it sometimes doesn't align objects on the
stack, which could be why they don't want to add the alignas keyword.
Still, this attribute may help for at least global variables.
5. The std::aligned_storage template class lets you create overaligned
types in some special cases and with ugly syntax.  However, it is
probably available only in C++11 compilers that have alignas anyway,
so it won't help much.
6. Boost has an implementation of aligned_storage somewhere in the
TypeTraits module, which could give some hints.
8. You can sometimes use a union with a highly aligned type to create
aligned storage, but this only helps if you have a type that's highly
aligned in first place, so 64-byte alignment this way is impossible
except in the latest systems.

The syntax of where you can place these in a declaration is picky, and
differ for these.  For a struct definition, put alignas(32) or
__attribute__((aligned(32))) or __declspec(align(32)) between the
struct keyword and the name of the newly defined structure type.  For
a variable (member) definition, put alignas(32) or
__attribute((aligned(32))) or __declspec(align(32)) at the very
beginning of the declaration.  Placing them like these is at least
accepted without a warning on some compilers, but it's hard to be sure
it actually set alignment.

== other stuff ==
Sometimes I'd like an aligned_alloc function (as in C11).  Most C
libraries, even the oldest ones, seem to have something like this, but
with lots of differences in the interface.  Boost has an
implementation which seems to work, but I think it doesn't always do
the optimal thing.  This, however, probably does not belong to libecb.

Slightly related is reading and writing unaligned integers in the
memory (and possibly floats too).  Boost now has a library that I can
use for this (called Endian), which supports unaligned integers of all
sizes and endiannesses, with a C++ interface.  This has at least some
platform-specific optimizations for endianness swaps.  I don't know
whether it can handle unaligned accesses efficiently, and that might
even be impossible on x86 systems, where some cpu instructions allow
unaligned access, some don't, some depend on some modes or states or
cpu types, and compilers don't seem to have an interface to do
unaligned access, even though I think they should.  I've used this
library to read a misaligned int64_t recently, but that didn't require
any sort of performance.  Anyway, if you can figure out how to handle
this properly, some functions for this could still be useful for

-- Ambrus

libev mailing list
libev <at>

repeating topic : detectect uncleanly closed socket

Hi all

I finally managed my implementation of an multi-threaded socket server 
with libev.

Now there is one thing left: detecting uncleanly disconnected sockets.

At the moment the approach of the client is the following:

1x ioReadWatcher
1x ioWriteWatcher
1x stopWatcher
1x timerWatcher called every 10/20/30 sec

I'm looking for a nice approach to implement the detection, as my 
devices are on a mobile network, due to this might loose connection.

Reconnect is cleanly handled.
But if the socket disconnects uncleanly, the timer keeps running and the 
client is kept open...

What is the suggested approach to implement this.
Any suggestions and code snippets are highly welcome!

Thanks in advance


libev mailing list
libev <at>
Cheyi Lin | 30 Jul 17:48 2015

How does libev invoke an io watcher if both EV_READ and EV_WRITE are pending?

If both EV_READ and EV_WRITE are pending, libev will ...

1) invoke the callback twice, one is for EV_READ, the other is for EV_WRITE.
2) invoke the callback once, revents |= (EV_READ | EV_WRITE).

Which is correct? Thanks.

Cheyi Lin

libev mailing list
libev <at>
Morand, Guy | 6 Jul 15:09 2015


Hello libev developpers!

I'm writing a little application to monitor GPIO status on my embedded Linux device. I wanted to give libev a
try, on the paper it looks really cool and fast.

However, to monitor a GPIO line, I need to get the  EXCEPTION event from select or the POLLPRI from poll.
Unfortunately this event doesn't seem to be implemented in libev and I can't use it out of the box. 

Before trying to change something, I wanted to see with you if there is there any reasons for no implementing
this event? What are the constraints and the limitations?

Kind regards,

Guy Morand

libev mailing list
libev <at>

Questions - partly newbie

Hi all

I'm new to event loops and am wondering about a couple of things...
Maybe somebody will clarify the questions for me. I'm using ev++ for 
implementation, if this is of interest.

I'm implementing a TCP-Socket Server on Linux to which a large number of 
embedded devices is connecting and reporting status every 10-60sec.

The current architecture spawns a thread for the server, accepting 
connections in an own ev::default_loop.
The server there is 2x ev:signal and 1x ev::io(ev::READ) for accepting 

On accepting the client gets it's own thread with an ev::dynamic_loop.
For the client I'm using 2x ev::io (1x ev::READ, 1x ev::WRITE), 1x 
ev::timer, 1x ev::async for stopping.

1. When running an event loop with multiple watchers, per iteration only 
one watcher is called - is this intended or is my implementation wrong?

2. Having the ev::timer running, at some point the ev::io watchers stop 
working. are the watcher excluding each other?

3. Sometimes the latency is extremly high, when accepting connections. I 
can't really find a reason for this. Any hints?

4. Is there any known difference between ev++ and ev I should be caring 

I started with this examples as a base for the implementation:

Thanks for your help and patience in advance!


libev mailing list
libev <at>