Lightweight Network Library Libevent overview

Source: Internet
Author: User
Tags openssl library

Libevent is a library for writing fast portable nonblocking IO.

The libevent is designed to write a fast portable, non-blocking IO program.

Libevent components

The libevent includes the following components:

  1. evutil

Generic functionality to abstract out the differences between different platforms ' networking implementations.

Common functionality used to abstract different platform networks to achieve differences.

2. event & event_base

This is the heart of Libevent. It provides an abstract API to the various platform-specific, event-based nonblocking IO backends. It can-let-know when sockets is ready-to-read or write, do basic timeout functionality, and detect OS signals.

  The core of Libevent provides abstract APIs for various platform-specific, event-based, non-blocking io backend (backend, epoll, select, etc.) . They can notify the application that the socket is ready to read or write, has the basic function of processing timeouts, and is able to detect operating system signals.

3. bufferevent

These functions provide a more convenient wrapper around Libevent ' s event-based core. They let your application request buffered reads and writes, and rather than informing if sockets is ready for do, t Hey let's know when IO has actually occurred.

(The Bufferevent interface also have multiple backends, so that it can take advantage of systems that provide faster ways t o do nonblocking IO, such as the Windows IOCP API.)

The functions in Bufferevent provide a more convenient package for Libevent event-based cores. They enable our application to request read and write operations that have been buffered. In addition, they let us know that Io reads and writes have actually occurred, rather than notifying us when the socket is ready to read or write.

(TheBufferevent interface has multiple back-end, which can take a faster, non-blocking IO backend from the system , such as the IOCP API in Windows.) )

4. Evbuffer

This module implements the buffers underlying bufferevents, and provides functions for efficient and/or convenient access.

The buffering function is implemented under the Bufferevent layer and provides convenient and effective access functions.

5. evhttp

A Simple HTTP client/server implementation.

A simple HTTP client /server implementation.

6. Evdns

A Simple DNS client/server implementation.

A simple DNS client /server implementation.

7. Evrpc

A simple RPC implementation.

A simple RPC implementation.

Libevent Compiled libraries

1. Event_core

All core event and buffer functionality. This library is contains all the Event_base, Evbuffer, bufferevent, and utility functions.

The library contains all the core events and buffering functions, including all event_base, Evbuffer, Bufferevent, and auxiliary (utility) functions.

2. Event_extra

This library defines protocol-specific functionality the May or may not want for your application, including HTTP, DN S, and RPC.

The Library defines protocol-specific features that the program may or may not need, including HTTP, DNS, and RPC.

3. Event

This library exists for historical reasons; It contains the contents of both Libevent_core and Libevent_extra. You shouldn ' t use it; It may go away in a future version of Libevent.

This library exists for historical reasons, and it contains the contents of Libevent_core and Libevent_extra. We should not use this library. Future versions of Libevent may remove this library.

The following libraries may be installed on some platforms:

4. event_pthreads

This library is adds threading and locking implementations based on the Pthreads Portable Threading Library. It's separated from Libevent_core so, you don't need to the link against Pthreads to use libevent unless you're ACTU Ally using Libevent in a multithreaded.

The library adds thread and lock implementations that are based on Pthread portable line libraries. It is independent of Libevent_core, so the program does not need to link to pthread when using libevent, unless libevent is used in a multithreaded manner.

5. Event_openssl

This library provides support for encrypted communications using bufferevents and the OpenSSL library. It's separated from Libevent_core so, you don't need to the link against OpenSSL to use libevent unless you are Actua Lly using encrypted connections.

The library provides support for encrypted communications using bufferevent and OpenSSL. It is independent of Libevent_core, so the program does not need to link to OpenSSL when it uses libevent, except for encrypted communication.

Libevent header File

All Libevent headers is installed under the event2 directory. Headers fall into three broad classes:

The libevent common header files are installed in the Event2 directory. Header files can be roughly divided into three categories:

1. API Headers

An API header is one that defines the current public interfaces to Libevent. These headers has no special suffix.

Defines the libevent public interface. This type of header file does not have a specific suffix.

2. Compatibility Headers

A compatibility header includes definitions for deprecated functions. You shouldn ' t include it unless your ' re porting a program from a older version of Libevent.

Provides compatibility for deprecated functions. This type of header file should not be used except to fly a program that uses older versions of Libevent to migrate.

3. Structure Headers

These headers define structures with relatively volatile layouts. Some of these is exposed in case you need fast access to structure component; Some is exposed for historical reasons. Relying on all of the structures in headers directly can break your program's binary compatibility with other versions of Libevent, sometimes in hard-to-debug ways. These headers has the suffix "_struct.h"

Such header files define a variety of structures in a relatively unstable layout. Some of these structures are exposed to provide quick access, and some are exposed for historical reasons. Relying directly on any struct in such a header file will break the program's binary compatibility with other versions of Libevent. These problems sometimes occur in a way that is very difficult to debug. This type of header file has the suffix "_struct.h".

Compare new and old versions

Libevent 2.0 fixes the API in a more reasonable and error-prone manner. If possible, you should use Libevent 2.0 when writing a new program. However, there may be times when you need to use older APIs, such as when you upgrade an existing app, or if you support an environment where you cannot install 2.0 or update version libevent for some reason. Older versions of Libevent header files are less, and are not installed in the Event2 directory.

  

In 2.0 and later versions of Libevent, the old header file will still exist as the package for the new header file.
Other tips for using older versions:

    • Prior to version V1.4, there was only one library libevent, which contained all the features now scattered across Libevent_core and Libevent_extra.
    • Locks are not supported prior to version V2.0: libevent is thread-safe only if it is determined that the same struct is used in multiple threads at different time.

Resources

The Libevent Reference manual:preliminaries

Libevent Reference Manual: Preface

Lightweight Network Library Libevent overview

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.