mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
简化ssl相关代码
This commit is contained in:
parent
6d7f987783
commit
e3ab51b337
@ -1 +1 @@
|
||||
Subproject commit 8e90a8dbefe9060fdb86b9dc8036345aa69faf41
|
||||
Subproject commit ea623e89153b7f5e4f693e3f2d4c5e60b79540ed
|
@ -100,7 +100,6 @@ 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;
|
||||
@ -132,12 +131,8 @@ void HttpClient::onConnect(const SockException &ex) {
|
||||
}
|
||||
|
||||
void HttpClient::onRecv(const Buffer::Ptr &pBuf) {
|
||||
onRecvBytes(pBuf->data(), pBuf->size());
|
||||
}
|
||||
|
||||
void HttpClient::onRecvBytes(const char *data, int size) {
|
||||
_aliveTicker.resetTime();
|
||||
HttpRequestSplitter::input(data, size);
|
||||
HttpRequestSplitter::input(pBuf->data(), pBuf->size());
|
||||
}
|
||||
|
||||
void HttpClient::onErr(const SockException &ex) {
|
||||
|
@ -283,13 +283,6 @@ protected:
|
||||
DebugL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到http回复数据回调
|
||||
* @param data 数据指针
|
||||
* @param size 数据大小
|
||||
*/
|
||||
virtual void onRecvBytes(const char *data,int size);
|
||||
|
||||
/**
|
||||
* http链接断开回调
|
||||
* @param ex 断开原因
|
||||
@ -299,9 +292,6 @@ 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;
|
||||
|
@ -28,37 +28,13 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
#if defined(ENABLE_OPENSSL)
|
||||
void HttpClientImp::onBeforeConnect(string &strUrl, uint16_t &iPort,float &fTimeOutSec) {
|
||||
if(_isHttps){
|
||||
_sslBox.reset(new SSL_Box(false));
|
||||
_sslBox->setOnDecData([this](const char *data, uint32_t len){
|
||||
public_onRecvBytes(data,len);
|
||||
});
|
||||
_sslBox->setOnEncData([this](const char *data, uint32_t len){
|
||||
public_send(data,len);
|
||||
});
|
||||
}else{
|
||||
_sslBox.reset();
|
||||
void HttpClientImp::onConnect(const SockException &ex) {
|
||||
if(!_isHttps){
|
||||
HttpClient::onConnect(ex);
|
||||
} else {
|
||||
TcpClientWithSSL<HttpClient>::onConnect(ex);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClientImp::onRecvBytes(const char* data, int size) {
|
||||
if(_sslBox){
|
||||
_sslBox->onRecv(data,size);
|
||||
}else{
|
||||
HttpClient::onRecvBytes(data,size);
|
||||
}
|
||||
}
|
||||
|
||||
int HttpClientImp::send(const Buffer::Ptr &buf) {
|
||||
if(_sslBox){
|
||||
_sslBox->onSend(buf->data(),buf->size());
|
||||
return buf->size();
|
||||
}
|
||||
return HttpClient::send(buf);
|
||||
}
|
||||
|
||||
#endif //defined(ENABLE_OPENSSL)
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
@ -28,41 +28,21 @@
|
||||
#define SRC_HTTP_HTTPCLIENTIMP_H_
|
||||
|
||||
#include "HttpClient.h"
|
||||
#ifdef ENABLE_OPENSSL
|
||||
#include "Util/SSLBox.h"
|
||||
#endif //ENABLE_OPENSSL
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
#if defined(ENABLE_OPENSSL)
|
||||
class HttpClientImp: public HttpClient {
|
||||
class HttpClientImp: public TcpClientWithSSL<HttpClient> {
|
||||
public:
|
||||
typedef std::shared_ptr<HttpClientImp> Ptr;
|
||||
HttpClientImp() {}
|
||||
virtual ~HttpClientImp() {}
|
||||
|
||||
inline void public_onRecvBytes(const char *data,int len){
|
||||
HttpClient::onRecvBytes(data,len);
|
||||
}
|
||||
inline void public_send(const char *data, uint32_t len){
|
||||
HttpClient::send(obtainBuffer(data,len));
|
||||
}
|
||||
private:
|
||||
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;
|
||||
protected:
|
||||
void onConnect(const SockException &ex) override ;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
typedef HttpClient HttpClientImp;
|
||||
|
||||
#endif // defined(ENABLE_OPENSSL)
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
#endif /* SRC_HTTP_HTTPCLIENTIMP_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user