An ICAP Connection Management Method, Apparatus, Electronic Device, and Storage Medium
By pre-creating an ICAP connection queue and setting it to an available state after receiving the response, multiplexing of TCP connections is solved, and the system resource consumption and response in a timely manner when the ICAP request data is large, and the transmission speed of ICAP requests is improved.
Patent Information
- Application Number
- CN202211458219.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-21
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2042-11-21
AI Technical Summary
When the ICAP requests a large amount of data, frequent TCP connection establishment and shutdown lead to serious system resource consumption, system response is not timely, and link network delay is serious.
Create an ICAP connection queue in advance, use the available connections in the queue to send request data, and set the connection to an available state after receiving the response, realizing the multiplexing of TCP connections and reducing the number of connection creation times.
By multiplexing the TCP connections of ICAP connections, the system resource consumption is reduced, the ICAP request sending speed is improved, and the system response is not timely.
Smart Images

Figure CN115834652B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data security technology. Specifically, it relates to an ICAP connection management method, device, electronic device, and storage medium. Background Art
[0002] The ICAP protocol and the HTTP protocol are similar in structure and usage, both being request / response protocols. The ICAP protocol also uses the TCP protocol as the bearer layer. For each TCP connection, that is, an ICAP connection, only one ICAP request can be sent at a time. Before the ICAP server returns an ICAP response, the ICAP client cannot send a new ICAP request on this connection. The sending frequency of ICAP requests on a single connection depends on the time-consuming of the ICAP server to process ICAP requests.
[0003] A simple way for an ICAP client to use an ICAP service is to create a new ICAP connection each time an ICAP request is sent and close the ICAP connection after receiving the ICAP response. However, when the amount of ICAP request data is very large, a large number of short-packet interactions will occur during the establishment and closing of a large number of TCP connections, occupying the system bandwidth and consuming the system's socket resources at the same time, resulting in problems such as untimely system response and serious link network delay. Summary of the Invention
[0004] The purpose of the embodiments of this application is to provide an ICAP connection management method, device, electronic device, and storage medium, which pre-creates multiple ICAP connections, realizes the reuse of TCP connections, reduces system resource consumption, improves the sending speed of ICAP requests, and solves the problems of untimely system response and serious system resource consumption in the existing methods.
[0005] The embodiments of this application provide an ICAP connection management method, which is applied to a client. The method includes:
[0006] After receiving request data, search for a pre-created ICAP connection queue to obtain an available ICAP connection;
[0007] Encapsulate the request data and send it to the ICAP server based on the ICAP connection;
[0008] After the ICAP server returns response data, set the ICAP connection to an available state.
[0009] In the above implementation process, by using the pre-created ICAP connection queue, multiple request data can be sent to the ICAP server simultaneously, improving the request traffic processing speed; by reusing the TCP connections of the ICAP connections, the number of TCP connection creations is reduced, thereby reducing the consumption of system resources, and solving the problems of untimely system response and serious consumption of system resources in the existing methods.
[0010] Further, before the step of finding the pre-created ICAP connection queue, the method further includes:
[0011] Initializing the ICAP connection queue;
[0012] Creating an initial number of ICAP connections based on the ICAP server information parameters, and binding each ICAP connection to a TCP connection. The ICAP connection has two flag bits, respectively representing the to-be-closed flag bit and the available flag bit of the ICAP connection;
[0013] Storing the connection handles of the ICAP connections sequentially into the ICAP connection queue.
[0014] In the above implementation process, multiple ICAP connections are pre-created, completely decoupling the ICAP client operations from the user operations, and pre-creating multiple TCP connections for the ICAP service, realizing the reuse of TCP connections.
[0015] Further, the encapsulating the request data and sending it to the ICAP server based on the ICAP connection includes:
[0016] Obtaining and occupying the connection handle of the ICAP connection with the available flag bit being 1 and the to-be-closed flag bit being 0;
[0017] Encapsulating the request data according to the ICAP protocol standard, and sending the request data to the ICAP server through the connection handle;
[0018] If the sending is successful, obtaining the response data returned by the ICAP server through the connection handle;
[0019] If the sending fails, resetting the ICAP connection.
[0020] In the above implementation process, after the ICAP server returns the response data, setting the ICAP connection to be available again realizes the reuse of TCP connections, while reducing the consumption of system resources and improving the ICAP request sending speed, and finally improving the network traffic processing speed of the network security product.
[0021] Further, the resetting the ICAP connection includes:
[0022] Close the TCP connection of the ICAP connection;
[0023] If the flag bit to be closed of the ICAP connection is 1, remove the ICAP connection and the corresponding connection handle;
[0024] If the flag bit to be closed of the ICAP connection is 0, generate a new TCP connection, bind the new TCP connection to the ICAP connection, and reset the available flag bit of the ICAP connection to 1 again.
[0025] In the above implementation process, resetting the ICAP connection means resetting the ICAP connection to an available state to achieve the reuse of TCP connections.
[0026] Further, the method further includes:
[0027] Periodically update the number of ICAP connections;
[0028] Periodically update the connection status of the ICAP connections.
[0029] In the above implementation process, update the ICAP connections periodically. At the beginning of each period, update the ICAP connection queue and update the connection status of the ICAP connections.
[0030] Further, the periodic update of the number of ICAP connections includes:
[0031] Obtain the number M1 of new ICAP connections;
[0032] If the M1 is less than the initial number M, traverse the ICAP connection queue in reverse order;
[0033] Set the flag bit to be closed of the ICAP connection from the Mth ICAP connection to the (M1 + 1)th ICAP connection to 1 and remove them from the ICAP connection queue in sequence. If the available flag bit of the ICAP connection is 0, skip the ICAP connection. If the available flag bit of the ICAP connection is 1, reset the ICAP connection;
[0034] If M1 is greater than M, generate (M1 - M) new ICAP connections and store the connection handles of the new ICAP connections at the end of the ICAP connection queue in sequence.
[0035] In the above implementation process, update the number of ICAP connections to meet the requirements.
[0036] Further, the periodic update of the connection status of the ICAP connections includes:
[0037] Sequentially traverse the ICAP connections in the ICAP connection queue;
[0038] If the available flag of the ICAP connection is 0 and the ICAP server information parameter changes, set the to-be-closed flag of the ICAP connection to 1;
[0039] If the available flag of the ICAP connection is 1, determine whether the TCP connection of the ICAP connection is normal. If it is not normal, reset the ICAP connection;
[0040] If the ICAP server information parameter changes, reset the ICAP connection.
[0041] In the above implementation process, update the connection status of the ICAP connection to available.
[0042] The embodiment of the present application further provides an ICAP connection management device, and the device includes:
[0043] An available connection acquisition module, configured to search a pre-created ICAP connection queue to obtain an available ICAP connection after receiving request data;
[0044] A request data processing module, configured to encapsulate the request data and send it to the ICAP server based on the ICAP connection;
[0045] A reset module, configured to set the ICAP connection to an available state after the ICAP server returns response data.
[0046] In the above implementation process, by using the pre-created ICAP connection queue, multiple request data can be sent to the ICAP server simultaneously, improving the request traffic processing speed; by reusing the TCP connection of the ICAP connection, the number of TCP connection creations is reduced, thereby reducing the consumption of system resources, and solving the problems of untimely system response and serious consumption of system resources in the existing methods.
[0047] The embodiment of the present application further provides an electronic device, and the electronic device includes a memory and a processor. The memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the ICAP connection management method described in any one of the above.
[0048] The embodiment of the present application further provides a readable storage medium, and computer program instructions are stored in the readable storage medium. When the computer program instructions are read and run by a processor, the ICAP connection management method described in any one of the above is executed. Description of the Drawings
[0049] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the accompanying drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0050] Figure 1 It is a flowchart of an ICAP connection management method provided by an embodiment of the present application;
[0051] Figure 2 It is a flowchart for initializing an ICAP connection queue provided by an embodiment of the present application;
[0052] Figure 3 It is a flowchart for processing request data provided by an embodiment of the present application;
[0053] Figure 4 It is a flowchart for resetting an ICAP connection provided by an embodiment of the present application;
[0054] Figure 5 It is a flowchart for updating an ICAP connection provided by an embodiment of the present application;
[0055] Figure 6 It is a flowchart for updating the number of ICAP connections provided by an embodiment of the present application;
[0056] Figure 7 It is a flowchart for updating the connection status of an ICAP connection provided by an embodiment of the present application;
[0057] Figure 8 It is a block diagram of the structure of a management device for CAP connections provided by an embodiment of the present application;
[0058] Figure 9 It is a block diagram of the structure of another ICAP connection management device provided by an embodiment of the present application;
[0059] Figure 10 It is a schematic diagram of the implementation structure for a client to manage ICAP connections provided by an embodiment of the present application.
[0060] Icon:
[0061] 100 - Available connection acquisition module; 110 - ICAP connection queue creation module; 200 - Request data processing module; 210 - Connection handle acquisition module; 220 - Encapsulation module; 230 - Response data acquisition module; 240 - Reset module; 241 - Connection closing module; 242 - Removal module; 243 - New connection generation module; 300 - Data reception module; 400 - ICAP connection update module; 410 - Connection number update module; 420 - Connection status update module. DETAILED DESCRIPTION
[0062] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0063] It should be noted that similar reference numerals and letters represent similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and should not be understood as indicating or implying relative importance.
[0064] Example 1
[0065] Please see Figure 1 , Figure 1 A flowchart of an ICAP connection management method provided in an embodiment of the present application. The method is applied to a client, specifically an ICAP client. Upon startup, the ICAP client pre-creates a set of ICAP connections and generates an ICAP connection queue. Upon receiving a request from a client, the client sequentially searches the ICAP connection queue for an available ICAP connection, then encapsulates the request according to the ICAP protocol standard and sends the encapsulated request to the ICAP server via the ICAP connection. After the ICAP server returns response data, the ICAP connection is set to available.
[0066] ICAP (Internet Content Adaptation Protocol) is a lightweight HTTP-based remote procedure call (RPC) protocol that clients can use to transmit HTTP-based content to ICAP servers for content operations.
[0067] The specific steps include:
[0068] Step S100: after receiving the request data, searching a pre-created ICAP connection queue to obtain an available ICAP connection;
[0069] Step S200: Encapsulate the request data and send it to the ICAP server based on the ICAP connection;
[0070] Step S300: After the ICAP server returns response data, the ICAP connection is set to an available state.
[0071] Specifically, after receiving the response data returned by the ICAP server, the response data is unsealed according to the ICAP protocol, the unsealed response data is sent to the client, and then the ICAP connection is set to an available state.
[0072] likeFigure 2 As shown, it is the flowchart for initializing the ICAP connection queue. Before step S100, the method further includes:
[0073] Step S111: Initialize the ICAP connection queue;
[0074] Read preset parameters and create an ICAP connection queue based on the preset parameters, where the preset parameters include the number M of ICAP connections, ICAP server information parameters, etc.
[0075] Step S112: Create an initial number of ICAP connections based on the ICAP server information parameters, and bind each ICAP connection to a TCP connection. The ICAP connection has two flag bits, respectively representing the to-be-closed flag bit and the available flag bit of the ICAP connection;
[0076] Step S113: Store the connection handles of the ICAP connections sequentially into the ICAP connection queue.
[0077] Read the information parameters of the ICAP server, create M ICAP connections respectively, bind each ICAP connection to a TCP connection. The ICAP connection has two flag bits, one flag bit represents the to-be-closed state of the ICAP connection, and the other flag bit represents the available state of the ICAP connection. Set the available state to 1, and then put the connection handles of the ICAP connections into the ICAP connection queue sequentially.
[0078] Support sending multiple request data to the ICAP server for processing simultaneously, improving the processing speed of the request traffic.
[0079] As Figure 3 shown, it is the flowchart for processing request data. Step S200 specifically includes the following steps:
[0080] Step S210: Obtain and occupy the connection handle of the ICAP connection whose available flag bit is 1 and to-be-closed flag bit is 0;
[0081] Sequentially search the ICAP connection queue to find the first ICAP connection whose available flag is 1 and to-be-closed flag is 0. Set the available flag of this ICAP connection to 0, and then return the connection handle of this ICAP connection; if no ICAP connection that meets the conditions is found, return empty, prompt that the acquisition fails, and prompt that the number of ICAP connections is not enough and preset parameters are required.
[0082] If the search fails, reset the ICAP connection and end the processing.
[0083] Step S220: Encapsulating the request data according to the ICAP protocol standard, and sending the request data to the ICAP server through the connection handle;
[0084] If the search is successful, the request data is encapsulated according to the ICAP protocol standard and sent to the ICAP server through the connection handle; if the sending fails, the ICAP connection is reset and the processing ends.
[0085] Step S230: If the sending is successful, the response data returned by the ICAP server is obtained through the connection handle;
[0086] If the sending is successful, the ICAP response returned by the ICAP server is obtained through the connection handle; if the ICAP response is still not obtained after the preset timeout period, the ICAP connection is reset and the processing ends.
[0087] Added a timeout guard mechanism to support dynamic updates of ICAP connection configurations.
[0088] If an ICAP response is obtained within a preset timeout period, the ICAP response is unsealed according to the ICAP protocol standard, and the response data is processed; finally, the connection handle of the ICAP connection is released.
[0089] The method for releasing the ICAP connection handle is: clearing the buffer area for sending request data and receiving response data of the ICAP connection, and then setting the available state of the ICAP connection handle to 1.
[0090] Step S240: If the sending fails, reset the ICAP connection.
[0091] like Figure 4 As shown in FIG. 1 , it is a flowchart of resetting an ICAP connection. For example, step S240 specifically includes the following steps:
[0092] Step S241: closing the TCP connection of the ICAP connection;
[0093] Step S242: If the pending close flag of the ICAP connection is 1, remove the ICAP connection and the corresponding connection handle;
[0094] Step S243: If the pending close flag of the ICAP connection is 0, a new TCP connection is generated, and the new TCP connection is bound to the ICAP connection, and the available flag of the ICAP connection is set to 1 again.
[0095] Specifically, close the TCP connection corresponding to the ICAP connection, and then check the flag bit to be closed; if the flag bit to be closed is 1, remove the data related to the ICAP connection and clear the connection handle of the ICAP connection; if the flag bit to be closed is set to 0, create a new TCP connection, bind the new TCP connection to the ICAP connection, and reset the available flag of the ICAP connection to 1.
[0096] By reusing the TCP connection of the ICAP connection, the number of TCP connection creations is reduced, thereby reducing the consumption of system resources.
[0097] As Figure 5 shown, it is the flowchart for updating the ICAP connection, which specifically includes the following steps:
[0098] Step S400: Periodically update the number of the ICAP connections;
[0099] Step S500: Periodically update the connection status of the ICAP connections.
[0100] The update of the ICAP connection is a periodic operation. At the beginning of each period, first read the number of ICAP connections in the configuration parameters from the ICAP parameter buffer, then update the ICAP connection queue according to the configuration parameters, and finally sequentially check the connection status of each ICAP connection.
[0101] As Figure 6 shown, it is the flowchart for updating the number of ICAP connections. Step S400 can specifically include the following steps:
[0102] Step S401: Obtain the number M1 of new ICAP connections;
[0103] If the number M1 of new ICAP connections is equal to the original number M of ICAP connections, no operation is performed.
[0104] Step S402: If M1 is less than the initial number M, traverse the ICAP connection queue in reverse order;
[0105] Step S403: Set the flag bit to be closed of the ICAP connections from the Mth ICAP connection to the (M1 + 1)th ICAP connection to 1 and sequentially remove them from the ICAP connection queue. If the available flag bit of the ICAP connection is 0, skip the ICAP connection; if the available flag bit of the ICAP connection is 1, reset the ICAP connection;
[0106] Step S404: If M1 is greater than M, generate (M1 - M) new ICAP connections, and sequentially store the connection handles of the new ICAP connections at the end of the ICAP connection queue.
[0107] As Figure 7As shown in the figure, it is a flowchart for updating the connection status of the ICAP connection. Checking the TCP connection status of the ICAP connection is to sequentially traverse the ICAP connections in the ICAP connection queue. Specifically, step S500 may include the following steps:
[0108] Step S501: Sequentially traverse the ICAP connections in the ICAP connection queue;
[0109] Step S502: If the available flag of the ICAP connection is 0 and the ICAP server information parameter changes, set the to-be-closed flag of the ICAP connection to 1;
[0110] The ICAP server information parameter refers to the information required for establishing a TCP connection, including but not limited to the ICAP server address, ICAP service port, etc.
[0111] Step S503: If the available flag of the ICAP connection is 1, determine whether the TCP connection of the ICAP connection is normal. If it is not normal, reset the ICAP connection;
[0112] Step S504: If the ICAP server information parameter changes, reset the ICAP connection.
[0113] As one of the implementation manners, this method can be applied to the traffic collection layer in a network security product in a multi-threaded running manner, realizing that multiple request traffic is sent to the ICAP server simultaneously to detect the request content. Specifically, it includes:
[0114] Step S11: The system starts, pre-configures ICAP parameters, including the number M of ICAP connections, the ICAP response waiting timeout T, initializes the ICAP client configuration, generates an ICAP connection queue and an ICAP connection update thread, and creates multiple request traffic processing threads;
[0115] Step S12: The system main thread collects request traffic from the network card and distributes it to multiple request traffic processing threads;
[0116] Step S13: The request traffic processing thread extracts the request content from the request traffic, obtains the connection handle from the ICAP connection queue, sends the request content through this connection handle, and then waits for the ICAP response regularly:
[0117] If the connection handle cannot be obtained, record the log, end the processing of the current request traffic, and continue to process the next request traffic;
[0118] If the request content sending fails, record the log, reset the ICAP connection, end the processing of the current request traffic, and continue to process the next request traffic;
[0119] After sending the request content, wait for time t and then read the ICAP response. If the response cannot be read, increment the wait count by 1. If the wait count t ≥ T, reset the ICAP connection, end the processing of the current request traffic, and continue to process the next request traffic. If the wait count t < T, continue to wait;
[0120] After reading the ICAP response, release the occupancy of the ICAP connection handle, process the ICAP response, end the processing of the current request traffic, and continue to process the next request traffic;
[0121] Step S14: The ICAP connection update thread periodically reads ICAP parameters, updates the ICAP connection queue, and updates each ICAP connection;
[0122] Step S15: Read the log and adjust the ICAP parameters according to the log.
[0123] As another implementation, this method can be applied to the traffic collection layer of network security products in a single-threaded manner to achieve parallel processing of multiple request traffic in a single thread. The specific steps are as follows:
[0124] Step S16: When the system starts, pre-configure the ICAP parameters, including the number of ICAP connections M, the ICAP response wait timeout T, initialize the ICAP client configuration, generate an ICAP connection queue and an ICAP connection update thread, and create a queue for the sent request traffic;
[0125] Step S17: The system main thread collects request traffic from the network card and extracts the request content; obtains the connection handle of the ICAP connection from the ICAP connection queue, sends the request content through this connection handle, and then combines the request content, the ICAP connection handle, and the request traffic collection time T1 and puts them into the queue of sent request traffic; finally, sequentially traverse each combination in the queue of sent request traffic to check for timeouts:
[0126] Timeout check: Obtain the ICAP response through the connection handle of the ICAP connection; if the ICAP response is obtained, process the ICAP response, determine whether it is necessary to block the corresponding request traffic, and perform the blocking action; if the ICAP response is not obtained, calculate the difference between the current time T2 and the request traffic collection time T1. If T2 - T1 ≥ T, remove this combination from the queue of sent request traffic, allow the request traffic to pass, release the occupancy of the connection handle, and reset the ICAP connection; if T2 - T1 < T, end the operation of the current combination;
[0127] Step S18: The ICAP connection update thread periodically reads ICAP parameters, updates the ICAP connection queue, and updates each ICAP connection;
[0128] Step S19: Read the log and adjust the ICAP parameters according to the log.
[0129] This method, aiming at the request / response characteristics of the ICAP protocol, manages the ICAP connections through the client, and realizes the simultaneous processing of multiple ICAP requests. This method pre-creates multiple ICAP connections, encapsulates all operations related to the ICAP protocol, and completely decouples the ICAP client operations from the user operations.
[0130] This method has a timeout guard mechanism, manages all ICAP connections in the form of a queue or a set, timely checks and updates the status of each ICAP connection, ensures that each ICAP connection is valid and available, and the user only uses the ICAP connection without perceiving the status change of the ICAP connection; at the same time, it supports both single-threaded systems and multi-threaded systems, and both single-threaded systems and multi-threaded systems can use this method to process multiple ICAP requests in parallel; it supports reusing a single TCP connection to process multiple ICAP requests, reduces system resource consumption, improves the sending speed of ICAP requests, and solves the problems of untimely system response and serious system resource consumption in the existing methods.
[0131] Embodiment 2
[0132] An embodiment of the present application provides an ICAP connection management device. As Figure 8 shown, it is a structural block diagram of the ICAP connection management device. The device includes but is not limited to:
[0133] An available connection acquisition module 100, configured to, after receiving request data, search a pre-created ICAP connection queue to obtain an available ICAP connection;
[0134] A request data processing module 200, configured to encapsulate the request data and send it to the ICAP server based on the ICAP connection;
[0135] A data receiving module 300, configured to, after the ICAP server returns response data, set the ICAP connection to an available state.
[0136] Here, after receiving the response data returned by the ICAP server, it is necessary to first process the response data (unseal the response data according to the ICAP protocol) and send it to the client, and then set the ICAP connection to an available state.
[0137] As Figure 9 shown, it is a structural block diagram of another ICAP connection management device, and further includes an ICAP connection queue creation module 110, specifically configured to:
[0138] Initialize the ICAP connection queue;
[0139] Create an initial number of ICAP connections based on the ICAP server information parameters, and bind each ICAP connection to a TCP connection. The ICAP connection has two flag bits, which respectively represent the to-be-closed flag bit and the available flag bit of the ICAP connection;
[0140] Store the connection handles of the ICAP connections sequentially in the ICAP connection queue.
[0141] The request data processing module 200 includes:
[0142] A connection handle acquisition module 210, which is used to acquire and occupy the connection handle of an ICAP connection whose available flag bit is 1 and to-be-closed flag bit is 0;
[0143] An encapsulation module 220, which is used to encapsulate the request data according to the ICAP protocol standard and send the request data to the ICAP server through the connection handle;
[0144] A response data acquisition module 230, which is used to, if the sending is successful, acquire the response data returned by the ICAP server through the connection handle;
[0145] A reset module 240, which is used to, if the sending fails, reset the ICAP connection.
[0146] Among them, the reset module 240 includes:
[0147] A connection closing module 241, which is used to close the TCP connection of the ICAP connection;
[0148] A removal module 242, which is used to remove the ICAP connection and the corresponding connection handle if the to-be-closed flag bit of the ICAP connection is 1;
[0149] A new connection generation module 243, which is used to, if the to-be-closed flag bit of the ICAP connection is 0, generate a new TCP connection, bind the new TCP connection to the ICAP connection, and reset the available flag bit of the ICAP connection to 1.
[0150] Such as Figure 10As shown in the figure, it is a schematic structural diagram of the client for managing ICAP connections. The latest ICAP parameters are read from the ICAP parameter buffer, and the ICAP connection is updated based on the ICAP parameters. Specifically, the device includes an ICAP connection update module 400, and the ICAP connection update module 400 specifically includes a connection number update module 410 and a connection status update module 420. Among them, the connection number update module 410 is used to periodically update the number of the ICAP connections, and the connection status update module 420 is used to periodically update the connection status of the ICAP connections. The specific update process has been described in detail in Embodiment 1 and will not be elaborated here.
[0151] By using the pre-created ICAP connection queue, multiple request data can be sent to the ICAP server simultaneously, improving the request traffic processing speed. By reusing the TCP connections of the ICAP connections, the number of TCP connection creations is reduced, thereby reducing the consumption of system resources, and solving the problems of untimely system response and serious consumption of system resources in the existing methods.
[0152] An embodiment of this application also provides an electronic device, which includes a memory and a processor. The memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the ICAP connection management method described in Embodiment 1.
[0153] An embodiment of this application also provides a readable storage medium, in which computer program instructions are stored. When the computer program instructions are read and run by a processor, the ICAP connection management method described in Embodiment 1 is executed.
[0154] In the several embodiments provided by this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are only illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of this application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order from that marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0155] In addition, each functional module in various embodiments of the present application may be integrated together to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.
[0156] If the above-mentioned function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0157] The above are only the embodiments of the present application and are not used to limit the protection scope of the present application. For those skilled in the art, the present application can have various changes and modifications. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numerals and letters indicate similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0158] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, and all of them should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0159] It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the existence of additional identical elements in the process, method, article or device comprising said element.
Claims
1. An ICAP connection management method, characterized in that, Applied to a client, the method includes: After receiving request data, look up a pre-created ICAP connection queue to obtain an available ICAP connection; Encapsulate the request data and send it to an ICAP server based on the ICAP connection; After the ICAP server returns response data, set the ICAP connection to an available state; The method further includes periodically updating the number of ICAP connections: Obtain the number M1 of new ICAP connections; If M1 is less than the initial number M, traverse the ICAP connection queue in reverse order; Set the closing flags of the ICAP connections from the Mth to the (M1 + 1)th ICAP connection to 1 and remove them from the ICAP connection queue in sequence. If the available flag of an ICAP connection is 0, skip the ICAP connection. If the available flag of an ICAP connection is 1, reset the ICAP connection; If M1 is greater than M, generate M1 - M new ICAP connections and store the connection handles of the new ICAP connections at the end of the ICAP connection queue in sequence.
2. The ICAP connection management method according to claim 1, wherein Before the step of looking up the pre-created ICAP connection queue, the method further includes: Initialize the ICAP connection queue; Create an initial number of ICAP connections based on ICAP server information parameters, and bind each ICAP connection to a TCP connection. The ICAP connection has two flag bits, representing the closing flag bit and the available flag bit of the ICAP connection respectively; Store the connection handles of the ICAP connections in order in the ICAP connection queue.
3. The ICAP connection management method according to claim 1, wherein The step of encapsulating the request data and sending it to an ICAP server based on the ICAP connection includes: Obtain and occupy the connection handle of an ICAP connection with an available flag of 1 and a closing flag of 0; Encapsulate the request data according to the ICAP protocol standard and send the request data to the ICAP server through the connection handle; If the sending is successful, obtain the response data returned by the ICAP server through the connection handle; If the sending fails, reset the ICAP connection.
4. The ICAP connection management method according to claim 3, wherein The step of resetting the ICAP connection includes: Close the TCP connection of the ICAP connection; If the closing flag bit of the ICAP connection is 1, remove the ICAP connection and the corresponding connection handle; If the closing flag bit of the ICAP connection is 0, generate a new TCP connection, bind the new TCP connection to the ICAP connection, and reset the available flag bit of the ICAP connection to 1 again.
5. The ICAP connection management method according to claim 1, wherein The method further includes: Periodically update the connection status of the ICAP connections.
6. The ICAP connection management method according to claim 5, wherein, The step of periodically updating the connection status of the ICAP connections includes: Traverse the ICAP connections in the ICAP connection queue in order; If the available flag of an ICAP connection is 0 and the ICAP server information parameters change, set the closing flag bit of the ICAP connection to 1; If the available flag bit of the ICAP connection is 1, determine whether the TCP connection of the ICAP connection is normal. If it is not normal, reset the ICAP connection; If the ICAP server information parameter changes, reset the ICAP connection.
7. An ICAP connection management device, characterized in that, The device includes: An available connection acquisition module, configured to, after receiving request data, search a pre-created ICAP connection queue to obtain an available ICAP connection; A request data processing module, configured to encapsulate the request data and send it to an ICAP server based on the ICAP connection; A reset module, configured to, after the ICAP server returns response data, set the ICAP connection to an available state; It further includes a connection number update module, configured to periodically update the number of ICAP connections. Specifically: Obtain the number M1 of new ICAP connections; If the M1 is less than the initial number M, traverse the ICAP connection queue in reverse order; Set the to-be-closed flag of the ICAP connection from the Mth ICAP connection to the (M1 + 1)th ICAP connection to 1 and remove them from the ICAP connection queue in sequence. If the available flag bit of the ICAP connection is 0, skip the ICAP connection. If the available flag bit of the ICAP connection is 1, reset the ICAP connection; If M1 is greater than M, generate M1 - M new ICAP connections and sequentially store the connection handles of the new ICAP connections at the end of the ICAP connection queue.
8. An electronic device, characterized in that, The electronic device includes a memory and a processor. The memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the ICAP connection management method according to any one of claims 1 to 6.
9. A readable storage medium, characterized in that, Computer program instructions are stored in the readable storage medium. When the computer program instructions are read and run by a processor, the ICAP connection management method according to any one of claims 1 to 6 is executed.