Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
6ff60dd5
Commit
6ff60dd5
authored
Apr 19, 2017
by
xzl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增Https支持
parent
52e25fc0
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
78 行增加
和
7 行删除
+78
-7
src/Http/HttpSession.cpp
+8
-4
src/Http/HttpSession.h
+5
-3
src/Http/HttpsSession.h
+54
-0
src/config.cpp
+4
-0
src/config.h
+1
-0
test.cpp
+6
-0
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
6ff60dd5
...
...
@@ -84,6 +84,7 @@ HttpSession::HttpSession(const std::shared_ptr<ThreadPool> &pTh, const Socket::P
static
onceToken
token
([]()
{
g_mapCmdIndex
.
emplace
(
"GET"
,
&
HttpSession
::
Handle_Req_GET
);
g_mapCmdIndex
.
emplace
(
"POST"
,
&
HttpSession
::
Handle_Req_POST
);
g_mapCmdIndex
.
emplace
(
"OPTIONS"
,
&
HttpSession
::
Handle_Req_POST
);
},
nullptr
);
}
...
...
@@ -91,15 +92,18 @@ HttpSession::~HttpSession() {
//DebugL;
}
void
HttpSession
::
onRecv
(
const
Socket
::
Buffer
::
Ptr
&
pBuf
)
{
void
HttpSession
::
onRecv
(
const
Socket
::
Buffer
::
Ptr
&
pBuf
)
{
onRecv
(
pBuf
->
data
(),
pBuf
->
size
());
}
void
HttpSession
::
onRecv
(
const
char
*
data
,
int
size
){
static
uint32_t
reqSize
=
mINI
::
Instance
()[
Config
::
Http
::
kMaxReqSize
].
as
<
uint32_t
>
();
m_ticker
.
resetTime
();
if
(
m_strRcvBuf
.
size
()
+
pBuf
->
size
()
>=
reqSize
)
{
WarnL
<<
"接收缓冲区溢出:"
<<
m_strRcvBuf
.
size
()
+
pBuf
->
size
()
<<
","
<<
reqSize
;
if
(
m_strRcvBuf
.
size
()
+
size
>=
reqSize
)
{
WarnL
<<
"接收缓冲区溢出:"
<<
m_strRcvBuf
.
size
()
+
size
<<
","
<<
reqSize
;
shutdown
();
return
;
}
m_strRcvBuf
.
append
(
pBuf
->
data
(),
pBuf
->
size
()
);
m_strRcvBuf
.
append
(
data
,
size
);
size_t
index
;
string
onePkt
;
while
((
index
=
m_strRcvBuf
.
find
(
"
\r\n\r\n
"
))
!=
std
::
string
::
npos
)
{
...
...
src/Http/HttpSession.h
查看文件 @
6ff60dd5
...
...
@@ -31,9 +31,11 @@ public:
HttpSession
(
const
std
::
shared_ptr
<
ThreadPool
>
&
pTh
,
const
Socket
::
Ptr
&
pSock
);
virtual
~
HttpSession
();
void
onRecv
(
const
Socket
::
Buffer
::
Ptr
&
)
override
;
void
onError
(
const
SockException
&
err
)
override
;
void
onManager
()
override
;
virtual
void
onRecv
(
const
Socket
::
Buffer
::
Ptr
&
)
override
;
virtual
void
onError
(
const
SockException
&
err
)
override
;
virtual
void
onManager
()
override
;
protected
:
void
onRecv
(
const
char
*
data
,
int
size
);
private
:
typedef
enum
{
...
...
src/Http/HttpsSession.h
0 → 100644
查看文件 @
6ff60dd5
/*
* HttpsSession.h
*
* Created on: 2017年4月19日
* Author: xzl
*/
#ifndef SRC_HTTP_HTTPSSESSION_H_
#define SRC_HTTP_HTTPSSESSION_H_
#include "HttpSession.h"
#include "Util/SSLBox.h"
#include "Util/TimeTicker.h"
using
namespace
ZL
::
Util
;
namespace
ZL
{
namespace
Http
{
class
HttpsSession
:
public
HttpSession
{
public
:
HttpsSession
(
const
std
::
shared_ptr
<
ThreadPool
>
&
pTh
,
const
Socket
::
Ptr
&
pSock
)
:
HttpSession
(
pTh
,
pSock
){
m_sslBox
.
setOnEncData
([
&
](
const
char
*
data
,
uint32_t
len
){
HttpSession
::
send
(
data
,
len
);
});
m_sslBox
.
setOnDecData
([
&
](
const
char
*
data
,
uint32_t
len
){
HttpSession
::
onRecv
(
data
,
len
);
});
}
virtual
~
HttpsSession
(){
//m_sslBox.shutdown();
}
void
onRecv
(
const
Socket
::
Buffer
::
Ptr
&
pBuf
)
override
{
TimeTicker
();
m_sslBox
.
onRecv
(
pBuf
->
data
(),
pBuf
->
size
());
}
private
:
virtual
int
send
(
const
string
&
buf
)
override
{
TimeTicker
();
m_sslBox
.
onSend
(
buf
.
data
(),
buf
.
size
());
return
buf
.
size
();
}
virtual
int
send
(
const
char
*
buf
,
int
size
)
override
{
TimeTicker
();
m_sslBox
.
onSend
(
buf
,
size
);
return
size
;
}
SSL_Box
m_sslBox
;
};
}
/* namespace Http */
}
/* namespace ZL */
#endif
/* SRC_HTTP_HTTPSSESSION_H_ */
src/config.cpp
查看文件 @
6ff60dd5
...
...
@@ -37,6 +37,9 @@ namespace Http {
#define HTTP_PORT 80
const
char
kPort
[]
=
HTTP_FIELD
"port"
;
#define HTTPS_PORT 443
extern
const
char
kSSLPort
[]
=
HTTP_FIELD
"sslport"
;
//http 文件发送缓存大小
#define HTTP_SEND_BUF_SIZE (64 * 1024)
const
char
kSendBufSize
[]
=
HTTP_FIELD
"sendBufSize"
;
...
...
@@ -85,6 +88,7 @@ const char kHttpPrefix[] = HTTP_FIELD"httpPrefix";
onceToken
token
([](){
mINI
::
Instance
()[
kPort
]
=
HTTP_PORT
;
mINI
::
Instance
()[
kSSLPort
]
=
HTTPS_PORT
;
mINI
::
Instance
()[
kSendBufSize
]
=
HTTP_SEND_BUF_SIZE
;
mINI
::
Instance
()[
kMaxReqSize
]
=
HTTP_MAX_REQ_SIZE
;
mINI
::
Instance
()[
kKeepAliveSecond
]
=
HTTP_KEEP_ALIVE_SECOND
;
...
...
src/config.h
查看文件 @
6ff60dd5
...
...
@@ -63,6 +63,7 @@ extern const char kReplayCount[];
////////////HTTP配置///////////
namespace
Http
{
extern
const
char
kPort
[];
extern
const
char
kSSLPort
[];
//http 文件发送缓存大小
extern
const
char
kSendBufSize
[];
//http 最大请求字节数
...
...
test.cpp
查看文件 @
6ff60dd5
...
...
@@ -18,6 +18,8 @@
#include "Poller/EventPoller.hpp"
#include "Thread/WorkThreadPool.h"
#include "Http/HttpSession.h"
#include "Http/HttpsSession.h"
#include "Util/SSLBox.h"
using
namespace
std
;
using
namespace
ZL
::
Util
;
...
...
@@ -35,19 +37,23 @@ int main(int argc,char *argv[]){
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
SSL_Initor
::
Instance
().
loadServerPem
((
exeDir
()
+
".HttpServer.pem"
).
data
());
TcpServer
<
RtspSession
>::
Ptr
rtspSrv
(
new
TcpServer
<
RtspSession
>
());
TcpServer
<
RtmpSession
>::
Ptr
rtmpSrv
(
new
TcpServer
<
RtmpSession
>
());
TcpServer
<
HttpSession
>::
Ptr
httpSrv
(
new
TcpServer
<
HttpSession
>
());
TcpServer
<
HttpsSession
>::
Ptr
httpsSrv
(
new
TcpServer
<
HttpsSession
>
());
rtspSrv
->
start
(
mINI
::
Instance
()[
Config
::
Rtsp
::
kPort
]);
rtmpSrv
->
start
(
mINI
::
Instance
()[
Config
::
Rtmp
::
kPort
]);
httpSrv
->
start
(
mINI
::
Instance
()[
Config
::
Http
::
kPort
]);
httpsSrv
->
start
(
mINI
::
Instance
()[
Config
::
Http
::
kSSLPort
]);
EventPoller
::
Instance
().
runLoop
();
rtspSrv
.
reset
();
rtmpSrv
.
reset
();
httpSrv
.
reset
();
httpsSrv
.
reset
();
static
onceToken
token
(
nullptr
,
[]()
{
UDPServer
::
Destory
();
WorkThreadPool
::
Destory
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论