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
faab85e2
Commit
faab85e2
authored
Jan 03, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善Http客户端复用机制
parent
bdaeada3
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
41 行增加
和
43 行删除
+41
-43
src/Http/HttpClient.cpp
+2
-1
src/Http/HttpClient.h
+12
-2
src/Http/HttpClientImp.cpp
+4
-29
src/Http/HttpClientImp.h
+15
-11
src/Http/HttpRequestSplitter.cpp
+1
-0
src/Http/HttpRequester.cpp
+6
-0
src/Http/HttpRequester.h
+1
-0
没有找到文件。
src/Http/HttpClient.cpp
查看文件 @
faab85e2
...
...
@@ -60,7 +60,7 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
if
(
_path
.
empty
())
{
_path
=
"/"
;
}
auto
port
=
atoi
(
FindField
(
host
.
data
(),
":"
,
NULL
).
data
());
uint16_t
port
=
atoi
(
FindField
(
host
.
data
(),
":"
,
NULL
).
data
());
if
(
port
<=
0
)
{
//默认端口
port
=
defaultPort
;
...
...
@@ -99,6 +99,7 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
if
(
!
alive
()
||
bChanged
)
{
//InfoL << "reconnet:" << _lastHost;
onBeforeConnect
(
host
,
port
,
fTimeOutSec
);
startConnect
(
host
,
port
,
fTimeOutSec
);
}
else
{
SockException
ex
;
...
...
src/Http/HttpClient.h
查看文件 @
faab85e2
...
...
@@ -207,13 +207,21 @@ public:
HttpClient
();
virtual
~
HttpClient
();
virtual
void
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
);
void
clear
(){
virtual
void
clear
(){
_header
.
clear
();
_body
.
reset
();
_method
.
clear
();
_path
.
clear
();
_parser
.
Clear
();
_recvedBodySize
=
0
;
_totalBodySize
=
0
;
_aliveTicker
.
resetTime
();
_fTimeOutSec
=
0
;
_chunkedSplitter
.
reset
();
HttpRequestSplitter
::
reset
();
}
void
setMethod
(
const
string
&
method
){
_method
=
method
;
}
...
...
@@ -291,6 +299,9 @@ protected:
//HttpRequestSplitter override
int64_t
onRecvHeader
(
const
char
*
data
,
uint64_t
len
)
override
;
void
onRecvContent
(
const
char
*
data
,
uint64_t
len
)
override
;
//在连接服务器前调用一次
virtual
void
onBeforeConnect
(
string
&
strUrl
,
uint16_t
&
iPort
,
float
&
fTimeOutSec
)
{};
protected
:
virtual
void
onConnect
(
const
SockException
&
ex
)
override
;
virtual
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
;
...
...
@@ -303,7 +314,6 @@ private:
protected
:
bool
_isHttps
;
private
:
//send
HttpHeader
_header
;
HttpBody
::
Ptr
_body
;
string
_method
;
...
...
src/Http/HttpClientImp.cpp
查看文件 @
faab85e2
...
...
@@ -28,47 +28,21 @@
namespace
mediakit
{
HttpClientImp
::
HttpClientImp
()
{
// TODO Auto-generated constructor stub
}
HttpClientImp
::~
HttpClientImp
()
{
}
void
HttpClientImp
::
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
)
{
HttpClient
::
sendRequest
(
url
,
fTimeOutSec
);
#if defined(ENABLE_OPENSSL)
void
HttpClientImp
::
onBeforeConnect
(
string
&
strUrl
,
uint16_t
&
iPort
,
float
&
fTimeOutSec
)
{
if
(
_isHttps
){
#ifndef ENABLE_OPENSSL
shutdown
();
throw
std
::
invalid_argument
(
"不支持HTTPS协议"
);
#else
_sslBox
.
reset
(
new
SSL_Box
(
false
));
_sslBox
->
setOnDecData
([
this
](
const
char
*
data
,
uint32_t
len
){
#if defined(__GNUC__) && (__GNUC__ < 5)
public_onRecvBytes
(
data
,
len
);
#else//defined(__GNUC__) && (__GNUC__ < 5)
HttpClient
::
onRecvBytes
(
data
,
len
);
#endif//defined(__GNUC__) && (__GNUC__ < 5)
});
_sslBox
->
setOnEncData
([
this
](
const
char
*
data
,
uint32_t
len
){
#if defined(__GNUC__) && (__GNUC__ < 5)
public_send
(
data
,
len
);
#else//defined(__GNUC__) && (__GNUC__ < 5)
HttpClient
::
send
(
obtainBuffer
(
data
,
len
));
#endif//defined(__GNUC__) && (__GNUC__ < 5)
});
#endif //ENABLE_OPENSSL
}
else
{
#ifdef ENABLE_OPENSSL
_sslBox
.
reset
();
#endif //ENABLE_OPENSSL
}
}
#ifdef ENABLE_OPENSSL
void
HttpClientImp
::
onRecvBytes
(
const
char
*
data
,
int
size
)
{
if
(
_sslBox
){
_sslBox
->
onRecv
(
data
,
size
);
...
...
@@ -84,6 +58,7 @@ int HttpClientImp::send(const Buffer::Ptr &buf) {
}
return
HttpClient
::
send
(
buf
);
}
#endif //ENABLE_OPENSSL
#endif //defined(ENABLE_OPENSSL)
}
/* namespace mediakit */
src/Http/HttpClientImp.h
查看文件 @
faab85e2
...
...
@@ -36,29 +36,33 @@ using namespace toolkit;
namespace
mediakit
{
#if defined(ENABLE_OPENSSL)
class
HttpClientImp
:
public
HttpClient
{
public
:
typedef
std
::
shared_ptr
<
HttpClientImp
>
Ptr
;
HttpClientImp
();
virtual
~
HttpClientImp
();
virtual
void
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
)
override
;
HttpClientImp
()
{}
virtual
~
HttpClientImp
()
{}
#if defined(__GNUC__) && (__GNUC__ < 5)
void
public_onRecvBytes
(
const
char
*
data
,
int
len
){
inline
void
public_onRecvBytes
(
const
char
*
data
,
int
len
){
HttpClient
::
onRecvBytes
(
data
,
len
);
}
void
public_send
(
const
char
*
data
,
uint32_t
len
){
inline
void
public_send
(
const
char
*
data
,
uint32_t
len
){
HttpClient
::
send
(
obtainBuffer
(
data
,
len
));
}
#endif //defined(__GNUC__) && (__GNUC__ < 5)
private
:
#ifdef ENABLE_OPENSSL
virtual
void
onRecvBytes
(
const
char
*
data
,
int
size
)
override
;
virtual
int
send
(
const
Buffer
::
Ptr
&
buf
)
override
;
void
onRecvBytes
(
const
char
*
data
,
int
size
)
override
;
int
send
(
const
Buffer
::
Ptr
&
buf
)
override
;
void
onBeforeConnect
(
string
&
strUrl
,
uint16_t
&
iPort
,
float
&
fTimeOutSec
)
override
;
private
:
std
::
shared_ptr
<
SSL_Box
>
_sslBox
;
#endif //ENABLE_OPENSSL
};
#else
typedef
HttpClient
HttpClientImp
;
#endif // defined(ENABLE_OPENSSL)
}
/* namespace mediakit */
#endif
/* SRC_HTTP_HTTPCLIENTIMP_H_ */
src/Http/HttpRequestSplitter.cpp
查看文件 @
faab85e2
...
...
@@ -126,6 +126,7 @@ void HttpRequestSplitter::setContentLen(int64_t content_len) {
void
HttpRequestSplitter
::
reset
()
{
_content_len
=
0
;
_remain_data_size
=
0
;
_remain_data
.
clear
();
}
...
...
src/Http/HttpRequester.cpp
查看文件 @
faab85e2
...
...
@@ -63,5 +63,11 @@ void HttpRequester::startRequester(const string &url,const HttpRequesterResult &
sendRequest
(
url
,
timeOutSecond
);
}
void
HttpRequester
::
clear
()
{
HttpClientImp
::
clear
();
_strRecvBody
.
clear
();
_onResult
=
nullptr
;
}
}
//namespace mediakit
src/Http/HttpRequester.h
查看文件 @
faab85e2
...
...
@@ -39,6 +39,7 @@ public:
HttpRequester
();
virtual
~
HttpRequester
();
void
startRequester
(
const
string
&
url
,
const
HttpRequesterResult
&
onResult
,
float
timeOutSecond
=
10
);
void
clear
()
override
;
private
:
int64_t
onResponseHeader
(
const
string
&
status
,
const
HttpHeader
&
headers
)
override
;
void
onResponseBody
(
const
char
*
buf
,
size_t
size
,
size_t
recvedSize
,
size_t
totalSize
)
override
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论