CN110012042B - Communication mode optimization method and electronic equipment - Google Patents

Communication mode optimization method and electronic equipment Download PDF

Info

Publication number
CN110012042B
CN110012042B CN201810011462.1A CN201810011462A CN110012042B CN 110012042 B CN110012042 B CN 110012042B CN 201810011462 A CN201810011462 A CN 201810011462A CN 110012042 B CN110012042 B CN 110012042B
Authority
CN
China
Prior art keywords
microkernel
message
client
machmessagesession
monitoring interface
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810011462.1A
Other languages
Chinese (zh)
Other versions
CN110012042A (en
Inventor
杨亮
陈少杰
张文明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Zhongtian Technology Consulting Co ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810011462.1A priority Critical patent/CN110012042B/en
Publication of CN110012042A publication Critical patent/CN110012042A/en
Application granted granted Critical
Publication of CN110012042B publication Critical patent/CN110012042B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/02Details
    • H04L12/16Arrangements for providing special services to substations
    • H04L12/18Arrangements for providing special services to substations for broadcast or conference, e.g. multicast
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources

Abstract

The invention discloses a communication mode optimization method and electronic equipment.A virtual service name is registered first, and a monitoring interface of a microkernel is established; sending the monitoring interface to a plurality of clients based on the acquisition requests of the plurality of clients, so that each client sends a respective connection request to the monitoring interface based on the monitoring interface; receiving respective connection requests sent by each client, correspondingly creating a microkernel message session example for each connection request by using a thread of a microkernel information server, generating connection response messages of each microkernel message session example, sending the connection response messages to the client corresponding to each connection request, detecting whether each microkernel message session example is valid, and deleting the invalid microkernel message session example.

Description

Communication mode optimization method and electronic equipment
Technical Field
The present application relates to the field of communications technologies, and in particular, to a method for optimizing a communication mode and an electronic device.
Background
Under the Mac OSX system, there are various methods for inter-process communication, such as CFMessagePort.
A CFMessagePort local port named "XXX" is created in process A by calling the CFMessagePort Createlocal API of the CoreFoundation framework under the OSX system (create local interface API), and then a CFMessagePort remote port, also named "XXX", is created in another process B by calling CFMessagePort CreateRemote. Process a and process B thus establish a communication connection through a port named "XXX".
However, the above method is suitable only for one-to-one communication method and is not suitable for one-to-many communication methods. If process a is a server and process B is a client, the CFMessagePort solution is not suitable if there are multiple clients communicating with a server.
Disclosure of Invention
The invention provides a communication mode optimization method and electronic equipment, which are used for solving or partially solving the technical problem that one-to-many communication cannot be realized under an OSX system at present.
In order to solve the above technical problem, the present invention provides a method for optimizing a communication method, where the method includes:
registering a virtual service name and establishing a monitoring interface of a microkernel;
sending the monitoring interface to a plurality of clients based on the acquisition requests of the plurality of clients, so that the plurality of clients send respective connection requests to the monitoring interface based on the monitoring interface;
receiving respective connection requests sent by the plurality of clients;
correspondingly creating a microkernel message session instance for each connection request by utilizing the thread of the microkernel information server, generating a connection response message of each microkernel message session instance and sending the connection response message to a client corresponding to each connection request;
and encapsulating communication messages communicated with the clients and sending the communication messages to the corresponding clients.
Preferably, the registering a virtual service name and creating a monitoring interface of the microkernel Mach includes:
and calling a bootstrap _ check _ in function of the OSX system, registering the character string corresponding to the virtual service name in the OSX system, and acquiring the monitoring interface.
Preferably, the receiving the respective connection requests sent by the multiple clients specifically includes:
and calling a macch _ msg system function by using a thread of the microkernel information server to receive a connection request from each client, wherein the connection request of each client carries a port name of each client.
Preferably, the correspondingly creating a microkernel message session instance for each connection request by using the thread of the microkernel information server specifically includes:
creating a MachMessageSession session instance for each connection request by calling an allocSession function of the microkernel information server;
calling a createFrom method of the MachMessageSession to initialize each MachMessageSession session instance, so that each MachMessageSession session instance comprises two parameters: port name of corresponding client, local port name.
Preferably, the generating a connection response message of each microkernel message session instance and sending the connection response message to the corresponding client includes:
and packaging the local port name of each MachMessageSession session instance into each connection response message, and sending the local port name to the port of the corresponding client.
Preferably, after the connection response message for generating each microkernel message session instance is sent to the corresponding client, the method further includes:
each MachMessageSession conversation instance is put into an m _ sessions list for management;
and reading all MachMessageSession in the m _ sessions list in the recvSessionMsg function so as to obtain the communication message sent by the corresponding client.
Preferably, each mach messagedata communication message includes three fields: the first field is a header field with the type of macchmsg _ header _ t, and the second field is an integer field with the name of payload size, which indicates the size of payload data to be transmitted, excluding the header structure, and payload data with the name of payload;
the packaging and sending of the communication message communicated with each client to the corresponding client specifically comprises:
the total amount totalSize of the data of each MachMessageData communication message is the sum of the structure size sizeof (MachMessageData) of MachMessageData and the size of payload data;
and judging whether the result of the AND operation of the total data amount totalSize and the numerical value 3 of each MachMessageData communication message is 3, if so, sending the communication message to the corresponding client.
The invention discloses an electronic device, comprising:
the registration module is used for registering a virtual service name and establishing a monitoring interface of the microkernel;
the sending module is used for sending the monitoring interface to a plurality of clients based on the acquisition requests of the clients, so that the clients send respective connection requests to the monitoring interface based on the monitoring interface;
a receiving module, configured to receive respective connection requests sent by the multiple clients;
the creating module is used for correspondingly creating a microkernel message session example for each connection request by utilizing the thread of the microkernel information server, generating a connection response message of each microkernel message session example and sending the connection response message to a client corresponding to each connection request;
and the detection module is used for detecting whether each microkernel message session instance is effective or not and then deleting the ineffective microkernel message session instances.
The invention discloses a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method.
The invention discloses a computer device, comprising a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor realizes the steps of the method when executing the program.
Through one or more technical schemes of the invention, the invention has the following beneficial effects or advantages:
the invention discloses a communication mode optimization method and electronic equipment, wherein the method comprises the following steps: registering a virtual service name and establishing a monitoring interface of a microkernel; the method comprises the steps that a monitoring interface is sent to a plurality of clients based on acquisition requests of the clients, so that the clients send respective connection requests to the monitoring interface based on the monitoring interface; and then receiving respective connection requests sent by a plurality of clients, correspondingly creating a microkernel message session example for each connection request by using the thread of the microkernel information server, generating connection response messages of each microkernel message session example, sending the connection response messages to the client corresponding to each connection request, detecting whether each microkernel message session example is valid, and then deleting the invalid microkernel message session example. Therefore, the monitoring interface is established by registering a virtual service name, and the microkernel message session instance is correspondingly established for each connection request by using the thread of the microkernel information server to communicate with the respective client, so that the communication in a one-to-many mode can be realized with a plurality of clients by using one monitoring interface.
Drawings
Fig. 1 is a diagram of an implementation process of a communication method optimization method according to an embodiment of the present invention;
fig. 2 is a schematic overall structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the present application more clearly understood by those skilled in the art to which the present application pertains, the following detailed description of the present application is made with reference to the accompanying drawings by way of specific embodiments.
In the embodiment of the invention, the Mach microkernel concept of the OSX system is adopted. A one-to-many mode is realized by registering a virtual service name in a Mach micro-kernel and establishing a monitoring interface of the micro-kernel, and communicating with a plurality of clients by utilizing the monitoring interface. In a specific implementation process, firstly, the monitoring interface is sent to a plurality of clients based on acquisition requests of the plurality of clients, so that the plurality of clients send respective connection requests to the monitoring interface based on the monitoring interface; then receiving respective connection requests sent by the plurality of clients, correspondingly creating a microkernel message session example for each connection request by using the thread of the microkernel information server, generating a connection response message of each microkernel message session example, and sending the connection response message to the corresponding client. Therefore, the monitoring interface is established by registering a virtual service name, and the microkernel message session instance is correspondingly established for each connection request by using the thread of the microkernel information server to communicate with the respective client, so that the communication in a one-to-many mode can be realized with a plurality of clients by using one monitoring interface.
Mach microkernels are described below.
The OSX system is based on the Mach microkernel, in which all communication is based on the Mach Message, i.e., the Mach Message. In the Mach message, the most important concept is the concept of a Mach port, i.e., a Mach port. In the OSX system, messages are transferred from one Mach port to another.
Therefore, according to the OSX feature, the inter-process communication is realized by sending the message to the Mach port of the process B through the Mach port of the process a. The bottom layer of the CFMessagePort of the OSX system depends on the Mach port. Therefore, the method is a method for realizing one-to-many interprocess communication based on the Mach port according to the self-defined service name. At the beginning of the communication process, the server only needs to register a virtual (i.e. any non-existent) service name, and the client can establish a connection. Thereby enabling interprocess communication.
In the process of transmitting and receiving the Mach message, in the OSX, the message is received and transmitted through the macch _ msg. The first parameter of the function is a pointer to the map _ MSG _ header _ t, which indicates a message to be transmitted or received, the second parameter indicates whether a message is to be received or transmitted, which indicates a message to be transmitted when the value is MACH _ SEND _ MSG, which indicates a message to be received when the value is MACH _ RCV _ MSG, the third parameter indicates the size of data to be transmitted, and the fourth parameter indicates the size of data to be received. In this case, the message is received and transmitted by using the map _ msg according to the above method, and therefore, the detailed description thereof is omitted.
The macchmsg header t structure, which is a very important structure, is relied upon for the transmission and reception of any Mach message. The msgh _ size of the structure indicates the size of data to be transmitted or received, and msgh _ remote _ port indicates a remote port to which the field value must be set when a message is transmitted; msgh _ local _ port denotes a local port, and this field value must be set when a message is received.
The technical scheme has the following names:
the MachMessageServer, which represents a server for Mach communication, is used for processing a connection request from a MachMessageClient client through a specific service name character, and creating a MachMessageSession object representing a connection with the MachMessageClient.
The MachMessageSession represents a session device generated by a MachMessageServer class, and when the MachMessageServer detects a connection request from a MachMessageClient, a MachMessageSession instance is created, and then data communication is performed between the MachMessageSession instance and the MachMessageClient. A one-to-many concept is implemented here. One MachMessageServer instance communicates with each MachMessageClient through the MachMessageSession instance by creating multiple MachMessageSession instances.
And the MachMessageClient represents a client of Mach communication, sends a connection request to the MachMessageServer through a specific service name character, waits for the response of the request from the MachMessageServer, establishes a communication channel with the MachMessageServer if the request passes, and fails if the request is rejected.
The structure of the MachMessageConnect is a message used for establishing a connection request and sent by the MachMessageClient to the MachMessageServer in the case. The first field in this message is the header field of type macchmsg _ header _ t (any Mach message must include the header structure of this macchmsg _ header _ t and a string named portName, which represents the local Mach port name of the MachMessageClient.
The structure of the MachMessageConnectResult is a result message sent by the MachMessageServer to the MachMessageClient in this case for answering the connection request. Also the first field is the header field of the macchmsg _ header _ t, an integer field named sessionId, and a string named portName, which represents the remote Mach port name with which the Mach messageclient communicates.
MachMessageData, which is used to encapsulate data to be sent by the upper layer. The structure contains three fields, the first of which is a header field of type macchmsg _ header _ t, one of which is an integer field named payloadSize, indicating the size of the payload data to be transmitted (excluding the header structure), and the payload data named payload. The structure has an alloc method for rapidly generating a MachMessageData instance. When transmitting mach messagedata using the machmsg, there is a particular importance that the result of the and operation of msgh _ size of the header with 3 must be equal to 0, i.e. header. If not, then the machjmsg will return an error for MACH _ SEND _ MSG _ TOO _ SMALL. In order to solve this problem, in the embodiment of the present invention, when determining, another determination method is selected, and when calculating totalSize of the total size of the MachMessageData data in the alloc method, the totalSize should be the size of the MachMessageData, i.e., sizeof (MachMessageData), plus the size of the payload data, i.e., pagesize, so that totalSize ═ sizeof (MachMessageData) + pagesize. According to the size restriction rule, totalSize ═ totalSize +3 & -3. For example, the size of payload data to be transmitted is 10 bytes, and the size of the mach messagedata structure is 29 bytes, the totalSize size is 39 bytes, the and operation with 3 results in 3, and the adjusted totalSize size is 40 bytes.
With the above description of the mach messageserver, the mach messagesession, and the mach messageclient, how to establish a connection and receive data with each other will be described below.
Referring to fig. 1, in the implementation process of the present invention, a method for optimizing a communication mode is disclosed, the method includes:
step 11, register a virtual service name, and create a monitoring interface of the microkernel.
In a specific implementation process, a bootstrap _ check _ in function of the OSX system is called, a character string corresponding to the virtual service name is registered in the OSX system, and the monitoring interface is obtained.
Further, the mach messageserver calls a bootstrap _ check _ in function of the OSX system, registers a character string with a service name of 'XXX' in the system, judges a return value of the function, if the return value of the function is 0, the registration service is successful, acquires a monitoring interface with a name of m _ listenPort, and proceeds to the following step 2). If the return value is not equal to 0, the registration service fails and the system is directly exited.
And step 12, sending the monitoring interface to a plurality of clients based on the acquisition requests of the plurality of clients, so that the plurality of clients send respective connection requests to the monitoring interface based on the monitoring interface.
And step 13, receiving respective connection requests sent by the plurality of clients.
Specifically, the embodiment of the invention calls the map _ msg system function by using the thread of the microkernel information server to receive the connection request from each client, wherein the connection request of each client carries the port name of each client.
And step 14, correspondingly creating a microkernel message session instance for each connection request by using the thread of the microkernel information server, generating a connection response message of each microkernel message session instance, and sending the connection response message to the client corresponding to each connection request.
In the specific implementation process, a respective MachMessageSession session instance is created for each connection request mainly by calling an allocSession function of a microkernel information server; then, a createFrom method of the MachMessageSession is called to initialize each MachMessageSession session instance, so that each MachMessageSession session instance comprises two parameters: port name of corresponding client, local port name.
Further, the local port name of each mach messagesession instance is encapsulated into each connection response message, and is sent to the port of the corresponding client.
As an optional implementation manner, after the connection response message for generating each microkernel message session instance is sent to the corresponding client, each mach messagesession instance is also put into the m _ sessions list for management. Then, when the server and the client are in formal communication, all the mach messagesessions in the m _ sessions list are read in the recvsensingmsg function, so as to obtain the communication message sent by the corresponding client.
As an alternative embodiment, when communicating with each client, the communication message communicating with each client is encapsulated and sent to the corresponding client.
In a specific implementation, each mach messagedata communication message includes three fields: the first field is a header field with the type of macchmsg _ header _ t, and the second field is an integer field with the name of payload size, which indicates the size of payload data to be transmitted, excluding the header structure, and payload data with the name of payload;
the packaging and sending of the communication message communicated with each client to the corresponding client specifically comprises: the total amount totalSize of the data of each MachMessageData communication message is the sum of the structure size sizeof (MachMessageData) of MachMessageData and the size of payload data; and judging whether the result of the AND operation of the total data amount totalSize and the numerical value 3 of each MachMessageData communication message is 3, if so, sending the communication message to the corresponding client. Specifically, the total amount totalSize of data in each mach messagedata communication message is determined by the following formula: totalSize ═ (totalSize +3) & -3. For example, if the payload data size to be transmitted is 10 bytes and the size of the MachMessageData structure is 29 bytes, the totalSize size is 39 bytes, the AND operation of 3 results in 3, and the adjusted totalSize size is 40 bytes.
And step 15, detecting whether each microkernel message session instance is effective or not, and then deleting the ineffective microkernel message session instances.
In a specific implementation process, calling a map _ PORT _ TYPE function to acquire a TYPE of a remote PORT m _ remotePort, and if the value of the TYPE is equal to MACH _ PORT _ TYPE _ DEAD _ NAME, indicating that the remote PORT is closed in a corresponding client, invalidating a corresponding MachMessageSession instance; the invalid mach messagesession instance is then deleted.
Specifically, after the mach messageclient establishes a connection with the mach messageserver, the mach messageserver creates a mach messagesession instance, so as to perform data communication with the Client. However, if the MachMessageSession is not checked for validity, the MachMessageServer will create more and more machmessagesessions as the number of connections increases, and a MachMessageSession will be invalid if the MachMessageClient corresponding to that MachMessageSession is closed or exited. Therefore, it is necessary to detect whether the mach messagesession is valid according to a certain mechanism, and if the Session becomes invalid, the Session needs to be removed from the m _ sessions list of the mach messageserver and released, otherwise, the mach messageserver resources are wasted. Similarly, the mach messageclient also needs to detect whether the mach messagesession corresponding to the mach messageclient is valid, and if the remote port of the Client is closed or deleted at the Server, the Client cannot communicate with the Server any more. The specific detection mechanism is as follows:
in the process of server-side detection, in the read method of the MACH messagesession, a map _ PORT _ TYPE function is called to obtain the TYPE of a remote PORT m _ remotePort, if the value of the TYPE is equal to MACH _ PORT _ TYPE _ DEAD _ NAME, it indicates that the remote PORT is closed in the corresponding MACH messageclient, and the Session is invalid. Then delete the session from the m _ sessions list of MachMessageServer
Correspondingly, in the process of detecting the client, the above-mentioned discussion is how to detect whether the machmessagesession is valid in the MachMessageServer, and if the machmessagesession is invalid, the session is deleted. The MachMessageClient also calls the map _ PORT _ TYPE function to obtain the TYPE of the remote PORT m _ remotePort, and if the TYPE is MACH _ PORT _ TYPE _ DEAD _ NAME, the remote PORT is closed in the corresponding MACH messagesession. At the moment, the MachMessageclient needs to reconnect with the server again
The above is a way for establishing each mach messagesession instance for each client to communicate with the corresponding client. For ease of explanation and explanation of the present invention, the following embodiments will be described in terms of establishing communication between an instance of a mach messagesession and a client.
1) Registering service name and creating Mach monitoring interface
Calling a bootstrap _ check _ in function of an OSX system, registering a character string with a service name XXX in the system, judging a return value of the function, if the return value of the function is 0, representing that the registration service is successful, acquiring a monitoring interface with a name of m _ listenPort, and entering the following step 2). If the return value is not equal to 0, the registration service fails and the system is directly exited.
2) Creating a thread loop for a MachMessageServer
And after the calling in the last step is successful, creating a thread to circularly process the connection request from the client, and receiving the message of the MachMessageClient corresponding to each MachMessageSession. In the thread loop, the connection request from the client is processed by calling the listenPortLoop function of the MachMessageServer, and the message from the client is received by recvSessionMsg
3) Processing connection requests by listenPortLoop
In order to prevent the function from blocking a thread loop by calling the macch _ msg system function to receive a connection request from a client, a timeout time of 1 millisecond is set when the function is called. If the return value of the function is MACH _ MSG _ SUCCESS, it indicates that a Mach message was successfully received. Then, whether the msgh _ id field in the map _ msg _ header _ t structure of the message structure is equal to the MMT _ CONNECT value or not is judged, and if yes, the message is a connection request message with the type of MachMessageConnect. Proceeding to the following step a)
a) Creating a MachMessageSession
A MachMessageSession instance is created by calling the allocSession function of the MachMessageServer and the createFrom method of the MachMessageSession is called to initialize the session, which has two particularly important parameters, one is remotePortName, which represents the port name of the MachMessageClient, and one is localPortName, which represents the local port name of the session. When sending a MachMessageConnect connection request message to a MachMessageServer, a client carries a portName string, which is a remotePortName parameter required by createFrom, and localPortName is represented by generating a random GUID string. Inside the createFrom function, the remote port represented by remotePortName is obtained by calling bootstrap _ look _ up, labeled m _ remotePort, and a local port, labeled m _ localPort, is created by calling bootstrap _ check _ in. After completion, the MachMessageSession may send a message to the m _ remotePort and receive the message from the MachMessageClient through the m _ localPort.
b) Returning a connection request result message to the client
After createFrom in the above step is completed, a mach messagesession is successfully created to communicate with the mach messageclient. At this time, a message for connecting the messagemessageconnectioncorresult, which contains the localeportname string created in step a), must be sent to the mach messageclient. The MachMessageClient sends a message to the MachMessageSession through the port corresponding to the localPortName.
c) And putting the created MachMessageSession into an m _ sessions list for management.
4) recvSessionMsg receives client messages
And reading all MachMessageSession in the m _ sessions list in the recvSessionMsg function, namely calling a read method of the MachMessageSession to acquire the communication message from the MachMessageClient.
5) Read method of MachMessageSession
Calling the macmsg to receive the message from the Client corresponding to the session, and setting the m _ local port in the msgh _ local _ port field in the macmsg _ header _ t structure on the method calling the function. And because the function is called in the message loop thread of the MachMessageServer, the thread cannot be blocked, so in calling the machMessageServer, a timeout time needs to be set, if timeout occurs, the function returns, otherwise, the function waits for the next time. The timeout time set in the scheme is 1 millisecond.
6) In the read method of the MACH messagesession, the map _ PORT _ TYPE function is called first to obtain the TYPE of the remote PORT m _ remotePort, and if the value of the TYPE is equal to MACH _ PORT _ TYPE _ DEAD _ NAME, it means that the remote PORT has been closed in its corresponding MACH messageclient, and the Session has been invalid. Then delete the session from the m _ sessions list of MachMessageServer
Client logic of MachMessageClient
The above describes how the mach messageserver listens for a connection request from the mach messageclient, creates a corresponding mach messagesession for data communication with the mach messageclient, and sends a mach messageconnectresult connection result message to the Client. The following mainly describes the main steps of MachMessageClient initiating connection request to Server
1) Obtaining service name port registered by MachMessageServer
Acquiring a monitoring interface with name XXX registered by the Server end by calling a bootstrap _ look _ up function, and if the return value of the function is equal to 0, entering the following step 2)
2) Creating a random guid string and creating a Mach Port through the string
And creating a random guid character string, calling bootstrap _ check _ in to acquire a port corresponding to the guid character end, and receiving the message by the Client depending on the port.
3) Sending a MachMessageConnect connection request message
Filling the guid character string in the step 2) into a portName field of the MachMessageConnect, and calling a macch _ msg function to send a connection request message to the Server.
4) Waiting for a connection request result
After the MachMessageConnect message is sent out, the machMessageConnectResult connection result message from the Server is received by calling the macch _ msg function. And then acquiring a portName field in a MachMessageConnectResult structure, and calling a bootstrap _ loop _ up function to acquire a remote Mach port corresponding to the portName, so that the Client can send a message to the MachMessageSession through the port.
5) Data transmission
After the step 4) is successful, the data transmission operation with the MachMessageServer can be carried out. The data payload to be sent and the size of the data payload size to be sent are transferred into the alloc method by calling the alloc method of the MachMessageData, and a MachMessageData instance is returned. And sets msgh _ remote _ port in the header field in the structure to m _ remotePort acquired in step 4), and then sends the data out by using the macro _ msg function.
6) Data reception
Step 4) is successful, a thread is created, the calling macchjmsg circulating in the thread receives the message from the server, and the m _ local _ port is set to the msgh _ local _ port field in the macchjmsg _ header _ t structure on the method calling the function.
7) In the MachMessageClient, the map _ PORT _ TYPE function is called to obtain the TYPE of the remote PORT m _ remotePort, and if the TYPE is MACH _ PORT _ TYPE _ DEAD _ NAME, the remote PORT is closed in the corresponding MachMessageSession. At this point the MachMessageClient needs to reconnect to the server.
By introducing the connection request and response to the MachMessageServer and the MachMessageclient, the method for performing one-to-many interprocess communication by using the Mach port is realized. When the communication process starts, the server only needs to register an arbitrary non-existent service name, and each client can establish connection. Thereby enabling interprocess communication. In addition, in the embodiment of the invention, MachMessageData is used for carrying out load data transmission between the Server and the Client, in addition, a new detection mechanism is also established, and whether the connection between the Server and the Client is effective is obtained by using the connection detection mechanism, thereby reducing the waste of system resources.
Based on the same inventive concept, the embodiment of the present invention further discloses an electronic device, referring to fig. 2, including:
the registration module 21 is configured to register a virtual service name and create a monitoring interface of the microkernel;
a sending module 22, configured to send the monitoring interface to multiple clients based on acquisition requests of the multiple clients, so that the multiple clients send respective connection requests to the monitoring interface based on the monitoring interface;
a receiving module 23, configured to receive respective connection requests sent by the multiple clients;
a creating module 24, configured to correspondingly create a microkernel message session instance for each connection request by using a thread of the microkernel information server, generate a connection response message of each microkernel message session instance, and send the connection response message to a client corresponding to each connection request;
a detecting module 25, configured to detect whether each microkernel message session instance is valid, and then delete the invalid microkernel message session instance.
Based on the same inventive concept as in the previous embodiments, the present invention also provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the steps of any of the methods described above.
Based on the same inventive concept as in the previous embodiments, the present invention also provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of any of the methods described above when executing the program.
Through one or more embodiments of the present invention, the present invention has the following advantageous effects or advantages:
the invention discloses a communication mode optimization method and electronic equipment.A virtual service name is registered first, and a monitoring interface of a microkernel is established; the method comprises the steps that a monitoring interface is sent to a plurality of clients based on acquisition requests of the clients, so that the clients send respective connection requests to the monitoring interface based on the monitoring interface; and then receiving respective connection requests sent by a plurality of clients, correspondingly creating a microkernel message session example for each connection request by using the thread of the microkernel information server, generating connection response messages of each microkernel message session example, sending the connection response messages to the client corresponding to each connection request, detecting whether each microkernel message session example is effective or not, and then deleting the ineffective microkernel message session example. Therefore, the monitoring interface is established by registering a virtual service name, and the microkernel message session instance is correspondingly established for each connection request by using the thread of the microkernel information server to communicate with the respective client, so that the communication in a one-to-many mode can be realized with a plurality of clients by using one monitoring interface.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (8)

