0

in my program I add an event as below:

    conn_ev = (struct event *)malloc(sizeof(struct event));
    event_set(conn_ev, connfd, EV_READ, on_recv, conn_ev);
    event_base_set(base, conn_ev);
    if(event_add(conn_ev, NULL) == -1){
            fprintf(stderr, "event_add(conn_ev) error!\n");
            goto EXCEPTION;
    }

later, if another condition is satisfied, I need to delete all events that are related to connfd, is it possible to search events by socket number? and how to delete these events?

thanks!

misteryes
  • 2,167
  • 4
  • 32
  • 58

1 Answers1

1

You can't directly use fd to search for event, but you can do something like below:

          sock = event_get_fd(conn_ev);
          if (sock == sock_of_your_interest)
             event_del(conn_ev);
             free(conn_ev);

event_get_fd() returns the socket assigned, then check whether it's on you interest list, if yes delete the events and free up the allocated memory. You could easily left these memory allocation things to libevent by using event_new(),event_free(). Hope this will help.

rakib_
  • 136,911
  • 4
  • 20
  • 26