add mixedsession

This commit is contained in:
aozhiwei 2018-10-09 11:57:04 +08:00
parent 65a4c6cc8f
commit a7613d51be
3 changed files with 85 additions and 0 deletions

60
a8/mixedsession.cc Normal file
View File

@ -0,0 +1,60 @@
#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <netinet/tcp.h>
#include <a8/a8.h>
#include <a8/openssl.h>
#include <a8/mixedsession.h>
namespace a8
{
static bool IsHttpHead(char* buf, int buflen)
{
return (buflen > 4 && strncmp("GET ", buf, 4)) ||
(buflen > 4 && strncmp("get ", buf, 4)) ||
(buflen > 5 && strncmp("POST ", buf, 5)) ||
(buflen > 5 && strncmp("post ", buf, 5));
}
void MixedSession::Reset()
{
a8::BaseHttpSession::Reset();
is_first_packet_ = true;
}
void MixedSession::Destory()
{
a8::TcpSession::Destory();
is_first_packet_ = true;
}
void MixedSession::DecodePacket(char* buf, int& offset, unsigned int buflen)
{
if (is_first_packet_) {
if (IsHttpHead(buf, buflen)) {
buf[buflen] = '\0';
ProcessHandShake(buf, offset, buflen);
} else {
DecodeUserPacket(buf, offset, buflen);
}
is_first_packet_ = offset == 0;
} else {
DecodeUserPacket(buf, offset, buflen);
}
}
void MixedSession::ProcessHandShake(char* buf, int& offset, unsigned int buflen)
{
char* pend = strstr(buf + offset, "\r\n\r\n");
if (!pend) {
return;
}
ProcessHttpHandShake(buf, offset, buflen);
}
}

24
a8/mixedsession.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef A8_MIXEDSESSION_H
#define A8_MIXEDSESSION_H
#include <a8/basehttpsession.h>
namespace a8
{
class MixedSession: public BaseHttpSession
{
protected:
virtual void Reset() override;
virtual void Destory() override;
virtual void DecodePacket(char* buf, int& offset, unsigned int buflen) override;
void ProcessHandShake(char* buf, int& offset, unsigned int buflen);
private:
bool is_first_packet_ = true;
};
}
#endif

View File

@ -141,6 +141,7 @@ namespace a8
bot_node_ = NULL;
work_node_ = NULL;
socket_handle = 0;
recv_bufflen_ = 0;
}
void TcpSession::Destory()