xref: /aosp_15_r20/external/deqp/external/vulkancts/vkscserver/vksNetwork.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKSNETWORK_HPP
2 #define _VKSNETWORK_HPP
3 
4 /*-------------------------------------------------------------------------
5  * Vulkan CTS Framework
6  * --------------------
7  *
8  * Copyright (c) 2021 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *-------------------------------------------------------------------------*/
23 
24 #include "vksCommon.hpp"
25 
26 namespace de
27 {
28 class Socket;
29 };
30 
31 namespace vksc_server
32 {
33 
34 constexpr auto DefaultPort = 59333;
35 
36 // Conver string (for example "192.168.0.1:59333") to host and port
37 void StringToAddress(const string &str, string &host, int &port);
38 
39 // Scan buffer, looking for a packet and call packetInterpreter, returns true if there is possibitly for another packet
40 bool ProccessNetworkData(vector<u8> &buffer, const std::function<void(u32, vector<u8>)> &packetInterpreter);
41 
42 // Sends whole bufer to socket
43 void Send(de::Socket *socket, const vector<u8> &buffer);
44 
45 // Send whole payload and insert [type, size] header before it
46 void SendPayloadWithHeader(de::Socket *socket, u32 type, const vector<u8> &payload);
47 
48 // Recv some bytes frome socket and insert it at the back of recvb
49 void RecvSome(de::Socket *socket, vector<u8> &recvb);
50 
51 // Recv single packet from socket (it will block until this function get it)
52 vector<u8> RecvPacket(de::Socket *socket, vector<u8> &recvb, u32 type);
53 
54 } // namespace vksc_server
55 
56 #endif // _VKSNETWORK_HPP
57