libev and libevent

Andy Green andy at warmcat.com
Tue Feb 20 03:35:01 CET 2018



On 20/02/18 10:17, Marc Lehmann wrote:
> On Tue, Feb 20, 2018 at 12:40:38AM +0800, Andy Green <andy at warmcat.com> wrote:
>> You sound confident about that, but actually having implemented it, you have not considered that the structures composing event lib state (handles, loop objects etc) must be defined in one place with types available for all event libs simultaneously.
> 
> Not really, even C supports opaque types.

No, there is no "not really" about it.

C supports opaque type pointers because the size of a pointer is known 
regardless of the details of what it points to.

However you cannot compose an opaque / forward-referenced struct into 
another struct with type safety, because the size of the undefined thing 
is unknown.

For example you do this:

typedef struct ev_io
{
   EV_WATCHER_LIST (ev_io)

   int fd;     /* ro */
   int events; /* ro */
} ev_io;


and I do this

struct lws_io_watcher {
#ifdef LWS_WITH_LIBEV
         ev_io ev_watcher;
#endif
#ifdef LWS_WITH_LIBUV
         uv_poll_t uv_watcher;
#endif
#ifdef LWS_WITH_LIBEVENT
         struct event *event_watcher;
#endif
         struct lws_context *context;

         uint8_t actual_events;
};

I must have your struct definition and that means I must have your headers.

-Andy



More information about the libev mailing list