-
Notifications
You must be signed in to change notification settings - Fork 3
/
session.hpp
57 lines (43 loc) · 996 Bytes
/
session.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <memory>
#include "handler.hpp"
#include "sock_stream.hpp"
class Session : public Handler
{
public:
~Session();
Session();
SockStream& stream() { return stream_; }
int get_handle() const { return stream_.get_handle(); }
State handle_input();
std::string read_request(unsigned int max_len);
private:
SockStream stream_;
unsigned int timeout_;
};
typedef std::shared_ptr<Session> SessionPtr;
inline bool match_str(const char* b, const char* e, const char* term_str, unsigned int term_len, unsigned int* match_from)
{
unsigned int n = e - b;
if( n >= (term_len - *match_from))
{
n = (term_len - *match_from);
}
unsigned int i;
for(i = 0; i < n; ++i)
{
if( b[i] != term_str[*match_from+i])
{
return false;
}
}
if(*match_from + i == term_len)
{
return true;
}
else
{
*match_from += (i);
return false;
}
}