Exemplo n.º 1
0
void
NeubotPoller_break_loop(struct NeubotPoller *self)
{
	(void) self;

	event_loopbreak();
}
static void
snmp_write_cb(const int sock, short int which, void *arg)
{
  struct send_data_entry * entry;

  if (!TAILQ_EMPTY(&send_queue_head)) {
    entry = TAILQ_FIRST(&send_queue_head);

    /* Send the data back to the client */
    if (sendto(sock, entry->buf, entry->len, 0, (struct sockaddr *) entry->client_sin, sizeof(struct sockaddr_in)) == -1) {
      perror("sendto()");
      event_loopbreak();
    }
    TAILQ_REMOVE(&send_queue_head, entry, entries);

    free(entry->buf);
    free(entry->client_sin);
    free(entry);

    /* Free send event */
    event_free(snmp_send_event);

    /* if there is other data to be sent, register another EV_WRITE event */
    if (!TAILQ_EMPTY(&send_queue_head)) {
      snmp_send_event = event_new(event_base, sock, EV_WRITE, snmp_write_cb, NULL);
      event_add(snmp_send_event, NULL);
    }
  }
}
Exemplo n.º 3
0
void 
LEDSequencer::eventAction( uint32_t EventID )
{
    struct timeval CLOCK_TV;

    //std::cout << "LEDSequencer::eventAction" << std::endl;

    if( leds == NULL )
        return;

    // Immediately apply any update if necessary so
    // the we get it as close to the 100ms boundary
    // as possible.
    leds->processUpdates();

    if( cfgNode == NULL )
        return;

    // Get a timestamp for the sequencer to key off of if necessary
    if( gettimeofday( &CLOCK_TV, NULL ) ) 
    {
        perror("gettimeofday()");
        event_loopbreak();
    }

    // Perform sequence updates
    cfgNode->updateSequence( &CLOCK_TV, leds );
}
Exemplo n.º 4
0
void stop_cb(int fd, short events, void *arg)
#endif
{
	log_msg(LOG_DEBUG, "Received signal (%d), %s", fd, sys_siglist[fd]);
#if HAVE_LIBEVENT2
	event_base_loopbreak(cfg.eb);
#else
	event_loopbreak();
#endif
}
Exemplo n.º 5
0
/** 
 *  signal_handler - signal handler
 */
