"Fossies" - the Fresh Open Source Software Archive

Member "httperf-0.9.0/src/event.c" (7 Apr 2007, 3523 Bytes) of package /linux/www/old/httperf-0.9.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "event.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2     httperf -- a tool for measuring web server performance
    3     Copyright 2000-2007 Hewlett-Packard Company and Contributors listed in
    4     AUTHORS file. Originally contributed by David Mosberger-Tang
    5 
    6     This file is part of httperf, a web server performance measurment
    7     tool.
    8 
    9     This program is free software; you can redistribute it and/or
   10     modify it under the terms of the GNU General Public License as
   11     published by the Free Software Foundation; either version 2 of the
   12     License, or (at your option) any later version.
   13     
   14     In addition, as a special exception, the copyright holders give
   15     permission to link the code of this work with the OpenSSL project's
   16     "OpenSSL" library (or with modified versions of it that use the same
   17     license as the "OpenSSL" library), and distribute linked combinations
   18     including the two.  You must obey the GNU General Public License in
   19     all respects for all of the code used other than "OpenSSL".  If you
   20     modify this file, you may extend this exception to your version of the
   21     file, but you are not obligated to do so.  If you do not wish to do
   22     so, delete this exception statement from your version.
   23 
   24     This program is distributed in the hope that it will be useful,
   25     but WITHOUT ANY WARRANTY; without even the implied warranty of
   26     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27     General Public License for more details.
   28 
   29     You should have received a copy of the GNU General Public License
   30     along with this program; if not, write to the Free Software
   31     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
   32     02110-1301, USA
   33 */
   34 
   35 #include <assert.h>
   36 #include <stdio.h>
   37 
   38 #include <httperf.h>
   39 #include <event.h>
   40 
   41 #define MAX_NUM_OPS 4
   42 
   43 static const char * const event_name[EV_NUM_EVENT_TYPES] =
   44   {
   45     "EV_PERF_SAMPLE",
   46     "EV_HOSTNAME_LOOKUP_START",
   47     "EV_HOSTNAME_LOOKUP_STOP",
   48     "EV_SESS_NEW",
   49     "EV_SESS_FAILED",
   50     "EV_SESS_DESTROYED",
   51     "EV_CONN_NEW",
   52     "EV_CONN_CONNECTING",
   53     "EV_CONN_CONNECTED",
   54     "EV_CONN_CLOSE",
   55     "EV_CONN_DESTROYED",
   56     "EV_CONN_FAILED",
   57     "EV_CONN_TIMEOUT",
   58     "EV_CALL_NEW",
   59     "EV_CALL_ISSUE",
   60     "EV_CALL_SEND_START",
   61     "EV_CALL_SEND_RAW_DATA",
   62     "EV_CALL_SEND_STOP",
   63     "EV_CALL_RECV_START",
   64     "EV_CALL_RECV_HDR",
   65     "EV_CALL_RECV_RAW_DATA",
   66     "EV_CALL_RECV_DATA",
   67     "EV_CALL_RECV_FOOTER",
   68     "EV_CALL_RECV_STOP",
   69     "EV_CALL_DESTROYED"
   70   };
   71 
   72 typedef struct Event_Action
   73   {
   74     int num_ops;
   75     struct closure
   76       {
   77     Event_Handler op;
   78     Any_Type arg;
   79       }
   80     closure[MAX_NUM_OPS];
   81   }
   82 Event_Action;
   83 
   84 static Event_Action action[EV_NUM_EVENT_TYPES] = {{0, }};
   85 
   86 void
   87 event_register_handler (Event_Type et, Event_Handler handler, Any_Type arg)
   88 {
   89   struct closure *c;
   90   int n;
   91 
   92   n = action[et].num_ops;
   93   if (n >= MAX_NUM_OPS)
   94     {
   95       fprintf (stderr, "event_register_handler: sorry, attempted to register "
   96            "more than %d handlers\n", MAX_NUM_OPS);
   97       exit (1);
   98     }
   99   c = action[et].closure + n;
  100   c->op = handler;
  101   c->arg = arg;
  102   action[et].num_ops = n + 1;
  103 }
  104 
  105 void
  106 event_signal (Event_Type type, Object *obj, Any_Type arg)
  107 {
  108   Event_Action *act = action + type;
  109   struct closure *c, *end;
  110 
  111   if (DBG > 1)
  112     {
  113       assert (NELEMS (event_name) == EV_NUM_EVENT_TYPES);
  114       fprintf (stderr, "event_signal: %s (obj=%p,arg=%lx)\n",
  115            event_name[type], obj, arg.l);
  116     }
  117 
  118   end = &act->closure[act->num_ops];
  119   for (c = &act->closure[0]; c < end; ++c)
  120     (*c->op) (type, obj, c->arg, arg);
  121 }