VR-Vantage 2.8 API Documentation
Home
Modules
Namespaces
Classes
Files
Libraries
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
TracyClient
common
TracySocket.hpp
Go to the documentation of this file.
1
#ifndef __TRACYSOCKET_HPP__
2
#define __TRACYSOCKET_HPP__
3
4
#include <atomic>
5
#include <
stdint.h
>
6
7
#include "
TracyForceInline.hpp
"
8
9
struct
addrinfo;
10
struct
sockaddr;
11
12
namespace
tracy
13
{
14
15
#ifdef _WIN32
16
void
InitWinSock();
17
#endif
18
19
class
Socket
20
{
21
public
:
22
Socket
();
23
Socket
(
int
sock );
24
~Socket
();
25
26
bool
Connect
(
const
char
*
addr
,
int
port );
27
void
Close
();
28
29
int
Send
(
const
void
*
buf
,
int
len
);
30
int
GetSendBufSize
();
31
32
bool
Read
(
void
* buf,
int
len,
int
timeout
);
33
34
template
<
typename
ShouldExit>
35
bool
Read
(
void
* buf,
int
len,
int
timeout, ShouldExit exitCb )
36
{
37
auto
cbuf = (
char
*)buf;
38
while
( len > 0 )
39
{
40
if
( exitCb() )
return
false
;
41
if
( !
ReadImpl
( cbuf, len, timeout ) )
return
false
;
42
}
43
return
true
;
44
}
45
46
bool
ReadRaw
(
void
* buf,
int
len,
int
timeout );
47
bool
HasData
();
48
bool
IsValid
()
const
;
49
50
Socket
(
const
Socket
& ) =
delete
;
51
Socket
(
Socket
&& ) =
delete
;
52
Socket
&
operator=
(
const
Socket
& ) =
delete
;
53
Socket
&
operator=
(
Socket
&& ) =
delete
;
54
55
private
:
56
int
RecvBuffered
(
void
* buf,
int
len,
int
timeout );
57
int
Recv
(
void
* buf,
int
len,
int
timeout );
58
59
bool
ReadImpl
(
char
*& buf,
int
& len,
int
timeout );
60
61
char
*
m_buf
;
62
char
*
m_bufPtr
;
63
std::atomic<int>
m_sock
;
64
int
m_bufLeft
;
65
66
struct
addrinfo *
m_res
;
67
struct
addrinfo *
m_ptr
;
68
int
m_connSock
;
69
};
70
71
class
ListenSocket
72
{
73
public
:
74
ListenSocket
();
75
~ListenSocket
();
76
77
bool
Listen
(
int
port,
int
backlog );
78
Socket
*
Accept
();
79
void
Close
();
80
81
ListenSocket
(
const
ListenSocket
& ) =
delete
;
82
ListenSocket
(
ListenSocket
&& ) =
delete
;
83
ListenSocket
&
operator=
(
const
ListenSocket
& ) =
delete
;
84
ListenSocket
&
operator=
(
ListenSocket
&& ) =
delete
;
85
86
private
:
87
int
m_sock
;
88
};
89
90
class
UdpBroadcast
91
{
92
public
:
93
UdpBroadcast
();
94
~UdpBroadcast
();
95
96
bool
Open
(
const
char
*
addr
,
int
port );
97
void
Close
();
98
99
int
Send
(
int
port,
const
void
*
data
,
int
len
);
100
101
UdpBroadcast
(
const
UdpBroadcast
& ) =
delete
;
102
UdpBroadcast
(
UdpBroadcast
&& ) =
delete
;
103
UdpBroadcast
&
operator=
(
const
UdpBroadcast
& ) =
delete
;
104
UdpBroadcast
&
operator=
(
UdpBroadcast
&& ) =
delete
;
105
106
private
:
107
int
m_sock
;
108
};
109
110
class
IpAddress
111
{
112
public
:
113
IpAddress
();
114
~IpAddress
();
115
116
void
Set
(
const
struct
sockaddr&
addr
);
117
118
uint32_t
GetNumber
()
const
{
return
m_number
; }
119
const
char
*
GetText
()
const
{
return
m_text
; }
120
121
IpAddress
(
const
IpAddress
& ) =
delete
;
122
IpAddress
(
IpAddress
&& ) =
delete
;
123
IpAddress
&
operator=
(
const
IpAddress
& ) =
delete
;
124
IpAddress
&
operator=
(
IpAddress
&& ) =
delete
;
125
126
private
:
127
uint32_t
m_number
;
128
char
m_text
[17];
129
};
130
131
class
UdpListen
132
{
133
public
:
134
UdpListen
();
135
~UdpListen
();
136
137
bool
Listen
(
int
port );
138
void
Close
();
139
140
const
char
*
Read
(
size_t
&
len
,
IpAddress
&
addr
);
141
142
UdpListen
(
const
UdpListen
& ) =
delete
;
143
UdpListen
(
UdpListen
&& ) =
delete
;
144
UdpListen
&
operator=
(
const
UdpListen
& ) =
delete
;
145
UdpListen
&
operator=
(
UdpListen
&& ) =
delete
;
146
147
private
:
148
int
m_sock
;
149
};
150
151
}
152
153
#endif
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (
www.mak.com
)