1. A method for optimizing a communication system, the method comprising:
registering a virtual service name in the Mach microkernel, and establishing a monitoring interface of the microkernel;
sending the monitoring interface to a plurality of clients based on the acquisition requests of the plurality of clients, so that the plurality of clients send respective connection requests to the monitoring interface based on the monitoring interface;
receiving respective connection requests sent by the plurality of clients;
correspondingly creating a microkernel message session instance for each connection request by utilizing the thread of the microkernel information server, generating a connection response message of each microkernel message session instance and sending the connection response message to a client corresponding to each connection request;
detecting whether each microkernel message session instance is effective or not, and then deleting the ineffective microkernel message session instances;
the correspondingly creating a microkernel message session instance for each connection request by using the thread of the microkernel information server specifically comprises:
creating a MachMessageSession session instance for each connection request by calling an allocSession function of the microkernel information server;
calling a createFrom method of the MachMessageSession to initialize each MachMessageSession session instance, so that each MachMessageSession session instance comprises two parameters: port name, local port name of the corresponding client;
the step of sending the connection response message for generating each microkernel message session instance to the client corresponding to each connection request includes:
and packaging the local port name of each MachMessageSession session instance into each connection response message, and sending the local port name to the port of the corresponding client.
2. The method of claim 1, wherein registering a virtual service name and creating a monitoring interface for a microkernel Mach comprises:
and calling a bootstrap _ check _ in function of the OSX system, registering the character string corresponding to the virtual service name in the OSX system, and acquiring the monitoring interface.
3. The method of claim 1, wherein the receiving the respective connection requests sent by the plurality of clients specifically comprises:
and calling a macch _ msg system function by using a thread of the microkernel information server to receive a connection request from each client, wherein the connection request of each client carries a port name of each client.
4. The method of claim 1, wherein after the generating of the connection reply message for each microkernel message session instance is sent to the corresponding client, the method further comprises:
each MachMessageSession conversation instance is put into an m _ sessions list for management;
and reading all MachMessageSession in the m _ sessions list in the recvSessionMsg function so as to obtain the communication message sent by the corresponding client.
5. The method according to claim 1, wherein said detecting whether each microkernel message session instance is valid and then deleting the invalid microkernel message session instances comprises:
calling a map _ PORT _ TYPE function to acquire a TYPE of a remote PORT m _ remotePort, and if the value of the TYPE is equal to MACH _ PORT _ TYPE _ DEAD _ NAME, indicating that the remote PORT is closed in a corresponding client, and the corresponding MachMessageSession instance is invalid; the invalid mach messagesession instance is then deleted.
6. An electronic device, comprising:
the registration module is used for registering a virtual service name in the Mach microkernel and establishing a monitoring interface of the microkernel;
the sending module is used for sending the monitoring interface to a plurality of clients based on the acquisition requests of the clients, so that the clients send respective connection requests to the monitoring interface based on the monitoring interface;
a receiving module, configured to receive respective connection requests sent by the multiple clients;
the creating module is used for correspondingly creating a microkernel message session example for each connection request by utilizing the thread of the microkernel information server, generating a connection response message of each microkernel message session example and sending the connection response message to a client corresponding to each connection request;
the detection module is used for detecting whether each microkernel message session instance is effective or not and then deleting the ineffective microkernel message session instances;
the correspondingly creating a microkernel message session instance for each connection request by using the thread of the microkernel information server specifically comprises:
creating a MachMessageSession session instance for each connection request by calling an allocSession function of the microkernel information server;
calling a createFrom method of the MachMessageSession to initialize each MachMessageSession session instance, so that each MachMessageSession session instance comprises two parameters: port name, local port name of the corresponding client;
the step of sending the connection response message for generating each microkernel message session instance to the client corresponding to each connection request includes:
and packaging the local port name of each MachMessageSession session instance into each connection response message, and sending the local port name to the port of the corresponding client.
7. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 5.
8. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method according to any of claims 1-5 are implemented when the program is executed by the processor.
CN201810011462.1A 2018-01-05 2018-01-05 Communication mode optimization method and electronic equipment Active CN110012042B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810011462.1A CN110012042B (en) 2018-01-05 2018-01-05 Communication mode optimization method and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810011462.1A CN110012042B (en) 2018-01-05 2018-01-05 Communication mode optimization method and electronic equipment

