Sese Framework
x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
TcpTransporter.h
浏览该文件的文档.
1
// Copyright 2024 libsese
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
20
21
#pragma once
22
23
#include <
sese/service/TimerableService_V1.h
>
24
#include <
sese/security/SSLContext.h
>
25
#include "
sese/io/ByteBuilder.h
"
26
27
#include <atomic>
28
29
#ifdef _WIN32
30
#pragma warning(disable : 4275)
31
#endif
32
33
namespace
sese::service
{
34
36
struct
TcpConnection
{
37
virtual
~TcpConnection
() =
default
;
38
45
std::atomic_bool
isAsync
=
false
;
46
47
void
*
ssl
=
nullptr
;
48
event::BaseEvent
*
event
=
nullptr
;
49
service::v1::TimeoutEvent
*
timeoutEvent
=
nullptr
;
50
io::ByteBuilder
buffer2read
{8192};
51
io::ByteBuilder
buffer2write
{8192};
52
};
53
55
struct
TcpTransporterConfig
{
56
uint32_t
keepalive
= 30;
57
security::SSLContext::Ptr
servCtx
=
nullptr
;
58
59
virtual
~TcpTransporterConfig
() =
default
;
60
virtual
TcpConnection
*
createConnection
() = 0;
61
virtual
void
freeConnection
(
TcpConnection
*conn);
62
};
63
65
class
TcpTransporter
:
public
v1::TimerableService
{
66
public
:
67
explicit
TcpTransporter
(
TcpTransporterConfig
*transporter_config)
noexcept
;
68
~TcpTransporter
()
override
;
69
70
protected
:
71
void
onAccept
(
int
fd)
override
;
72
void
onRead
(
event::BaseEvent
*event)
override
;
73
void
onWrite
(
event::BaseEvent
*event)
override
;
74
void
onClose
(
event::BaseEvent
*event)
override
;
75
void
onTimeout
(
v1::TimeoutEvent
*timeout_event)
override
;
76
77
protected
:
78
virtual
void
postRead
(
TcpConnection
*conn);
79
virtual
void
postWrite
(
TcpConnection
*conn);
80
virtual
int
onProcAlpnSelect
(
81
const
uint8_t **out, uint8_t *out_length,
82
const
uint8_t *
in
, uint32_t in_length
83
) = 0;
84
virtual
void
onProcAlpnGet
(
85
TcpConnection
*conn,
86
const
uint8_t *
in
, uint32_t in_length
87
) = 0;
88
virtual
void
onProcHandle
(
TcpConnection
*conn) = 0;
89
virtual
void
onProcClose
(
TcpConnection
*conn) = 0;
90
91
protected
:
92
event::BaseEvent
*
createEventEx
(
int
fd,
unsigned
int
events,
TcpConnection
*conn)
noexcept
;
93
void
freeEventEx
(
event::BaseEvent
*event)
noexcept
;
94
static
int64_t
read
(
int
fd,
void
*buffer,
size_t
len,
void
*ssl)
noexcept
;
95
static
int64_t
write
(
int
fd,
const
void
*buffer,
size_t
len,
void
*ssl)
noexcept
;
96
97
TcpTransporterConfig
*
config
=
nullptr
;
98
std::map<int, event::BaseEvent *>
eventMap
;
99
100
private
:
101
static
int
alpnCallbackFunction
(
102
void
*ssl,
103
const
uint8_t **out, uint8_t *out_length,
104
const
uint8_t *
in
, uint32_t in_length,
105
TcpTransporter
*transporter
106
);
107
};
108
109
}
// namespace sese::service
sese
service
TcpTransporter.h
生成于 2024年 十一月 4日 星期一 09:58:02 , 为 Sese Framework使用
1.11.0