forest-net
an overlay networks for large-scale virtual worlds
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
NetBuffer.h
Go to the documentation of this file.
1
9
#ifndef NETBUFFER_H
10
#define NETBUFFER_H
11
12
#include "
Forest.h
"
13
#include "
Packet.h
"
14
#include "
CtlPkt.h
"
15
#include "
RateSpec.h
"
16
17
namespace
forest {
18
26
class
NetBuffer
{
27
public
:
28
// constructors/destructor
29
NetBuffer
(
int
,
int
);
30
NetBuffer
(
string
&);
31
NetBuffer
(
char
*,
int
);
32
~
NetBuffer
();
33
34
void
reset
(
string
&);
35
void
reset
(
char
*,
int
);
36
37
// predicates
38
bool
full()
const
;
39
bool
empty()
const
;
40
bool
isWordChar(
char
)
const
;
41
42
// operations on buffer
43
void
clear
();
44
void
flushBuf
(
string
&);
45
bool
readWord
(
string
&);
46
bool
readName
(
string
&);
47
bool
readString
(
string
&);
48
bool
readAlphas
(
string
&);
49
bool
readLine
(
string
&);
50
bool
readBit
(
bool
&);
51
bool
readInt
(
int
&);
52
bool
readInt
(uint64_t&);
53
bool
readForestAddress
(
string
&);
54
bool
readPktType(
Forest::ptyp_t
&);
55
bool
readCpType(
CtlPkt::CpType
&);
56
bool
readIpAddress
(
string
&);
57
int
readBlock
(
char
*,
int
);
58
bool
readRspec(
RateSpec
&);
59
bool
nextLine
();
60
bool
skipSpace
();
61
bool
skipSpaceInLine
();
62
bool
verify
(
char
);
63
64
string
& toString(
string
&);
65
private
:
66
int
sock
;
67
char
*
rp
;
68
char
*
wp
;
69
70
char
*
buf
;
71
int
size
;
72
73
bool
noRefill
;
74
75
// internal helper methods
76
void
advance(
char
*&,
int
=1);
77
bool
refill
();
78
void
extract
(
int
,
string
&);
79
};
80
81
inline
bool
NetBuffer::full()
const
{
82
return
wp
+1 ==
rp
|| (
rp
==
buf
&&
wp
==
buf
+(
size
-1));
83
}
84
85
inline
bool
NetBuffer::empty()
const
{
return
rp
==
wp
; }
86
87
inline
void
NetBuffer::advance(
char
*& p,
int
len) {
88
p += len;
if
(p >=
buf
+
size
) p -=
size
;
89
}
90
91
inline
bool
NetBuffer::isWordChar(
char
c)
const
{
92
return
isalpha(c) || isdigit(c) || c ==
'_'
|| c ==
'/'
||
93
c ==
'@'
|| c ==
'.'
|| c ==
'-'
;
94
}
95
96
}
// ends namespace
97
98
99
#endif
forest-net
cpp
include
NetBuffer.h
Generated on Mon Aug 4 2014 11:13:35 for forest-net by
1.8.4