High-performance Windows Socket component HP-Socket v2.2.3 officially released

Source: Internet
Author: User

650) this. width = 650; "style =" max-width: 98%; "src =" http://www.bkjia.com/uploads/allimg/131228/204Z1D02-0.png "alt =" HP-Socket "width =" 225 "height =" 150 "/>

HP-Socket is a set of general high-performance Windows Socket component packages, including the IOCP model of the server component) and the Event Select model of the client component. It is widely used in TCP communication systems on Windows. HP-Socket fully encapsulates the communication layer, and upper-layer applications do not need to pay attention to any details of the communication layer. HP-Socket provides an API Interface Based on The Event Notification model, it can be easily and efficiently integrated into various applications. In addition, in order to make it easier for everyone to learn HP-Socket, we have carefully produced a function Test example Test Echo) A performance Test example Test Echo-PFM) and a PULL model Test example Test Echo-Pull). You can use these two Test examples to quickly master the design ideas and usage of components.

----------------------------------------------------------------

Versatility

  • The only responsibility of a communication component is to accept and send byte streams. It cannot participate in upper-layer protocol parsing;

  • Decoupled from upper-layer users and independent from each other, components interact with users through the operation interface and listener interface, and the component implementation operation interface provides the upper-layer operation method; the user registers himself as the Listener of the component through the Listener interface to receive notifications from the component. Therefore, any user can use components as long as the listener interface is implemented. On the other hand, you can even re-write a component implementation method that is completely different for the user to call, as long as the component complies with the operation interface of the component, this is also the embodiment of the DIP design principles.

Availability

Availability is crucial to all common components. If it is too difficult to use, it is easier to rewrite it. Therefore, the operation interface and listener interface of components are designed to be as simple and easy as possible. In other words, they are "silly". The main methods of these two interfaces are no more than five. In addition, the component completely encapsulates all the underlying Socket communication, and the upper-layer applications do not see any communication details and do not have to intervene in any communication operations. The Socket Connection is abstracted as the Connection ID, this parameter is used as a connection identifier for upper-layer applications to identify different connections.

High Performance

As a general component at the underlying layer, performance issues must be considered and cannot be a bottleneck of the system. On the other hand, different Socket models are used according to the performance requirements of client components and server components. Components fully consider factors such as performance, actual use cases, availability, and implementation complexity to ensure that the performance requirements are not too complex. Make the following two design decisions:

  • Client: Implement Socket communication interaction in a separate thread. This avoids interference with the main thread or other threads. Select the Event Select Communication Model for the I/O model.

  • Server: The IOCP communication model with the highest efficiency on the Windows platform is adopted. The cache pool technology usually requires frequent application and release of the memory buffer during communication and a dynamic cache pool is established, A new object is created only when there are no available objects in the cache pool, and when there are too many cached objects, the cache pool is compressed. In addition, the dynamic memory of the component is allocated through the Private Heap mechanism, avoid competition with new/malloc and reduce memory holes.

Scalability

You can set the performance parameters of the component according to the actual usage environment requirements, for example: the number of working threads, the size of various cache pools, the size of the sending and receiving buffer, the size of the Socket listening queue, the number of Accep distributions, and the interval of Heartbeat checks ).

(Project homepage: Click Here, click here)

* ** V2.2.3 update ***

> Change the data type of the connection ID to 'connid ':

-----------------

  1. Define the CONNID data type in SocketHelper. h. Default Value: typedef ULONG_PTR CONNID)

  2. Applications can define CONNID as the desired type, such as ULONG/ULONGLONG)

  3. To facilitate transplantation and maintenance, the connection ID should be referenced anywhere in the Application

> The Socket component on the server supports binding additional data to each connection:

-----------------

  1. IServerSocket and CIocpServer add method Get/SetConnectionExtra ()

  2. Through the above two methods, the application can bind any additional data for each connection and obtain the data

> Other updates:

-----------------

  1. Increase the maximum number of IOCP worker threads of CIocpServer by 64 to 500)

  2. The Disconnect () method of the Socket component of the server adds an identifier parameter 'bforce' to indicate whether to force Disconnect the connection.

  3. Adjust the connection ID generation rules to avoid generating a connection ID with a value of 0.

* ** V2.2.2 update ***

> Optimize the functions of Heartbeat Detection:

-----------------

  1. Change the Get/SetKeepAliveTimes () method of IServerSocket and IClientSocket TO Get/SetKeepAliveTime ()

  2. The default KeepAliveTime attribute of CIocpServer and CClientSocket is changed to 5000.

  3. The default KeepAliveInterval attribute of CIocpServer and CClientSocket is changed to 3000

* ** V2.2.1 update ***

> PULL model support:

-----------------

  1. Added the PULL model data receiving and notification method OnReceive (dwConnID, int) to the ISocketListener)

  2. Added the PULL Socket interface IPullSocket. The Fetch (dwConnID, pBuffer, iLength) method of this interface is used to capture communication data.

> Server:

-----------------

  1. The server Socket interface ISocketServer is renamed IServerSocket

  2. Added the PULL Server Socket listener abstract class CPullServerSocketListener.

  3. Added the PULL Server Socket interface IPullServerSocket

  4. Added the PULL Server Socket implementation class CIocpPullServer

> Client:

-----------------

  1. The client Socket interface ISocketClient is renamed IClientSocket

  2. The client Socket implementation class CSocketClient is renamed CClientSocket

  3. Added the PULL Client Socket listener abstract class CPullClientSocketListener.

  4. Added the PULL Client Socket interface IPullClientSocket.

  5. Added the PULL Client Socket implementation class CPullClientSocket

> Other updates:
-----------------

  1. Added the PULL Socket test program TestEcho-Pull.

  2. Add some help struct in SocketHelper. h (. cpp)

This article from the "Monster Garden" blog, please be sure to keep this source http://404201.blog.51cto.com/394201/1282370

Related Article

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.