Пример #1
0
int Reactor :: add_event(Event * ev,
                         struct timeval * tv,
                         bool actived)
{
    int ret = 0;
    if(ev == NULL)
       return 0;
    
    if(status & RA_THREAD)
    {
        pthread_mutex_lock(&event_mutex);
        if(!set_io_event_active(ev))
        {
            Log :: WARN("Add fail, Event is ACtive, FD %d", ev->ev_fd);
            pthread_mutex_unlock(&event_mutex);
            return -1;
        } 
        pthread_mutex_unlock(&event_mutex);
    } 

    Log :: DEBUG("ADD EVENT FD: %d events: %s%s%s reactor: %d",
                 ev->ev_fd,
                 ev->ev_events&EV_READ ? "READ":"",
                 ev->ev_events&EV_WRITE ?"WRITE":"",
                 ev->ev_events&EV_TIMEOUT?"TIME":"",
                 epfd);
      
    assert((ev->ev_flags & EV_INIT));

    if(tv != NULL)
    {
        assert(ev->ev_events & EV_TIMEOUT);
        printf("add timeout event\n");
    }
     
    //if pass, no other can handle this event 
    if((ev->ev_events & (EV_READ|EV_WRITE)) &&
       !(ev->ev_flags & (EV_INSERTED)))
    {
       event_queue_insert(ev, EV_INSERTED);
       Log :: NOTICE("EVENT fd:%d added IN LIST", ev->ev_fd); 
       
       if((ret = epoll_add_event(ev)) < 0)
           goto done;
        
       if(actived)
       {
           if((ret = epoll_active_event(ev)) < 0)
               goto done;
       }

       Log :: NOTICE("Reactor Add Event succ fd %d", ev->ev_fd);
       
       if((status & RA_THREAD) & (!set_event_unactive(ev)))
       {
           Log :: WARN("Add SUcc Set fail, set Event UnaCtive Error,\
                   status broken FD %d", ev->ev_fd);
       }
Пример #2
0
int
enqueue_msg(struct event_queue *eq, struct server_msg *msg)
/* global: parallel */
{
	int ret;

	/* fire thread to take care of this queue */
	if(event_queue_create_thread(eq, parallel) < 0)
		return(-1);

#if defined(IL_NOTIFICATIONS)
	/* if there are no data to send, do not send anything
	   (messsage was just to change the delivery address) */
	/* CORRECTION - let the message pass through the output queue
	   to commit it properly and keep event_store in sync */
	/* if(msg->len == 0)
		return(0);
	*/
#endif
	/* avoid losing signal to thread */
	event_queue_cond_lock(eq);

	/* insert new event */
	if((ret = event_queue_insert(eq, msg)) < 0) {
		event_queue_cond_unlock(eq);
		return ret;
	}

	/* signal thread that we have a new message */
	event_queue_signal(eq);

	/* allow thread to continue */
	event_queue_cond_unlock(eq);

	return ret;
}