Publications (2)

Publication Number Publication Date
CN110012042A CN110012042A (en) 2019-07-12
CN110012042B true CN110012042B (en) 2022-01-04

Family

ID=67164613

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810011462.1A Active CN110012042B (en) 2018-01-05 2018-01-05 Communication mode optimization method and electronic equipment

Country Status (1)

Country Link
CN (1) CN110012042B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101262487A (en) * 2008-04-25 2008-09-10 北京中企开源信息技术有限公司 Data transmission processing method and device for point-to-point client
CN103414885A (en) * 2013-08-22 2013-11-27 济南中维世纪科技有限公司 Communication method of network audio-video monitoring system
CN106850698A (en) * 2017-04-06 2017-06-13 广东浪潮大数据研究有限公司 A kind of User space RPC agreement multithreading optimization methods and system
CN107147543A (en) * 2017-04-19 2017-09-08 武汉票据交易中心有限公司 A kind of socket communication means of server towards pc client
CN107193854A (en) * 2016-03-14 2017-09-22 商业对象软件有限公司 Uniform client for distributed processing platform

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9609058B2 (en) * 2014-10-13 2017-03-28 Commvault Systems, Inc. Storage management operations based on executable files served on demand to storage management components

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101262487A (en) * 2008-04-25 2008-09-10 北京中企开源信息技术有限公司 Data transmission processing method and device for point-to-point client
CN103414885A (en) * 2013-08-22 2013-11-27 济南中维世纪科技有限公司 Communication method of network audio-video monitoring system
CN107193854A (en) * 2016-03-14 2017-09-22 商业对象软件有限公司 Uniform client for distributed processing platform
CN106850698A (en) * 2017-04-06 2017-06-13 广东浪潮大数据研究有限公司 A kind of User space RPC agreement multithreading optimization methods and system
CN107147543A (en) * 2017-04-19 2017-09-08 武汉票据交易中心有限公司 A kind of socket communication means of server towards pc client

