libevent 学习

libevent 学习一 主要结构体

主要结构体

struct event_base{
/** Function pointers and other data to describe this event_base's
 * backend. */
**const struct eventop *evsel;**
/** Pointer to backend-specific data. */
**void *evbase;**
/** List of changes to tell backend about at next dispatch.  Only used
 * by the O(1) backends. */
struct event_changelist changelist;

/** Function pointers used to describe the backend that this event_base
 * uses for signals */
const struct eventop *evsigsel;
/** Data to implement the common signal handelr code. */
struct evsig_info sig;

/** Number of virtual events */
int virtual_event_count;
/** Number of total events added to this event_base */
int event_count;
/** Number of total events active in this event_base */
int event_count_active;

/** Set if we should terminate the loop once we're done processing
 * events. */
int event_gotterm;
/** Set if we should terminate the loop immediately */
int event_break;
/** Set if we should start a new instance of the loop immediately. */
int event_continue;

/** The currently running priority of events */
int event_running_priority;

/** Set if we're running the event_base_loop function, to prevent
 * reentrant invocation. */
int running_loop;

/* Active event management. */
/** An array of nactivequeues queues for active events (ones that
 * have triggered, and whose callbacks need to be called).  Low
 * priority numbers are more important, and stall higher ones.
 */
struct event_list *activequeues;
/** The length of the activequeues array */
int nactivequeues;

/* common timeout logic */

/** An array of common_timeout_list* for all of the common timeout
 * values we know. */
struct common_timeout_list **common_timeout_queues;
/** The number of entries used in common_timeout_queues */
int n_common_timeouts;
/** The total size of common_timeout_queues. */
int n_common_timeouts_allocated;

/** List of defered_cb that are active.  We run these after the active
 * events. */
struct deferred_cb_queue defer_queue;

/** Mapping from file descriptors to enabled (added) events */
struct event_io_map io;

/** Mapping from signal numbers to enabled (added) events. */
struct event_signal_map sigmap;

/** All events that have been enabled (added) in this event_base */
struct event_list eventqueue;

/** Stored timeval; used to detect when time is running backwards. */
struct timeval event_tv;

/** Priority queue of events with timeouts. */
struct min_heap timeheap;

/** Stored timeval: used to avoid calling gettimeofday/clock_gettime
 * too often. */
struct timeval tv_cache;

#if defined(_EVENT_HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
/** Difference between internal time (maybe from clock_gettime) and
 * gettimeofday. */
struct timeval tv_clock_diff;
/** Second in which we last updated tv_clock_diff, in monotonic time. */
time_t last_updated_clock_diff;
#endif

#ifndef _EVENT_DISABLE_THREAD_SUPPORT
/* threading support */
/** The thread currently running the event_loop for this base */
unsigned long th_owner_id;
/** A lock to prevent conflicting accesses to this event_base */
void *th_base_lock;
/** The event whose callback is executing right now */
struct event *current_event;
/** A condition that gets signalled when we're done processing an
 * event with waiters on it. */
void *current_event_cond;
/** Number of threads blocking on current_event_cond. */
int current_event_waiters;
#endif

#ifdef WIN32
/** IOCP support structure, if IOCP is enabled. */
struct event_iocp_port *iocp;
#endif

/** Flags that this base was configured with */
enum event_base_config_flag flags;

/* Notify main thread to wake up break, etc. */
/** True if the base already has a pending notify, and we don't need
 * to add any more. */
int is_notify_pending;
/** A socketpair used by some th_notify functions to wake up the main
 * thread. */
evutil_socket_t th_notify_fd[2];
/** An event used by some th_notify functions to wake up the main
 * thread. */
struct event th_notify;
/** A function used to wake up the main thread from another thread. */
int (*th_notify_fn)(struct event_base *base);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值