root/orte/test/system/evpri-test2.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. die
  2. cbfunc2
  3. cbfunc1
  4. main

   1 
   2 #include <event2/event.h>
   3 #include <event2/event_struct.h>
   4 
   5 #include <stdio.h>
   6 #include <stdlib.h>
   7 #include <signal.h>
   8 #include <stdbool.h>
   9 
  10 #define SIGPRI 0
  11 #define TERMPRI 1
  12 
  13 static struct event_base *base;
  14 static bool run=true;
  15 static int loops=0;
  16 static bool again=false;
  17 static struct event ev2, ev3;
  18 
  19 
  20 static void
  21 die(const char *msg)
  22 {
  23     fprintf(stderr, "%s\n", msg);
  24     fflush(stderr);
  25     exit(1);
  26 }
  27 
  28 static void
  29 cbfunc2(evutil_socket_t fd, short what, void *arg)
  30 {
  31     fprintf(stderr, "CAUGHT EVENT 2\n");
  32     fflush(stderr);
  33 #if 0
  34     event_base_loopbreak(base);
  35 #endif
  36     run = false;
  37 }
  38 
  39 static void
  40 cbfunc1(evutil_socket_t fd, short what, void *arg)
  41 {
  42     if (again) {
  43         fprintf(stderr, "CYCLING BACK THRU EVENT 1\n");
  44         return;
  45     }
  46 
  47     fprintf(stderr, "CAUGHT EVENT 1\n");
  48     fflush(stderr);
  49     again = true;
  50 
  51     if (event_assign(&ev2, base, -1, EV_WRITE, cbfunc1, NULL) < 0)
  52         die("event_assign_2");
  53     if (event_priority_set(&ev2, 4) < 0)
  54         die("event_priority_set2");
  55     event_active(&ev2, EV_WRITE, 1);
  56     fprintf(stderr, "CB1: FIRST EVENT DEFINED\n");
  57     fflush(stderr);
  58 
  59     if (event_assign(&ev3, base, -1, EV_WRITE, cbfunc2, NULL) < 0)
  60         die("event_assign_3");
  61     if (event_priority_set(&ev3, 0) < 0)
  62         die("event_priority_set3");
  63     event_active(&ev3, EV_WRITE, 1);
  64     fprintf(stderr, "CB2: SECOND EVENT DEFINED\n");
  65     fflush(stderr);
  66 }
  67 
  68 int
  69 main(int argc, char **argv)
  70 {
  71     struct event ev1;
  72 
  73     event_enable_debug_mode();
  74 
  75     fprintf(stderr, "Libevent %s\n", event_get_version());
  76     fflush(stderr);
  77 
  78     if (!(base = event_base_new()))
  79         die("event_base_new");
  80     if (event_base_priority_init(base, 8) < 0)
  81         die("event_base_priority_init");
  82 
  83     if (event_assign(&ev1, base, -1, EV_WRITE, cbfunc1, NULL) < 0)
  84         die("event_assign_1");
  85     if (event_priority_set(&ev1, 4) < 0)
  86         die("event_priority_set");
  87     event_active(&ev1, EV_WRITE, 1);
  88     fprintf(stderr, "FIRST EVENT DEFINED\n");
  89     fflush(stderr);
  90 
  91     /*    event_dispatch(base); */
  92 
  93     while (run) {
  94         event_base_loop(base, EVLOOP_ONCE);
  95     }
  96 
  97     fprintf(stderr, "EXITED LOOP - FREEING BASE\n");
  98     fflush(stderr);
  99     event_base_free(base);
 100     return 0;
 101 }

/* [<][>][^][v][top][bottom][index][help] */