winlin

move the ts buffer to http message

... ... @@ -515,6 +515,7 @@ SrsHttpMessage::SrsHttpMessage()
_uri = new SrsHttpUri();
_match = NULL;
_requires_crossdomain = false;
_http_ts_send_buffer = new char[HTTP_TS_SEND_BUFFER_SIZE];
}
SrsHttpMessage::~SrsHttpMessage()
... ... @@ -522,6 +523,12 @@ SrsHttpMessage::~SrsHttpMessage()
srs_freep(_body);
srs_freep(_uri);
srs_freep(_match);
srs_freepa(_http_ts_send_buffer);
}
char* SrsHttpMessage::http_ts_send_buffer()
{
return _http_ts_send_buffer;
}
void SrsHttpMessage::reset()
... ...
... ... @@ -145,6 +145,9 @@ class SrsHttpHandler;
#define HTTP_GatewayTimeout_str "Gateway Timeout"
#define HTTP_HTTPVersionNotSupported_str "HTTP Version Not Supported"
// @see SrsHttpMessage._http_ts_send_buffer
#define HTTP_TS_SEND_BUFFER_SIZE 4096
// linux path seprator
#define __PATH_SEP '/'
// query string seprator
... ... @@ -310,10 +313,15 @@ private:
* whether the message requires crossdomain.
*/
bool _requires_crossdomain;
/**
* use a buffer to read and send ts file.
*/
char* _http_ts_send_buffer;
public:
SrsHttpMessage();
virtual ~SrsHttpMessage();
public:
virtual char* http_ts_send_buffer();
virtual void reset();
virtual int parse_uri();
public:
... ...
... ... @@ -195,14 +195,12 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
// write body.
int64_t left = length;
const static int HTTP_PKT_SIZE = 4096;
char* buf = new char[HTTP_PKT_SIZE];
SrsAutoFree(char, buf, true);
char* buf = req->http_ts_send_buffer();
while (left > 0) {
ssize_t nread = -1;
// TODO: FIXME: use st_read.
if ((nread = ::read(fd, buf, HTTP_PKT_SIZE)) < 0) {
if ((nread = ::read(fd, buf, HTTP_TS_SEND_BUFFER_SIZE)) < 0) {
::close(fd);
ret = ERROR_HTTP_READ_FILE;
srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
... ...