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
6 years ago
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) {
...
@@ -60,7 +60,7 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
if
(
_path
.
empty
())
{
if
(
_path
.
empty
())
{
_path
=
"/"
;
_path
=
"/"
;
}
}
auto
port
=
atoi
(
FindField
(
host
.
data
(),
":"
,
NULL
).
data
());
uint16_t
port
=
atoi
(
FindField
(
host
.
data
(),
":"
,
NULL
).
data
());
if
(
port
<=
0
)
{
if
(
port
<=
0
)
{
//默认端口
//默认端口
port
=
defaultPort
;
port
=
defaultPort
;
...
@@ -99,6 +99,7 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
...
@@ -99,6 +99,7 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
if
(
!
alive
()
||
bChanged
)
{
if
(
!
alive
()
||
bChanged
)
{
//InfoL << "reconnet:" << _lastHost;
//InfoL << "reconnet:" << _lastHost;
onBeforeConnect
(
host
,
port
,
fTimeOutSec
);
startConnect
(
host
,
port
,
fTimeOutSec
);
startConnect
(
host
,
port
,
fTimeOutSec
);
}
else
{
}
else
{
SockException
ex
;
SockException
ex
;
...
...
This diff is collapsed.
Click to expand it.
src/Http/HttpClient.h
查看文件 @
faab85e2
...
@@ -207,13 +207,21 @@ public:
...
@@ -207,13 +207,21 @@ public:
HttpClient
();
HttpClient
();
virtual
~
HttpClient
();
virtual
~
HttpClient
();
virtual
void
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
);
virtual
void
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
);
void
clear
(){
virtual
void
clear
(){
_header
.
clear
();
_header
.
clear
();
_body
.
reset
();
_body
.
reset
();
_method
.
clear
();
_method
.
clear
();
_path
.
clear
();
_path
.
clear
();
_parser
.
Clear
();
_parser
.
Clear
();
_recvedBodySize
=
0
;
_totalBodySize
=
0
;
_aliveTicker
.
resetTime
();
_fTimeOutSec
=
0
;
_chunkedSplitter
.
reset
();
HttpRequestSplitter
::
reset
();
}
}
void
setMethod
(
const
string
&
method
){
void
setMethod
(
const
string
&
method
){
_method
=
method
;
_method
=
method
;
}
}
...
@@ -291,6 +299,9 @@ protected:
...
@@ -291,6 +299,9 @@ protected:
//HttpRequestSplitter override
//HttpRequestSplitter override
int64_t
onRecvHeader
(
const
char
*
data
,
uint64_t
len
)
override
;
int64_t
onRecvHeader
(
const
char
*
data
,
uint64_t
len
)
override
;
void
onRecvContent
(
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
:
protected
:
virtual
void
onConnect
(
const
SockException
&
ex
)
override
;
virtual
void
onConnect
(
const
SockException
&
ex
)
override
;
virtual
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
;
virtual
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
;
...
@@ -303,7 +314,6 @@ private:
...
@@ -303,7 +314,6 @@ private:
protected
:
protected
:
bool
_isHttps
;
bool
_isHttps
;
private
:
private
:
//send
HttpHeader
_header
;
HttpHeader
_header
;
HttpBody
::
Ptr
_body
;
HttpBody
::
Ptr
_body
;
string
_method
;
string
_method
;
...
...
This diff is collapsed.
Click to expand it.
src/Http/HttpClientImp.cpp
查看文件 @
faab85e2
...
@@ -28,47 +28,21 @@
...
@@ -28,47 +28,21 @@
namespace
mediakit
{
namespace
mediakit
{
HttpClientImp
::
HttpClientImp
()
{
#if defined(ENABLE_OPENSSL)
// TODO Auto-generated constructor stub
void
HttpClientImp
::
onBeforeConnect
(
string
&
strUrl
,
uint16_t
&
iPort
,
float
&
fTimeOutSec
)
{
}
HttpClientImp
::~
HttpClientImp
()
{
}
void
HttpClientImp
::
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
)
{
HttpClient
::
sendRequest
(
url
,
fTimeOutSec
);
if
(
_isHttps
){
if
(
_isHttps
){
#ifndef ENABLE_OPENSSL
shutdown
();
throw
std
::
invalid_argument
(
"不支持HTTPS协议"
);
#else
_sslBox
.
reset
(
new
SSL_Box
(
false
));
_sslBox
.
reset
(
new
SSL_Box
(
false
));
_sslBox
->
setOnDecData
([
this
](
const
char
*
data
,
uint32_t
len
){
_sslBox
->
setOnDecData
([
this
](
const
char
*
data
,
uint32_t
len
){
#if defined(__GNUC__) && (__GNUC__ < 5)
public_onRecvBytes
(
data
,
len
);
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
){
_sslBox
->
setOnEncData
([
this
](
const
char
*
data
,
uint32_t
len
){
#if defined(__GNUC__) && (__GNUC__ < 5)
public_send
(
data
,
len
);
public_send
(
data
,
len
);
#else//defined(__GNUC__) && (__GNUC__ < 5)
HttpClient
::
send
(
obtainBuffer
(
data
,
len
));
#endif//defined(__GNUC__) && (__GNUC__ < 5)
});
});
#endif //ENABLE_OPENSSL
}
else
{
}
else
{
#ifdef ENABLE_OPENSSL
_sslBox
.
reset
();
_sslBox
.
reset
();
#endif //ENABLE_OPENSSL
}
}
}
}
#ifdef ENABLE_OPENSSL
void
HttpClientImp
::
onRecvBytes
(
const
char
*
data
,
int
size
)
{
void
HttpClientImp
::
onRecvBytes
(
const
char
*
data
,
int
size
)
{
if
(
_sslBox
){
if
(
_sslBox
){
_sslBox
->
onRecv
(
data
,
size
);
_sslBox
->
onRecv
(
data
,
size
);
...
@@ -84,6 +58,7 @@ int HttpClientImp::send(const Buffer::Ptr &buf) {
...
@@ -84,6 +58,7 @@ int HttpClientImp::send(const Buffer::Ptr &buf) {
}
}
return
HttpClient
::
send
(
buf
);
return
HttpClient
::
send
(
buf
);
}
}
#endif //ENABLE_OPENSSL
#endif //defined(ENABLE_OPENSSL)
}
/* namespace mediakit */
}
/* namespace mediakit */
This diff is collapsed.
Click to expand it.
src/Http/HttpClientImp.h
查看文件 @
faab85e2
...
@@ -36,29 +36,33 @@ using namespace toolkit;
...
@@ -36,29 +36,33 @@ using namespace toolkit;
namespace
mediakit
{
namespace
mediakit
{
#if defined(ENABLE_OPENSSL)
class
HttpClientImp
:
public
HttpClient
{
class
HttpClientImp
:
public
HttpClient
{
public
:
public
:
typedef
std
::
shared_ptr
<
HttpClientImp
>
Ptr
;
typedef
std
::
shared_ptr
<
HttpClientImp
>
Ptr
;
HttpClientImp
();
HttpClientImp
()
{}
virtual
~
HttpClientImp
();
virtual
~
HttpClientImp
()
{}
virtual
void
sendRequest
(
const
string
&
url
,
float
fTimeOutSec
)
override
;
#if defined(__GNUC__) && (__GNUC__ < 5)
inline
void
public_onRecvBytes
(
const
char
*
data
,
int
len
){
void
public_onRecvBytes
(
const
char
*
data
,
int
len
){
HttpClient
::
onRecvBytes
(
data
,
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
));
HttpClient
::
send
(
obtainBuffer
(
data
,
len
));
}
}
#endif //defined(__GNUC__) && (__GNUC__ < 5)
private
:
private
:
#ifdef ENABLE_OPENSSL
void
onRecvBytes
(
const
char
*
data
,
int
size
)
override
;
virtual
void
onRecvBytes
(
const
char
*
data
,
int
size
)
override
;
int
send
(
const
Buffer
::
Ptr
&
buf
)
override
;
virtual
int
send
(
const
Buffer
::
Ptr
&
buf
)
override
;
void
onBeforeConnect
(
string
&
strUrl
,
uint16_t
&
iPort
,
float
&
fTimeOutSec
)
override
;
private
:
std
::
shared_ptr
<
SSL_Box
>
_sslBox
;
std
::
shared_ptr
<
SSL_Box
>
_sslBox
;
#endif //ENABLE_OPENSSL
};
};
#else
typedef
HttpClient
HttpClientImp
;
#endif // defined(ENABLE_OPENSSL)
}
/* namespace mediakit */
}
/* namespace mediakit */
#endif
/* SRC_HTTP_HTTPCLIENTIMP_H_ */
#endif
/* SRC_HTTP_HTTPCLIENTIMP_H_ */
This diff is collapsed.
Click to expand it.
src/Http/HttpRequestSplitter.cpp
查看文件 @
faab85e2
...
@@ -126,6 +126,7 @@ void HttpRequestSplitter::setContentLen(int64_t content_len) {
...
@@ -126,6 +126,7 @@ void HttpRequestSplitter::setContentLen(int64_t content_len) {
void
HttpRequestSplitter
::
reset
()
{
void
HttpRequestSplitter
::
reset
()
{
_content_len
=
0
;
_content_len
=
0
;
_remain_data_size
=
0
;
_remain_data
.
clear
();
_remain_data
.
clear
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Http/HttpRequester.cpp
查看文件 @
faab85e2
...
@@ -63,5 +63,11 @@ void HttpRequester::startRequester(const string &url,const HttpRequesterResult &
...
@@ -63,5 +63,11 @@ void HttpRequester::startRequester(const string &url,const HttpRequesterResult &
sendRequest
(
url
,
timeOutSecond
);
sendRequest
(
url
,
timeOutSecond
);
}
}
void
HttpRequester
::
clear
()
{
HttpClientImp
::
clear
();
_strRecvBody
.
clear
();
_onResult
=
nullptr
;
}
}
//namespace mediakit
}
//namespace mediakit
This diff is collapsed.
Click to expand it.
src/Http/HttpRequester.h
查看文件 @
faab85e2
...
@@ -39,6 +39,7 @@ public:
...
@@ -39,6 +39,7 @@ public:
HttpRequester
();
HttpRequester
();
virtual
~
HttpRequester
();
virtual
~
HttpRequester
();
void
startRequester
(
const
string
&
url
,
const
HttpRequesterResult
&
onResult
,
float
timeOutSecond
=
10
);
void
startRequester
(
const
string
&
url
,
const
HttpRequesterResult
&
onResult
,
float
timeOutSecond
=
10
);
void
clear
()
override
;
private
:
private
:
int64_t
onResponseHeader
(
const
string
&
status
,
const
HttpHeader
&
headers
)
override
;
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
;
void
onResponseBody
(
const
char
*
buf
,
size_t
size
,
size_t
recvedSize
,
size_t
totalSize
)
override
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论