[Libwebsockets] [PATCH v2 2/9] introduce context->event_ops

Alejandro Mery amery at geeks.cl
Thu Dec 18 11:48:36 CET 2014


On 17 December 2014 at 22:20, Alejandro Mery <amery at geeks.cl> wrote:
> Signed-off-by: Alejandro Mery <alejandro.mery at opensynergy.com>
> ---
>  CMakeLists.txt              |  2 ++
>  lib/context.c               | 11 +++++++++++
>  lib/event-poll-unix.c       |  4 ++++
>  lib/event-poll-win.c        |  4 ++++
>  lib/libwebsockets.h         |  9 +++++++++
>  lib/private-libwebsockets.h |  2 ++
>  6 files changed, 32 insertions(+)
>  create mode 100644 lib/event-poll-unix.c
>  create mode 100644 lib/event-poll-win.c
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index d890ef5..1f21dc5 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -306,10 +306,12 @@ endif()
>  if (WIN32)
>         list(APPEND SOURCES
>                 lib/lws-plat-win.c
> +               lib/event-poll-win.c
>                 )
>  else()
>         list(APPEND SOURCES
>                 lib/lws-plat-unix.c
> +               lib/event-poll-unix.c
>                 )
>  endif()
>
> diff --git a/lib/context.c b/lib/context.c
> index 2ea9c60..c90e9c4 100644
> --- a/lib/context.c
> +++ b/lib/context.c
> @@ -107,6 +107,17 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
>                 return NULL;
>         }
>
> +       if (info->event_ops)
> +               context->event_ops = info->event_ops;
> +       else
> +               context->event_ops = &lws_poll_event_ops;
> +
> +       if (context->event_ops->init &&
> +           !context->event_ops->init(info, context)) {
> +               lws_free(context);
> +               return NULL;
> +       }
> +
>         if (pid_daemon) {
>                 context->started_with_parent = pid_daemon;
>                 lwsl_notice(" Started with daemon pid %d\n", pid_daemon);
> diff --git a/lib/event-poll-unix.c b/lib/event-poll-unix.c
> new file mode 100644
> index 0000000..7ccc6a5
> --- /dev/null
> +++ b/lib/event-poll-unix.c
> @@ -0,0 +1,4 @@
> +#include "private-libwebsockets.h"
> +
> +struct lws_event_ops lws_poll_event_ops = {
> +};
> diff --git a/lib/event-poll-win.c b/lib/event-poll-win.c
> new file mode 100644
> index 0000000..7ccc6a5
> --- /dev/null
> +++ b/lib/event-poll-win.c
> @@ -0,0 +1,4 @@
> +#include "private-libwebsockets.h"
> +
> +struct lws_event_ops lws_poll_event_ops = {
> +};
> diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
> index 3c717ff..684de60 100644
> --- a/lib/libwebsockets.h
> +++ b/lib/libwebsockets.h
> @@ -554,6 +554,7 @@ struct libwebsocket;
>  struct libwebsocket_context;
>  /* needed even with extensions disabled for create context */
>  struct libwebsocket_extension;
> +struct lws_context_creation_info;
>
>  /**
>   * callback_function() - User server actions
> @@ -992,6 +993,13 @@ struct libwebsocket_extension {
>  };
>  #endif
>
> +struct lws_event_ops {
> +       int (*init)(struct lws_context_creation_info *info,
> +                   struct libwebsocket_context *context);
> +};
> +
> +LWS_EXTERN struct lws_event_ops lws_poll_event_ops;

LWS_VISIBLE is missing here

> +
>  /**
>   * struct lws_context_creation_info: parameters to create context with
>   *
> @@ -1056,6 +1064,7 @@ struct lws_context_creation_info {
>         int uid;
>         unsigned int options;
>         void *user;
> +       struct lws_event_ops *event_ops;
>         int ka_time;
>         int ka_probes;
>         int ka_interval;
> diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h
> index 975c671..3abac16 100755
> --- a/lib/private-libwebsockets.h
> +++ b/lib/private-libwebsockets.h
> @@ -435,6 +435,8 @@ struct libwebsocket_context {
>  #endif
>         } e;
>
> +       struct lws_event_ops *event_ops;
> +
>         int listen_port;
>         const char *iface;
>         char http_proxy_address[128];
> --
> 2.2.0
>



More information about the Libwebsockets mailing list