mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
优化http服务器性能
This commit is contained in:
parent
ddd4f57fe8
commit
a97b7ce701
@ -355,7 +355,7 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_GET() {
|
||||
//send completed!
|
||||
//FatalL << "send completed!";
|
||||
if(iRead>0) {
|
||||
strongSelf->send(pacSendBuf.get(), iRead);
|
||||
strongSelf->sock->send(pacSendBuf.get(), iRead,SOCKET_DEFAULE_FLAGS | FLAG_MORE);
|
||||
}
|
||||
if(bClose) {
|
||||
strongSelf->shutdown();
|
||||
@ -363,7 +363,7 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_GET() {
|
||||
return false;
|
||||
}
|
||||
|
||||
int iSent=strongSelf->send(pacSendBuf.get(), iRead);
|
||||
int iSent = strongSelf->sock->send(pacSendBuf.get(), iRead,SOCKET_DEFAULE_FLAGS | FLAG_MORE);
|
||||
if(iSent == -1) {
|
||||
//send error
|
||||
//FatalL << "send error";
|
||||
@ -378,6 +378,8 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_GET() {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
//关闭tcp_nodelay ,优化性能
|
||||
SockUtil::setNoDelay(sock->rawFD(),false);
|
||||
onFlush();
|
||||
sock->setOnFlush(onFlush);
|
||||
return Http_success;
|
||||
@ -594,7 +596,7 @@ void HttpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
|
||||
CLEAR_ARR(m_aui32FirstStamp);
|
||||
modifiedStamp = 0;
|
||||
}
|
||||
sendRtmp(pkt->typeId, pkt->strBuf, modifiedStamp);
|
||||
sendRtmp(pkt, modifiedStamp);
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
@ -614,17 +616,44 @@ public:
|
||||
#pragma pack(pop)
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
class BufferRtmp : public Socket::Buffer{
|
||||
public:
|
||||
typedef std::shared_ptr<BufferRtmp> Ptr;
|
||||
BufferRtmp(const RtmpPacket::Ptr & pkt):_rtmp(pkt){}
|
||||
virtual ~BufferRtmp(){}
|
||||
|
||||
char *data() override {
|
||||
return (char *)_rtmp->strBuf.data();
|
||||
}
|
||||
uint32_t size() const override {
|
||||
return _rtmp->strBuf.size();
|
||||
}
|
||||
private:
|
||||
RtmpPacket::Ptr _rtmp;
|
||||
};
|
||||
|
||||
void HttpSession::sendRtmp(const RtmpPacket::Ptr &pkt, uint32_t ui32TimeStamp) {
|
||||
auto size = htonl(m_previousTagSize);
|
||||
send((char *)&size,4);//send PreviousTagSize
|
||||
RtmpTagHeader header;
|
||||
header.type = pkt->typeId;
|
||||
set_be24(header.data_size, pkt->strBuf.size());
|
||||
header.timestamp_ex = (uint8_t) ((ui32TimeStamp >> 24) & 0xff);
|
||||
set_be24(header.timestamp,ui32TimeStamp & 0xFFFFFF);
|
||||
send((char *)&header, sizeof(header));//send tag header
|
||||
send(std::make_shared<BufferRtmp>(pkt));//send tag data
|
||||
m_previousTagSize += (pkt->strBuf.size() + sizeof(header) + 4);
|
||||
m_ticker.resetTime();
|
||||
}
|
||||
|
||||
void HttpSession::sendRtmp(uint8_t ui8Type, const std::string& strBuf, uint32_t ui32TimeStamp) {
|
||||
auto size = htonl(m_previousTagSize);
|
||||
send((char *)&size,4);//send PreviousTagSize
|
||||
|
||||
RtmpTagHeader header;
|
||||
header.type = ui8Type;
|
||||
set_be24(header.data_size, strBuf.size());
|
||||
|
||||
header.timestamp_ex = (uint8_t) ((ui32TimeStamp >> 24) & 0xff);
|
||||
set_be24(header.timestamp,ui32TimeStamp & 0xFFFFFF);
|
||||
|
||||
send((char *)&header, sizeof(header));//send tag header
|
||||
send(strBuf);//send tag data
|
||||
m_previousTagSize += (strBuf.size() + sizeof(header) + 4);
|
||||
|
@ -78,6 +78,7 @@ private:
|
||||
uint32_t m_previousTagSize = 0;
|
||||
RingBuffer<RtmpPacket::Ptr>::RingReader::Ptr m_pRingReader;
|
||||
void onSendMedia(const RtmpPacket::Ptr &pkt);
|
||||
void sendRtmp(const RtmpPacket::Ptr &pkt, uint32_t ui32TimeStamp);
|
||||
void sendRtmp(uint8_t ui8Type, const std::string& strBuf, uint32_t ui32TimeStamp);
|
||||
|
||||
inline HttpCode parserHttpReq(const string &);
|
||||
|
@ -121,7 +121,7 @@ int domain(int argc, const char *argv[]) {
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
const char *argList[] = {argv[0],"rtmp://live.hkstv.hk.lxdns.com/live/hks","rtmp://jizan.iok.la/live/test"};
|
||||
const char *argList[] = {argv[0],"rtmp://live.hkstv.hk.lxdns.com/live/hks",argv[1]};
|
||||
return domain(3,argList);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user