Lievent Source Analysis: Evbuffer

Source: Internet
Author: User

The struct evbuffer is defined in the Evbuffer-internal.h file.

The Evbuffer structure holds a linked list with evbuffer-chain structure as a node, and there are two pointers within the evbuffer that point to the end and end nodes respectively.

1 structEvbuffer {2     /** The first chain in this buffer ' s linked list of chains.*/3     structEvbuffer_chain *First ;4     /** The last chain in this buffer ' s linked list of chains.*/5     structEvbuffer_chain *Last ;6 7     /** Pointer to the next Pointer pointing at the ' Last_with_data ' chain.8      *9 * to unpack:Ten      * One * The Last_with_data chain is the last chain of that have any data in it. A * If All chains in the buffer was empty, it is the first chain. - * If The buffer has no chains, it is NULL. -      * the * The Last_with_datap pointer points at _whatever ' Next ' pointer_ - * points at the Last_with_datap chain. If the Last_with_data chain - * is the first chain, or it was NULL, then the Last_with_datap pointer - * is &buf->first. +      */ -     structEvbuffer_chain * *Last_with_datap; +  A     /** Total amount of bytes stored in all chains.*/ at size_t Total_len; -  -     /** Number of bytes We have added to the buffer since we last tried to - * Invoke callbacks.*/ - size_t N_ADD_FOR_CB; -     /** Number of bytes we have removed from the buffer since we last in * tried to invoke callbacks.*/ - size_t N_DEL_FOR_CB; to  + #ifndef Event__disable_thread_support -     /** A lock used to mediate access to this buffer.*/ the     void*Lock; * #endif $     /** True iff we should free the lock field if we free thisPanax Notoginseng * Evbuffer.*/ -Unsigned own_lock:1; the     /** True iff we should not allow changes to the front of the buffer + * (drains or prepends).*/ AUnsigned freeze_start:1; the     /** True iff we should not allow changes to the end of the buffer + * (appends)*/ -Unsigned freeze_end:1; $     /** True iff this evbuffer ' s callbacks is not invoked immediately $ * Upon a change in the buffer, but instead is deferred to be invoked - * from the Event_base ' s loop. Useful for preventing enormous stack - * Overflows when we had mutually recursive callbacks, and for the * Serializing callbacks in a single thread.*/ -Unsigned Deferred_cbs:1;Wuyi #ifdef _WIN32 the     /** True iff this buffer is set to overlapped IO.*/ -Unsigned is_overlapped:1; Wu #endif -     /** Zero or more evbuffer_flag_* bits*/ About ev_uint32_t flags; $  -     /** Used to implement deferred callbacks.*/ -     structEvent_base *Cb_queue; -  A     /** A reference count on this evbuffer. When the reference count + * reaches 0, the buffer is destroyed. Manipulated with the * Evbuffer_incref and Evbuffer_decref_and_unlock and - * Evbuffer_free.*/ $     intrefcnt; the  the     /** A struct event_callback handle to make all of the this buffer ' s callbacks the * Invoked from the event loop.*/ the     structEvent_callback deferred; -  in     /** A Doubly-linked-list of callback functions*/ the List_head (Evbuffer_cb_queue, Evbuffer_cb_entry) callbacks; the  About     /** The parent Bufferevent object this evbuffer belongs to. the * NULL If the evbuffer stands alone.*/ the     structBufferevent *parent; the};

struct Evbuffer_chain:

Inside the evbuffer-chain structure, a variable that represents the length of the buffer content and a pointer to a char* point to the location of the buffer content.

1 /** A Single item in an Evbuffer.*/2 structEvbuffer_chain {3     /** points to next buffer in the chain*/4     structEvbuffer_chain *Next;5 6     /** Total allocation available in the buffer field.*/7 size_t Buffer_len;8 9     /** Unused space at the beginning of buffer or an offset into aTen * file for sendfile buffers.*/ One ev_misalign_t misalign; A  -     /** Offset into buffer + misalign at which to start writing. - * In other words, the total number of bytes actually stored the * in buffer.*/ - size_t off; -  -     /** Set If special handling is required for this chain*/ + unsigned flags; - #defineEvbuffer_filesegment 0x0001/**< A chain used for A file segment */ + #defineEvbuffer_sendfile 0x0002/**< A chain used with SENDFILE */ A #defineEvbuffer_reference 0x0004/**< A chain with a mem REFERENCE */ at #defineEvbuffer_immutable 0x0008/**< read-only Chain * * -     /** A chain that mustn ' t is reallocated or freed, or has its contents - * memmoved, until the chain is un-pinned.*/ - #defineEvbuffer_mem_pinned_r 0x0010 - #defineEvbuffer_mem_pinned_w 0x0020 - #defineEvbuffer_mem_pinned_any (evbuffer_mem_pinned_r| EVBUFFER_MEM_PINNED_W) in     /** A chain that should being freed, but can ' t be freed until it 's - * un-pinned.*/ to #defineEvbuffer_dangling 0x0040 +     /** A chain that is a referenced copy of another chain*/ - #defineEvbuffer_multicast 0x0080 the  *     /** Number of references to this chain*/ $     intrefcnt;Panax Notoginseng  -     /** Usually points to the read-write memory belonging to this the * Buffer Allocated as part of the Evbuffer_chain allocation. + * For Mmap, the can be a read-only buffer and A * Evbuffer_immutable'll is set in flags. For Sendfile, it the * May point to NULL. +      */ -UnsignedChar*buffer; $ }; $  - /** Callback for a reference chain, lets us know what-if - * we ' re do with it. Lives at the end of a evbuffer_chain with the the * Evbuffer_reference flag set*/ - structEvbuffer_chain_reference {Wuyi EVBUFFER_REF_CLEANUP_CB CLEANUPFN; the     void*Extra; -};

Lievent Source Analysis: Evbuffer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.