Also Published As

Publication number Publication date
CN110012042A (en) 2019-07-12

Similar Documents

Publication Publication Date Title
CN107948324B (en) Request Transmission system, method, apparatus and storage medium
CN114124451B (en) Data processing method and system for Internet of things equipment and computer storage medium
US20170054640A1 (en) Device and method for establishing connection in load-balancing system
CN109815025B (en) Service model calling method, device and storage medium
US20040186918A1 (en) Method and apparatus for dispatching incoming data in a multi-application terminal
WO2014182694A1 (en) Device triggering
US11916740B2 (en) K8S-based service deployment method and apparatus, device, and medium
CN108494623A (en) A kind of performance test methods and equipment of network forwarding equipment
CN109857572B (en) Method, device and equipment for realizing remote calling and computer readable storage medium
CN112596931A (en) Cross-process communication method and device, electronic equipment and storage medium
CN106357654B (en) Remote procedure calling method, device and communication system
CN109388388B (en) Information interaction method, device, equipment and storage medium between function modules
CN110008033B (en) Method for communicating with client and electronic equipment
US20230421663A1 (en) Efficient resource representation exchange between service layers
CN110012042B (en) Communication mode optimization method and electronic equipment
CN110008032B (en) Communication mode realization method and electronic equipment
CN106919550B (en) Semantic verification method and device
CN116192985B (en) Data transmission method, device and system
CN114553956B (en) Data transmission method and system based on unified extensible firmware protocol (UEP) middleware
CN114679436B (en) Session management method, server and computer readable storage medium
CN115361348A (en) Method for communicating with web browser performed by data acquisition device
CN113992740A (en) Middleware based on autonomous control and data transmission method
US10623523B2 (en) Distributed communication and task handling to facilitate operations of application system
CN113489775A (en) VPP-based seven-layer load balancing server and load balancing method
CN114189384B (en) Service processing method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20240201

Address after: Room 101-1, Building 2, No. 95 Daguan Middle Road, Tianhe District, Guangzhou City, Guangdong Province, 510000

Patentee after: Guangzhou Zhongtian Technology Consulting Co.,Ltd.

Country or region after: China

Address before: 430000 East Lake Development Zone, Wuhan City, Hubei Province, No. 1 Software Park East Road 4.1 Phase B1 Building 11 Building

Patentee before: WUHAN DOUYU NETWORK TECHNOLOGY Co.,Ltd.

Country or region before: China

TR01 Transfer of patent right