Commit 68948288 by ziyue

TcpSession/UdpSession统一为Session类

parent 47530ce8
ZLToolKit @ 617b6b1d
Subproject commit 894be81929f227583081755288ab0927c077e411
Subproject commit 617b6b1db23f13e2592b29204b84b1b9dbbf81c0
......@@ -174,7 +174,7 @@ API_EXPORT uint16_t API_CALL mk_http_server_start(uint16_t port, int ssl) {
try {
http_server[ssl] = std::make_shared<TcpServer>();
if(ssl){
http_server[ssl]->start<TcpSessionWithSSL<HttpSession> >(port);
http_server[ssl]->start<SessionWithSSL<HttpSession> >(port);
} else{
http_server[ssl]->start<HttpSession>(port);
}
......@@ -191,7 +191,7 @@ API_EXPORT uint16_t API_CALL mk_rtsp_server_start(uint16_t port, int ssl) {
try {
rtsp_server[ssl] = std::make_shared<TcpServer>();
if(ssl){
rtsp_server[ssl]->start<TcpSessionWithSSL<RtspSession> >(port);
rtsp_server[ssl]->start<SessionWithSSL<RtspSession> >(port);
}else{
rtsp_server[ssl]->start<RtspSession>(port);
}
......@@ -208,7 +208,7 @@ API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl) {
try {
rtmp_server[ssl] = std::make_shared<TcpServer>();
if(ssl){
rtmp_server[ssl]->start<TcpSessionWithSSL<RtmpSession> >(port);
rtmp_server[ssl]->start<SessionWithSSL<RtmpSession> >(port);
}else{
rtmp_server[ssl]->start<RtmpSession>(port);
}
......
......@@ -109,19 +109,19 @@ API_EXPORT uint16_t API_CALL mk_sock_info_local_port(const mk_sock_info ctx){
////////////////////////////////////////////////////////////////////////////////////////
API_EXPORT mk_sock_info API_CALL mk_tcp_session_get_sock_info(const mk_tcp_session ctx){
assert(ctx);
TcpSessionForC *session = (TcpSessionForC *)ctx;
SessionForC *session = (SessionForC *)ctx;
return (SockInfo *)session;
}
API_EXPORT void API_CALL mk_tcp_session_shutdown(const mk_tcp_session ctx,int err,const char *err_msg){
assert(ctx);
TcpSessionForC *session = (TcpSessionForC *)ctx;
SessionForC *session = (SessionForC *)ctx;
session->safeShutdown(SockException((ErrCode)err,err_msg));
}
API_EXPORT void API_CALL mk_tcp_session_send_buffer(const mk_tcp_session ctx, mk_buffer buffer) {
assert(ctx && buffer);
TcpSessionForC *session = (TcpSessionForC *) ctx;
SessionForC *session = (SessionForC *) ctx;
session->send(*((Buffer::Ptr *) buffer));
}
......@@ -134,9 +134,9 @@ API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx, const cha
API_EXPORT void API_CALL mk_tcp_session_send_buffer_safe(const mk_tcp_session ctx, mk_buffer buffer) {
assert(ctx && buffer);
try {
std::weak_ptr<TcpSession> weak_session = ((TcpSessionForC *) ctx)->shared_from_this();
std::weak_ptr<Session> weak_session = ((SessionForC *) ctx)->shared_from_this();
auto ref = mk_buffer_ref(buffer);
((TcpSessionForC *) ctx)->async([weak_session, ref]() {
((SessionForC *) ctx)->async([weak_session, ref]() {
auto session_session = weak_session.lock();
if (session_session) {
session_session->send(*((Buffer::Ptr *) ref));
......@@ -149,16 +149,16 @@ API_EXPORT void API_CALL mk_tcp_session_send_buffer_safe(const mk_tcp_session ct
}
API_EXPORT mk_tcp_session_ref API_CALL mk_tcp_session_ref_from(const mk_tcp_session ctx) {
auto ref = ((TcpSessionForC *) ctx)->shared_from_this();
return new std::shared_ptr<TcpSessionForC>(std::dynamic_pointer_cast<TcpSessionForC>(ref));
auto ref = ((SessionForC *) ctx)->shared_from_this();
return new std::shared_ptr<SessionForC>(std::dynamic_pointer_cast<SessionForC>(ref));
}
API_EXPORT void mk_tcp_session_ref_release(const mk_tcp_session_ref ref) {
delete (std::shared_ptr<TcpSessionForC> *) ref;
delete (std::shared_ptr<SessionForC> *) ref;
}
API_EXPORT mk_tcp_session mk_tcp_session_from_ref(const mk_tcp_session_ref ref) {
return ((std::shared_ptr<TcpSessionForC> *) ref)->get();
return ((std::shared_ptr<SessionForC> *) ref)->get();
}
API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx, const char *data, size_t len) {
......@@ -167,30 +167,30 @@ API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx, cons
mk_buffer_unref(buffer);
}
////////////////////////////////////////TcpSessionForC////////////////////////////////////////////////
////////////////////////////////////////SessionForC////////////////////////////////////////////////
static TcpServer::Ptr s_tcp_server[4];
static mk_tcp_session_events s_events_server = {0};
TcpSessionForC::TcpSessionForC(const Socket::Ptr &pSock) : TcpSession(pSock) {
SessionForC::SessionForC(const Socket::Ptr &pSock) : Session(pSock) {
_local_port = get_local_port();
if (s_events_server.on_mk_tcp_session_create) {
s_events_server.on_mk_tcp_session_create(_local_port,this);
}
}
void TcpSessionForC::onRecv(const Buffer::Ptr &buffer) {
void SessionForC::onRecv(const Buffer::Ptr &buffer) {
if (s_events_server.on_mk_tcp_session_data) {
s_events_server.on_mk_tcp_session_data(_local_port, this, (mk_buffer)&buffer);
}
}
void TcpSessionForC::onError(const SockException &err) {
void SessionForC::onError(const SockException &err) {
if (s_events_server.on_mk_tcp_session_disconnect) {
s_events_server.on_mk_tcp_session_disconnect(_local_port,this, err.getErrCode(), err.what());
}
}
void TcpSessionForC::onManager() {
void SessionForC::onManager() {
if (s_events_server.on_mk_tcp_session_manager) {
s_events_server.on_mk_tcp_session_manager(_local_port,this);
}
......@@ -202,13 +202,13 @@ void stopAllTcpServer(){
API_EXPORT void API_CALL mk_tcp_session_set_user_data(mk_tcp_session session,void *user_data){
assert(session);
TcpSessionForC *obj = (TcpSessionForC *)session;
SessionForC *obj = (SessionForC *)session;
obj->_user_data = user_data;
}
API_EXPORT void* API_CALL mk_tcp_session_get_user_data(mk_tcp_session session){
assert(session);
TcpSessionForC *obj = (TcpSessionForC *)session;
SessionForC *obj = (SessionForC *)session;
return obj->_user_data;
}
......@@ -226,18 +226,18 @@ API_EXPORT uint16_t API_CALL mk_tcp_server_start(uint16_t port, mk_tcp_type type
s_tcp_server[type] = std::make_shared<TcpServer>();
switch (type) {
case mk_type_tcp:
s_tcp_server[type]->start<TcpSessionForC>(port);
s_tcp_server[type]->start<SessionForC>(port);
break;
case mk_type_ssl:
s_tcp_server[type]->start<TcpSessionWithSSL<TcpSessionForC> >(port);
s_tcp_server[type]->start<SessionWithSSL<SessionForC> >(port);
break;
case mk_type_ws:
//此处你也可以修改WebSocketHeader::BINARY
s_tcp_server[type]->start<WebSocketSession<TcpSessionForC, HttpSession, WebSocketHeader::TEXT> >(port);
s_tcp_server[type]->start<WebSocketSession<SessionForC, HttpSession, WebSocketHeader::TEXT> >(port);
break;
case mk_type_wss:
//此处你也可以修改WebSocketHeader::BINARY
s_tcp_server[type]->start<WebSocketSession<TcpSessionForC, HttpsSession, WebSocketHeader::TEXT> >(port);
s_tcp_server[type]->start<WebSocketSession<SessionForC, HttpsSession, WebSocketHeader::TEXT> >(port);
break;
default:
return 0;
......@@ -295,7 +295,7 @@ TcpClientForC::Ptr *mk_tcp_client_create_l(mk_tcp_client_events *events, mk_tcp_
case mk_type_tcp:
return new TcpClientForC::Ptr(new TcpClientForC(events));
case mk_type_ssl:
return (TcpClientForC::Ptr *)new std::shared_ptr<TcpSessionWithSSL<TcpClientForC> >(new TcpSessionWithSSL<TcpClientForC>(events));
return (TcpClientForC::Ptr *)new std::shared_ptr<SessionWithSSL<TcpClientForC> >(new SessionWithSSL<TcpClientForC>(events));
case mk_type_ws:
//此处你也可以修改WebSocketHeader::BINARY
return (TcpClientForC::Ptr *)new std::shared_ptr<WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, false> >(new WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, false>(events));
......
......@@ -13,7 +13,7 @@
#include "mk_tcp.h"
#include "Network/TcpClient.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
class TcpClientForC : public toolkit::TcpClient {
public:
......@@ -31,10 +31,10 @@ private:
mk_tcp_client _client;
};
class TcpSessionForC : public toolkit::TcpSession {
class SessionForC : public toolkit::Session {
public:
TcpSessionForC(const toolkit::Socket::Ptr &pSock) ;
~TcpSessionForC() override = default;
SessionForC(const toolkit::Socket::Ptr &pSock) ;
~SessionForC() override = default;
void onRecv(const toolkit::Buffer::Ptr &buffer) override ;
void onError(const toolkit::SockException &err) override;
void onManager() override;
......
......@@ -18,7 +18,7 @@ using namespace toolkit;
API_EXPORT mk_thread API_CALL mk_thread_from_tcp_session(mk_tcp_session ctx){
assert(ctx);
TcpSessionForC *obj = (TcpSessionForC *)ctx;
SessionForC *obj = (SessionForC *)ctx;
return obj->getPoller().get();
}
......
......@@ -348,7 +348,7 @@
"response": []
},
{
"name": "获取TcpSession列表(getAllSession)",
"name": "获取Session列表(getAllSession)",
"request": {
"method": "GET",
"header": [],
......
......@@ -854,7 +854,7 @@ void installWebApi() {
val["count_closed"] = count_closed;
});
//获取所有TcpSession列表信息
//获取所有Session列表信息
//可以根据本地端口和远端ip来筛选
//测试url(筛选某端口下的tcp会话) http://127.0.0.1/index/api/getAllSession?local_port=1935
api_regist("/index/api/getAllSession",[](API_ARGS_MAP){
......
......@@ -15,7 +15,7 @@
#include "Common/config.h"
#include "Common/MediaSource.h"
#include "Http/HttpRequester.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "Rtsp/RtspSession.h"
#include "Http/HttpSession.h"
#include "WebHook.h"
......
......@@ -11,7 +11,7 @@
#include "Util/util.h"
#include "Util/NoticeCenter.h"
#include "Network/sockutil.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "MediaSource.h"
#include "Common/config.h"
#include "Record/MP4Reader.h"
......
......@@ -181,7 +181,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
}
//拦截hls的播放请求
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender){
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,Session &sender){
//访问的hls.m3u8结尾,我们转换成kBroadcastMediaPlayed事件
Broadcast::AuthInvoker auth_invoker = [invoker](const string &err) {
//cookie有效期为kHlsCookieSecond
......@@ -236,7 +236,7 @@ public:
* 4、cookie中记录的url参数是否跟本次url参数一致,如果一致直接返回客户端错误码
* 5、触发kBroadcastHttpAccess事件
*/
static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
static void canAccessPath(Session &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
const function<void(const string &err_msg, const HttpServerCookie::Ptr &cookie)> &callback) {
//获取用户唯一id
auto uid = parser.Params();
......@@ -353,7 +353,7 @@ static string pathCat(const string &a, const string &b){
* @param file_path 文件绝对路径
* @param cb 回调对象
*/
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
static void accessFile(Session &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
bool is_hls = end_with(file_path, kHlsSuffix);
if (!is_hls && !File::fileExist(file_path.data())) {
//文件不存在且不是hls,那么直接返回404
......@@ -366,7 +366,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
replace(const_cast<string &>(media_info._streamid), kHlsSuffix, "");
}
weak_ptr<TcpSession> weakSession = sender.shared_from_this();
weak_ptr<Session> weakSession = sender.shared_from_this();
//判断是否有权限访问该文件
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
auto strongSession = weakSession.lock();
......@@ -456,7 +456,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
});
}
static string getFilePath(const Parser &parser,const MediaInfo &media_info, TcpSession &sender){
static string getFilePath(const Parser &parser,const MediaInfo &media_info, Session &sender){
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
GET_CONFIG(string, rootPath, Http::kRootPath);
GET_CONFIG_FUNC(StrCaseMap, virtualPathMap, Http::kVirtualPath, [](const string &str) {
......@@ -491,7 +491,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, TcpS
* @param parser http请求
* @param cb 回调对象
*/
void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const HttpFileManager::invoker &cb) {
void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFileManager::invoker &cb) {
auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl();
MediaInfo media_info(fullUrl);
auto file_path = getFilePath(parser, media_info, sender);
......
......@@ -14,7 +14,7 @@
#include "HttpBody.h"
#include "HttpCookie.h"
#include "Common/Parser.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "Util/function_traits.h"
namespace mediakit {
......@@ -54,7 +54,7 @@ public:
* @param parser http请求
* @param cb 回调对象
*/
static void onAccessPath(toolkit::TcpSession &sender, Parser &parser, const invoker &cb);
static void onAccessPath(toolkit::Session &sender, Parser &parser, const invoker &cb);
/**
* 获取mime值
......
......@@ -23,7 +23,7 @@ using namespace toolkit;
namespace mediakit {
HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
HttpSession::HttpSession(const Socket::Ptr &pSock) : Session(pSock) {
TraceP(this);
GET_CONFIG(uint32_t,keep_alive_sec,Http::kKeepAliveSecond);
pSock->setSendTimeOutSecond(keep_alive_sec);
......@@ -440,7 +440,7 @@ class AsyncSenderData {
public:
friend class AsyncSender;
typedef std::shared_ptr<AsyncSenderData> Ptr;
AsyncSenderData(const TcpSession::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
AsyncSenderData(const Session::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
_session = dynamic_pointer_cast<HttpSession>(session);
_body = body;
_close_when_complete = close_when_complete;
......@@ -675,7 +675,7 @@ std::string HttpSession::get_peer_ip() {
if(!forwarded_ip_header.empty() && !_parser.getHeader()[forwarded_ip_header].empty()){
return _parser.getHeader()[forwarded_ip_header];
}
return TcpSession::get_peer_ip();
return Session::get_peer_ip();
}
void HttpSession::Handle_Req_POST(ssize_t &content_len) {
......
......@@ -12,7 +12,7 @@
#define SRC_HTTP_HTTPSESSION_H_
#include <functional>
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "Rtmp/RtmpMediaSource.h"
#include "Rtmp/FlvMuxer.h"
#include "HttpRequestSplitter.h"
......@@ -24,7 +24,7 @@
namespace mediakit {
class HttpSession: public toolkit::TcpSession,
class HttpSession: public toolkit::Session,
public FlvMuxer,
public HttpRequestSplitter,
public WebSocketSplitter {
......@@ -139,7 +139,7 @@ private:
std::function<bool (const char *data,size_t len) > _contentCallBack;
};
using HttpsSession = toolkit::TcpSessionWithSSL<HttpSession>;
using HttpsSession = toolkit::SessionWithSSL<HttpSession>;
} /* namespace mediakit */
......
......@@ -27,18 +27,18 @@ public:
};
/**
* 该类实现了TcpSession派生类发送数据的截取
* 该类实现了Session派生类发送数据的截取
* 目的是发送业务数据前进行websocket协议的打包
*/
template <typename TcpSessionType>
class TcpSessionTypeImp : public TcpSessionType, public SendInterceptor{
template <typename SessionType>
class SessionTypeImp : public SessionType, public SendInterceptor{
public:
typedef std::shared_ptr<TcpSessionTypeImp> Ptr;
using Ptr = std::shared_ptr<SessionTypeImp>;
TcpSessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
TcpSessionType(pSock), _identifier(parent.getIdentifier()) {}
SessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
SessionType(pSock), _identifier(parent.getIdentifier()) {}
~TcpSessionTypeImp() {}
~SessionTypeImp() = default;
/**
* 设置发送数据截取回调函数
......@@ -58,7 +58,7 @@ protected:
if (_beforeSendCB) {
return _beforeSendCB(buf);
}
return TcpSessionType::send(std::move(buf));
return SessionType::send(std::move(buf));
}
std::string getIdentifier() const override {
......@@ -70,12 +70,12 @@ private:
onBeforeSendCB _beforeSendCB;
};
template <typename TcpSessionType>
class TcpSessionCreator {
template <typename SessionType>
class SessionCreator {
public:
//返回的TcpSession必须派生于SendInterceptor,可以返回null
toolkit::TcpSession::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
return std::make_shared<TcpSessionTypeImp<TcpSessionType> >(header,parent,pSock);
//返回的Session必须派生于SendInterceptor,可以返回null
toolkit::Session::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
return std::make_shared<SessionTypeImp<SessionType> >(header,parent,pSock);
}
};
......@@ -228,15 +228,15 @@ private:
std::string _payload_cache;
std::string _payload_section;
std::weak_ptr<toolkit::Server> _weak_server;
toolkit::TcpSession::Ptr _session;
toolkit::Session::Ptr _session;
Creator _creator;
};
template<typename TcpSessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
class WebSocketSession : public WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>{
template<typename SessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
class WebSocketSession : public WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>{
public:
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>(pSock){}
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>(pSock){}
virtual ~WebSocketSession(){}
};
......
......@@ -17,7 +17,7 @@ using namespace toolkit;
namespace mediakit {
RtmpSession::RtmpSession(const Socket::Ptr &sock) : TcpSession(sock) {
RtmpSession::RtmpSession(const Socket::Ptr &sock) : Session(sock) {
DebugP(this);
GET_CONFIG(uint32_t,keep_alive_sec,Rtmp::kKeepAliveSecond);
sock->setSendTimeOutSecond(keep_alive_sec);
......
......@@ -20,12 +20,12 @@
#include "RtmpMediaSourceImp.h"
#include "Util/util.h"
#include "Util/TimeTicker.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "Common/Stamp.h"
namespace mediakit {
class RtmpSession : public toolkit::TcpSession, public RtmpProtocol, public MediaSourceEvent {
class RtmpSession : public toolkit::Session, public RtmpProtocol, public MediaSourceEvent {
public:
using Ptr = std::shared_ptr<RtmpSession>;
......@@ -109,7 +109,7 @@ private:
/**
* 支持ssl加密的rtmp服务器
*/
using RtmpSessionWithSSL = toolkit::TcpSessionWithSSL<RtmpSession>;
using RtmpSessionWithSSL = toolkit::SessionWithSSL<RtmpSession>;
} /* namespace mediakit */
#endif /* SRC_RTMP_RTMPSESSION_H_ */
......@@ -13,7 +13,7 @@
#if defined(ENABLE_RTPPROXY)
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "RtpSplitter.h"
#include "RtpProcess.h"
#include "Util/TimeTicker.h"
......
......@@ -49,7 +49,7 @@ static unordered_map<string, weak_ptr<RtspSession> > g_mapGetter;
//对g_mapGetter上锁保护
static recursive_mutex g_mtxGetter;
RtspSession::RtspSession(const Socket::Ptr &sock) : TcpSession(sock) {
RtspSession::RtspSession(const Socket::Ptr &sock) : Session(sock) {
DebugP(this);
GET_CONFIG(uint32_t,keep_alive_sec,Rtsp::kKeepAliveSecond);
sock->setSendTimeOutSecond(keep_alive_sec);
......@@ -1078,7 +1078,7 @@ ssize_t RtspSession::send(Buffer::Ptr pkt){
// DebugP(this) << pkt->data();
// }
_bytes_usage += pkt->size();
return TcpSession::send(std::move(pkt));
return Session::send(std::move(pkt));
}
bool RtspSession::sendRtspResponse(const string &res_code, const std::initializer_list<string> &header, const string &sdp, const char *protocol) {
......
......@@ -18,7 +18,7 @@
#include "Util/util.h"
#include "Util/logger.h"
#include "Common/config.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
#include "Player/PlayerBase.h"
#include "RtpMultiCaster.h"
#include "RtspMediaSource.h"
......@@ -52,7 +52,7 @@ private:
Buffer::Ptr _rtp;
};
class RtspSession : public toolkit::TcpSession, public RtspSplitter, public RtpReceiver, public MediaSourceEvent {
class RtspSession : public toolkit::Session, public RtspSplitter, public RtpReceiver, public MediaSourceEvent {
public:
using Ptr = std::shared_ptr<RtspSession>;
using onGetRealm = std::function<void(const std::string &realm)>;
......@@ -62,7 +62,7 @@ public:
RtspSession(const toolkit::Socket::Ptr &sock);
virtual ~RtspSession();
////TcpSession override////
////Session override////
void onRecv(const toolkit::Buffer::Ptr &buf) override;
void onError(const toolkit::SockException &err) override;
void onManager() override;
......@@ -94,7 +94,7 @@ protected:
// 由于支持断连续推,存在OwnerPoller变更的可能
toolkit::EventPoller::Ptr getOwnerPoller(MediaSource &sender) override;
/////TcpSession override////
/////Session override////
ssize_t send(toolkit::Buffer::Ptr pkt) override;
//收到RTCP包回调
virtual void onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *data, size_t len);
......@@ -225,7 +225,7 @@ private:
/**
* 支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问
*/
using RtspSessionWithSSL = toolkit::TcpSessionWithSSL<RtspSession>;
using RtspSessionWithSSL = toolkit::SessionWithSSL<RtspSession>;
} /* namespace mediakit */
......
......@@ -24,7 +24,7 @@ static onceToken s_token([]() {
REGIST_CMD(media);
}, nullptr);
ShellSession::ShellSession(const Socket::Ptr &_sock) : TcpSession(_sock) {
ShellSession::ShellSession(const Socket::Ptr &_sock) : Session(_sock) {
DebugP(this);
pleaseInputUser();
}
......
......@@ -14,11 +14,11 @@
#include <functional>
#include "Common/config.h"
#include "Util/TimeTicker.h"
#include "Network/TcpSession.h"
#include "Network/Session.h"
namespace mediakit {
class ShellSession: public toolkit::TcpSession {
class ShellSession: public toolkit::Session {
public:
ShellSession(const toolkit::Socket::Ptr &_sock);
virtual ~ShellSession();
......
......@@ -8,7 +8,7 @@ namespace SRT {
using namespace mediakit;
SrtSession::SrtSession(const Socket::Ptr &sock)
: UdpSession(sock) {
: Session(sock) {
socklen_t addr_len = sizeof(_peer_addr);
memset(&_peer_addr, 0, addr_len);
// TraceL<<"before addr len "<<addr_len;
......
......@@ -8,7 +8,7 @@ namespace SRT {
using namespace toolkit;
class SrtSession : public UdpSession {
class SrtSession : public Session {
public:
SrtSession(const Socket::Ptr &sock);
~SrtSession() override;
......
......@@ -22,9 +22,9 @@ using namespace mediakit;
/**
* 回显会话
*/
class EchoSession : public TcpSession {
class EchoSession : public Session {
public:
EchoSession(const Socket::Ptr &pSock) : TcpSession(pSock){
EchoSession(const Socket::Ptr &pSock) : Session(pSock){
DebugL;
}
virtual ~EchoSession(){
......@@ -32,7 +32,7 @@ public:
}
void attachServer(const Server &server) override{
DebugL << getIdentifier() << " " << TcpSession::getIdentifier();
DebugL << getIdentifier() << " " << Session::getIdentifier();
}
void onRecv(const Buffer::Ptr &buffer) override {
//回显数据
......@@ -49,9 +49,9 @@ public:
};
class EchoSessionWithUrl : public TcpSession {
class EchoSessionWithUrl : public Session {
public:
EchoSessionWithUrl(const Socket::Ptr &pSock) : TcpSession(pSock){
EchoSessionWithUrl(const Socket::Ptr &pSock) : Session(pSock){
DebugL;
}
virtual ~EchoSessionWithUrl(){
......@@ -59,7 +59,7 @@ public:
}
void attachServer(const Server &server) override{
DebugL << getIdentifier() << " " << TcpSession::getIdentifier();
DebugL << getIdentifier() << " " << Session::getIdentifier();
}
void onRecv(const Buffer::Ptr &buffer) override {
//回显数据
......@@ -80,13 +80,13 @@ public:
* 此对象可以根据websocket 客户端访问的url选择创建不同的对象
*/
struct EchoSessionCreator {
//返回的TcpSession必须派生于SendInterceptor,可以返回null(拒绝连接)
TcpSession::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) {
//返回的Session必须派生于SendInterceptor,可以返回null(拒绝连接)
Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) {
// return nullptr;
if (header.Url() == "/") {
return std::make_shared<TcpSessionTypeImp<EchoSession> >(header, parent, pSock);
return std::make_shared<SessionTypeImp<EchoSession> >(header, parent, pSock);
}
return std::make_shared<TcpSessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock);
return std::make_shared<SessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock);
}
};
......@@ -107,7 +107,7 @@ int main(int argc, char *argv[]) {
httpsSrv->start<WebSocketSessionBase<EchoSessionCreator, HttpsSession> >(443);//默认443
TcpServer::Ptr httpSrvOld(new TcpServer());
//兼容之前的代码(但是不支持根据url选择生成TcpSession类型)
//兼容之前的代码(但是不支持根据url选择生成Session类型)
httpSrvOld->start<WebSocketSession<EchoSession, HttpSession> >(8080);
DebugL << "请打开网页:http://www.websocket-test.com/,进行测试";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论