[nginx] Events: implemented eventport notification mechanism.

Valentin Bartenev vbart at nginx.com
Wed Mar 18 15:58:03 UTC 2015


details:   http://hg.nginx.org/nginx/rev/117c77b22db1
branches:  
changeset: 6021:117c77b22db1
user:      Ruslan Ermilov <ru at nginx.com>
date:      Sat Mar 14 17:37:21 2015 +0300
description:
Events: implemented eventport notification mechanism.

diffstat:

 src/event/modules/ngx_eventport_module.c |  35 +++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)

diffs (87 lines):

diff -r e5f1d83360ef -r 117c77b22db1 src/event/modules/ngx_eventport_module.c
--- a/src/event/modules/ngx_eventport_module.c	Sat Mar 14 17:37:16 2015 +0300
+++ b/src/event/modules/ngx_eventport_module.c	Sat Mar 14 17:37:21 2015 +0300
@@ -93,6 +93,13 @@ int port_getn(int port, port_event_t lis
     return -1;
 }
 
+int port_send(int port, int events, void *user);
+
+int port_send(int port, int events, void *user)
+{
+    return -1;
+}
+
 
 int timer_create(clockid_t clock_id, struct sigevent *evp, timer_t *timerid);
 
@@ -133,6 +140,7 @@ static ngx_int_t ngx_eventport_add_event
     ngx_uint_t flags);
 static ngx_int_t ngx_eventport_del_event(ngx_event_t *ev, ngx_int_t event,
     ngx_uint_t flags);
+static ngx_int_t ngx_eventport_notify(ngx_event_handler_pt handler);
 static ngx_int_t ngx_eventport_process_events(ngx_cycle_t *cycle,
     ngx_msec_t timer, ngx_uint_t flags);
 
@@ -143,6 +151,7 @@ static int            ep = -1;
 static port_event_t  *event_list;
 static ngx_uint_t     nevents;
 static timer_t        event_timer = (timer_t) -1;
+static ngx_event_t    notify_event;
 
 static ngx_str_t      eventport_name = ngx_string("eventport");
 
@@ -172,7 +181,7 @@ ngx_event_module_t  ngx_eventport_module
         ngx_eventport_del_event,           /* disable an event */
         NULL,                              /* add an connection */
         NULL,                              /* delete an connection */
-        NULL,                              /* trigger a notify */
+        ngx_eventport_notify,              /* trigger a notify */
         NULL,                              /* process the changes */
         ngx_eventport_process_events,      /* process the events */
         ngx_eventport_init,                /* init the events */
@@ -215,6 +224,9 @@ ngx_eventport_init(ngx_cycle_t *cycle, n
                           "port_create() failed");
             return NGX_ERROR;
         }
+
+        notify_event.active = 1;
+        notify_event.log = cycle->log;
     }
 
     if (nevents < epcf->events) {
@@ -406,6 +418,21 @@ ngx_eventport_del_event(ngx_event_t *ev,
 }
 
 
+static ngx_int_t
+ngx_eventport_notify(ngx_event_handler_pt handler)
+{
+    notify_event.handler = handler;
+
+    if (port_send(ep, 0, &notify_event) != 0) {
+        ngx_log_error(NGX_LOG_ALERT, notify_event.log, ngx_errno,
+                      "port_send() failed");
+        return NGX_ERROR;
+    }
+
+    return NGX_OK;
+}
+
+
 ngx_int_t
 ngx_eventport_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
     ngx_uint_t flags)
@@ -580,6 +607,12 @@ ngx_eventport_process_events(ngx_cycle_t
 
             continue;
 
+        case PORT_SOURCE_USER:
+
+            ev->handler(ev);
+
+            continue;
+
         default:
             ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
                           "unexpected eventport object %d",



More information about the nginx-devel mailing list