openthread-br
0.3.0-72c0388
src
rest
connection.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020, The OpenThread Authors.
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* 3. Neither the name of the copyright holder nor the
13
* names of its contributors may be used to endorse or promote products
14
* derived from this software without specific prior written permission.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
27
*/
28
34
#ifndef OTBR_REST_CONNECTION_HPP_
35
#define OTBR_REST_CONNECTION_HPP_
36
37
#include <string.h>
38
#include <unistd.h>
39
40
#include "
common/mainloop.hpp
"
41
#include "
rest/parser.hpp
"
42
#include "
rest/resource.hpp
"
43
44
using
std::chrono::steady_clock;
45
46
namespace
otbr {
47
namespace
rest {
48
53
class
Connection
:
public
MainloopProcessor
54
{
55
public
:
67
Connection
(steady_clock::time_point aStartTime,
Resource
*aResource,
int
aFd);
68
73
~Connection
(
void
)
override
;
74
80
void
Init
(
void
);
81
82
void
Update
(
MainloopContext
&aMainloop)
override
;
83
void
Process
(
const
MainloopContext
&aMainloop)
override
;
84
92
bool
IsComplete
(
void
)
const
;
93
94
private
:
95
void
UpdateReadFdSet(fd_set &aReadFdSet,
int
&aMaxFd)
const
;
96
void
UpdateWriteFdSet(fd_set &aWriteFdSet,
int
&aMaxFd)
const
;
97
void
UpdateTimeout(timeval &aTimeout)
const
;
98
void
ProcessWaitRead(
const
fd_set &aReadFdSet);
99
void
ProcessWaitCallback(
void
);
100
void
ProcessWaitWrite(
const
fd_set &aWriteFdSet);
101
void
Write(
void
);
102
void
Handle(
void
);
103
void
Disconnect(
void
);
104
105
// Timestamp used for each check point of a connection
106
steady_clock::time_point mTimeStamp;
107
108
// File descriptor for this connection
109
int
mFd;
110
111
// Enum indicates the state of this connection
112
ConnectionState mState;
113
114
// Response instance binded to this connection
115
Response
mResponse;
116
117
// Request instance binded to this connection
118
Request
mRequest;
119
120
// HTTP parser instance
121
Parser
mParser;
122
123
// Resource handler instance
124
Resource
*mResource;
125
126
// Write buffer in case write multiple times
127
std::string mWriteContent;
128
};
129
130
}
// namespace rest
131
}
// namespace otbr
132
133
#endif // OTBR_REST_CONNECTION_HPP_
otbr::rest::Connection::Update
void Update(MainloopContext &aMainloop) override
Definition:
connection.cpp:136
otbr::rest::Resource
Definition:
resource.hpp:57
parser.hpp
otbr::rest::Connection::Connection
Connection(steady_clock::time_point aStartTime, Resource *aResource, int aFd)
Definition:
connection.cpp:58
otbr::rest::Response
Definition:
response.hpp:56
mainloop.hpp
otbr::rest::Connection::IsComplete
bool IsComplete(void) const
Definition:
connection.cpp:355
otbr::rest::Connection::Process
void Process(const MainloopContext &aMainloop) override
Definition:
connection.cpp:154
otbr::MainloopProcessor
Definition:
mainloop.hpp:54
otbr::rest::Request
Definition:
request.hpp:50
otbr::rest::Connection::~Connection
~Connection(void) override
Definition:
connection.cpp:67
otbr::rest::Connection::Init
void Init(void)
Definition:
connection.cpp:72
resource.hpp
otbr::rest::Parser
Definition:
parser.hpp:54
otbr::MainloopContext
otSysMainloopContext MainloopContext
Definition:
mainloop.hpp:47
otbr::rest::Connection
Definition:
connection.hpp:53
Generated by
1.8.17