mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-16 13:05:59 +08:00
Http服务改成异步回复模式
This commit is contained in:
@@ -11,16 +11,23 @@
|
||||
#include "config.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Network/TcpLimitedSession.h"
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
using namespace ZL::Network;
|
||||
using namespace ZL::Network;
|
||||
|
||||
namespace ZL {
|
||||
namespace Http {
|
||||
|
||||
|
||||
class HttpSession: public TcpLimitedSession<MAX_TCP_SESSION> {
|
||||
public:
|
||||
typedef map<string,string> KeyValue;
|
||||
typedef std::function<void(const string &codeOut,
|
||||
const KeyValue &headerOut,
|
||||
const string &contentOut)> HttpResponseInvoker;
|
||||
|
||||
HttpSession(const std::shared_ptr<ThreadPool> &pTh, const Socket::Ptr &pSock);
|
||||
virtual ~HttpSession();
|
||||
|
||||
@@ -28,21 +35,30 @@ public:
|
||||
void onError(const SockException &err) override;
|
||||
void onManager() override;
|
||||
private:
|
||||
typedef int (HttpSession::*HttpCMDHandle)();
|
||||
typedef enum
|
||||
{
|
||||
Http_success = 0,
|
||||
Http_failed = 1,
|
||||
Http_moreData = 2,
|
||||
} HttpCode;
|
||||
typedef HttpSession::HttpCode (HttpSession::*HttpCMDHandle)();
|
||||
static unordered_map<string, HttpCMDHandle> g_mapCmdIndex;
|
||||
|
||||
Parser m_parser;
|
||||
string m_strPath;
|
||||
string m_strRcvBuf;
|
||||
Ticker m_ticker;
|
||||
uint32_t m_iReqCnt = 0;
|
||||
|
||||
inline int parserHttpReq(const string &);
|
||||
inline int Handle_Req_GET();
|
||||
inline int Handle_Req_POST();
|
||||
|
||||
inline HttpCode parserHttpReq(const string &);
|
||||
inline HttpCode Handle_Req_GET();
|
||||
inline HttpCode Handle_Req_POST();
|
||||
inline bool makeMeun(const string &strFullPath, string &strRet);
|
||||
inline void sendNotFound(bool bClose);
|
||||
inline void sendResponse(const char *pcStatus,const KeyValue &header,const string &strContent);
|
||||
inline KeyValue makeHttpHeader(bool bClose=false,int64_t iContentSize=-1,const char *pcContentType="text/html");
|
||||
inline static KeyValue makeHttpHeader(bool bClose=false,int64_t iContentSize=-1,const char *pcContentType="text/html");
|
||||
void responseDelay(bool bClose,string &codeOut,KeyValue &headerOut, string &contentOut);
|
||||
};
|
||||
|
||||
} /* namespace Http */
|
||||
|
||||
Reference in New Issue
Block a user