void signal_handler(int sig)
{
	switch (sig) {
#ifndef __WIN32
		case SIGHUP:
		case SIGQUIT:
#endif
		case SIGTERM:
		case SIGINT:
			//终止侦听event_dispatch()的事件侦听循环,执行之后的代码
			event_loopbreak();
			break;
	}
}
Exemplo n.º 6
0
static void
unprivileged_signal_handler(int sig, short ev, void *arg)
{
	(void) ev; (void) arg;

	switch (sig) {
	case SIGPIPE:
		break;
	case SIGCHLD:
		if (waitpid(privileged_pid, &privileged_exit_code, WNOHANG) ==
		    privileged_pid) {
			if (privileged_exit_code)
				log_warnx("privileged child died with %d",
				    privileged_exit_code);
			event_loopbreak();
		}
		break;
	case SIGHUP:
		break;
	default:
		event_loopbreak();
		break;
	}
}
Exemplo n.º 7
0
void    evt_server_stop()
{
    if (event_loopexit(&min_time) != 0) {
        event_loopbreak();
    }
    if (pool.nr > 0) {
        int i;
        for (i = 0; i < pool.nr; ++i) {
            cq_push_back(&pool.conns[i], -1, 0, NULL);
            while (pool.conns[i].size > 1) {
                usleep(THREAD_POLL_TIME);
            }
        }
        free(pool.conns);
    }
    freeaddrinfo(serv.ai);
}
Exemplo n.º 8
0
void 
HeartbeatEventSource::afterObservers( const int arg1, short int which )
{
    struct timeval CLOCK_TV;
    struct timeval NEW_TV;
    struct timeval TIMER_TV = {1, 0};

    //std::cout << "TimerEventSource::afterObservers" << std::endl;

    // Get the current time.
    if( gettimeofday( &CLOCK_TV, NULL ) ) 
    {
        perror("gettimeofday()");
        event_loopbreak();
    }

    //printf( "timer cb: %d, %d\n", CLOCK_TV.tv_sec, CLOCK_TV.tv_usec );

    // Calculate the time to the next 100ms boundary
    NEW_TV.tv_usec = ( ( CLOCK_TV.tv_usec / 1000 ) * 1000 ) + 1000;
    NEW_TV.tv_sec  = CLOCK_TV.tv_sec;

    while( NEW_TV.tv_usec >= 1000000 )
    {
        NEW_TV.tv_usec -= 1000000;
        NEW_TV.tv_sec  += 1;
    }

    //printf( "new time: %d, %d\n", NEW_TV.tv_sec, NEW_TV.tv_usec );

    if( NEW_TV.tv_usec == 0 )
    {
        TIMER_TV.tv_sec  = NEW_TV.tv_sec  - CLOCK_TV.tv_sec - 1;
        TIMER_TV.tv_usec = 1000000 - CLOCK_TV.tv_usec;
    }
    else
    {
        TIMER_TV.tv_sec  = NEW_TV.tv_sec  - CLOCK_TV.tv_sec;
        TIMER_TV.tv_usec = NEW_TV.tv_usec - CLOCK_TV.tv_usec;
    }

    //printf( "new inc: %d, %d\n", TIMER_TV.tv_sec, TIMER_TV.tv_usec );

    // Wake up again in a little bit.
    evtimer_add( getEventPtr(), &TIMER_TV );
}
Exemplo n.º 9
0
void 
HeartbeatEventSource::beforeObservers( const int arg1, short int which )
{
#if 0
    struct timeval CLOCK_TV;

    std::cout << "TimerEventSource::beforeObservers" << std::endl;

    if( gettimeofday( &CLOCK_TV, NULL ) ) 
    {
        perror("gettimeofday()");
        event_loopbreak();
    }

    printf( "timer cb: %d, %d\n", CLOCK_TV.tv_sec, CLOCK_TV.tv_usec );
#endif
}
static void
snmp_read_cb(const int sock, short int which, void *arg)
{
  socklen_t server_sz = sizeof(struct sockaddr_in);
  int len;
  uint8_t * buf;

  buf = xmalloc(TRANS_BUF_SIZ);
  client_sin = xmalloc(server_sz);

  /* Receive UDP data, store the address of the sender in client_sin */
  len = recvfrom(sock, buf, TRANS_BUF_SIZ, 0, (struct sockaddr *)client_sin, &server_sz);
  if (len == -1) {
    perror("recvfrom()");
    event_loopbreak();
  }

  /* Parse SNMP PDU in decoder */
  snmp_prot_ops.receive(buf, len);
}
Exemplo n.º 11
0
void
signal_handler(int sig) {
	switch(sig) {
		
		case SIGHUP:
			ini_parse(&Ctx);
			tolog(&Ctx, LOG_ERROR, "server restarted ");
			evhttp_free(httpd);
			httpd = evhttp_start(Ctx.bind, Ctx.port);
			evhttp_set_gencb(httpd, http_handler, NULL);
			event_dispatch();

			break;
		case SIGTERM:
		case SIGINT:
			event_loopbreak();
			break;
        default:
            //syslog(LOG_WARNING, "Unhandled signal (%d) %s", strsignal(sig));
            break;
    }
}
Exemplo n.º 12
0
void fpm_event_exit_loop()
{
	event_loopbreak();
}
Exemplo n.º 13
0
static void termination_handler(int signum)
{
    event_loopbreak();
}
Exemplo n.º 14
0
static void terminate(int sig, short what, void *_arg)
{
	if (event_loopbreak() != 0)
		log_error(LOG_WARNING, "event_loopbreak");
}
Exemplo n.º 15
0
void error_cb(int status_code, void *cb_arg)
{
    event_loopbreak();
}
Exemplo n.º 16
0
static void
state_machine_handler(int fd __attribute__((unused)), short event, void *arg)
{
  struct state_data *sd= arg;
  int status;

again:
  switch(sd->ST)
  {
  case 0:
    /* Initial state, start making the connection. */
    status= mysql_real_connect_start(&sd->ret, &sd->mysql, opt_host, opt_user, opt_password, opt_db, opt_port, opt_socket, 0);
    if (status)
      /* Wait for connect to complete. */
      next_event(1, status, sd);
    else
      NEXT_IMMEDIATE(sd, 9);
    break;

  case 1:
    status= mysql_real_connect_cont(&sd->ret, &sd->mysql, mysql_status(event));
    if (status)
      next_event(1, status, sd);
    else
      NEXT_IMMEDIATE(sd, 9);
    break;

  case 9:
    if (!sd->ret)
      fatal(sd, "Failed to mysql_real_connect()");
    NEXT_IMMEDIATE(sd, 10);
    break;

  case 10:
    /* Now run the next query. */
    sd->query_element= query_list;
    if (!sd->query_element)
    {
      /* No more queries, end the connection. */
      NEXT_IMMEDIATE(sd, 40);
    }
    query_list= query_list->next;

    sd->index= sd->query_element->index;
    printf("%d ! %s\n", sd->index, sd->query_element->query);
    status= mysql_real_query_start(&sd->err, &sd->mysql, sd->query_element->query,
                                   strlen(sd->query_element->query));
    if (status)
      next_event(11, status, sd);
    else
      NEXT_IMMEDIATE(sd, 20);
    break;

  case 11:
    status= mysql_real_query_cont(&sd->err, &sd->mysql, mysql_status(event));
    if (status)
      next_event(11, status, sd);
    else
      NEXT_IMMEDIATE(sd, 20);
    break;

  case 20:
    my_free(sd->query_element->query);
    my_free(sd->query_element);
    if (sd->err)
    {
      printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql));
      NEXT_IMMEDIATE(sd, 10);
    }
    else
    {
      sd->result= mysql_use_result(&sd->mysql);
      if (!sd->result)
        fatal(sd, "mysql_use_result() returns error");
      NEXT_IMMEDIATE(sd, 30);
    }
    break;

  case 30:
    status= mysql_fetch_row_start(&sd->row, sd->result);
    if (status)
      next_event(31, status, sd);
    else
      NEXT_IMMEDIATE(sd, 39);
    break;

  case 31:
    status= mysql_fetch_row_cont(&sd->row, sd->result, mysql_status(event));
    if (status)
      next_event(31, status, sd);
    else
      NEXT_IMMEDIATE(sd, 39);
    break;

  case 39:
    if (sd->row)
    {
      /* Got a row. */
      unsigned int i;
      printf("%d - ", sd->index);
      for (i= 0; i < mysql_num_fields(sd->result); i++)
        printf("%s%s", (i ? "\t" : ""), (sd->row[i] ? sd->row[i] : "(null)"));
      printf ("\n");
      NEXT_IMMEDIATE(sd, 30);
    }
    else
    {
      if (mysql_errno(&sd->mysql))
      {
        /* An error occured. */
        printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql));
      }
      else
      {
        /* EOF. */
        printf("%d | EOF\n", sd->index);
      }
      mysql_free_result(sd->result);
      NEXT_IMMEDIATE(sd, 10);
    }
    break;

  case 40:
    status= mysql_close_start(&sd->mysql);
    if (status)
      next_event(41, status, sd);
    else
      NEXT_IMMEDIATE(sd, 50);
    break;

  case 41:
    status= mysql_close_cont(&sd->mysql, mysql_status(event));
    if (status)
      next_event(41, status, sd);
    else
      NEXT_IMMEDIATE(sd, 50);
    break;

  case 50:
    /* We are done! */
    num_active_connections--;
    if (num_active_connections == 0)
      event_loopbreak();
    break;

  default:
    abort();
  }
}
Exemplo n.º 17
0
void c_basis::loopbreak()
{
	event_loopbreak();
}