• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { class Socket; };
27 
28 namespace vksc_server
29 {
30 
31 constexpr auto DefaultPort = 59333;
32 
33 // Conver string (for example "192.168.0.1:59333") to host and port
34 void		StringToAddress			(const string& str,		string& host,				int& port							);
35 
36 // Scan buffer, looking for a packet and call packetInterpreter, returns true if there is possibitly for another packet
37 bool		ProccessNetworkData		(vector<u8>& buffer,	const std::function<void(u32, vector<u8>)>& packetInterpreter	);
38 
39 // Sends whole bufer to socket
40 void		Send					(de::Socket* socket,	const vector<u8>& buffer										);
41 
42 // Send whole payload and insert [type, size] header before it
43 void		SendPayloadWithHeader	(de::Socket* socket,	u32 type,					const vector<u8>& payload			);
44 
45 // Recv some bytes frome socket and insert it at the back of recvb
46 void		RecvSome				(de::Socket* socket,	vector<u8>& recvb);
47 
48 // Recv single packet from socket (it will block until this function get it)
49 vector<u8>	RecvPacket				(de::Socket* socket,	vector<u8>&	recvb,			u32 type							);
50 
51 }
52 
53 #endif // _VKSNETWORK_HPP
54