1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #913, Kernel MP4 FLV HTTP support complex error.

This commit is contained in:
winlin 2017-12-31 12:11:48 +08:00
parent 9802dc326e
commit 204ef041da
23 changed files with 1413 additions and 1660 deletions

View file

@ -129,16 +129,17 @@ srs_error_t srs_go_http_error(ISrsHttpResponseWriter* w, int code)
srs_error_t srs_go_http_error(ISrsHttpResponseWriter* w, int code, string error)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
w->header()->set_content_type("text/plain; charset=utf-8");
w->header()->set_content_length(error.length());
w->write_header(code);
if ((ret = w->write((char*)error.data(), (int)error.length())) != ERROR_SUCCESS) {
return srs_error_new(ret, "http write");
if ((err = w->write((char*)error.data(), (int)error.length())) != srs_success) {
return srs_error_wrap(err, "http write");
}
return srs_success;
return err;
}
SrsHttpHeader::SrsHttpHeader()
@ -330,14 +331,13 @@ srs_error_t SrsHttpFileServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
srs_error_t SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
// open the target file.
SrsFileReader fs;
if ((ret = fs.open(fullpath)) != ERROR_SUCCESS) {
return srs_error_new(ret, "open file %s", fullpath.c_str());
if ((err = fs.open(fullpath)) != srs_success) {
return srs_error_wrap(err, "open file %s", fullpath.c_str());
}
int64_t length = fs.filesize();
@ -397,8 +397,8 @@ srs_error_t SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, ISrsHttpMes
return srs_error_wrap(err, "copy file=%s size=%d", fullpath.c_str(), left);
}
if ((ret = w->final_request()) != ERROR_SUCCESS) {
return srs_error_new(ret, "final request");
if ((err = w->final_request()) != srs_success) {
return srs_error_wrap(err, "final request");
}
return err;
@ -468,7 +468,7 @@ srs_error_t SrsHttpFileServer::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsH
srs_error_t SrsHttpFileServer::copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, ISrsHttpMessage* r, int size)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
int left = size;
char* buf = r->http_ts_send_buffer();
@ -476,21 +476,21 @@ srs_error_t SrsHttpFileServer::copy(ISrsHttpResponseWriter* w, SrsFileReader* fs
while (left > 0) {
ssize_t nread = -1;
int max_read = srs_min(left, SRS_HTTP_TS_SEND_BUFFER_SIZE);
if ((ret = fs->read(buf, max_read, &nread)) != ERROR_SUCCESS) {
if ((err = fs->read(buf, max_read, &nread)) != srs_success) {
break;
}
left -= nread;
if ((ret = w->write(buf, (int)nread)) != ERROR_SUCCESS) {
if ((err = w->write(buf, (int)nread)) != srs_success) {
break;
}
}
if (ret != ERROR_SUCCESS) {
return srs_error_new(ret, "copy");
if (err != srs_success) {
return srs_error_wrap(err, "copy");
}
return srs_success;
return err;
}
SrsHttpMuxEntry::SrsHttpMuxEntry()
@ -765,7 +765,7 @@ srs_error_t SrsHttpCorsMux::initialize(ISrsHttpServeMux* worker, bool cros_enabl
srs_error_t SrsHttpCorsMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
// If CORS enabled, and there is a "Origin" header, it's CORS.
if (enabled) {
@ -795,8 +795,8 @@ srs_error_t SrsHttpCorsMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
} else {
w->write_header(SRS_CONSTS_HTTP_MethodNotAllowed);
}
if ((ret = w->final_request()) != ERROR_SUCCESS) {
return srs_error_new(ret, "final request");
if ((err = w->final_request()) != srs_success) {
return srs_error_wrap(err, "final request");
}
}

View file

@ -180,7 +180,7 @@ public:
// final the request to complete the chunked encoding.
// for no-chunked mode,
// final to send request, for example, content-length is 0.
virtual int final_request() = 0;
virtual srs_error_t final_request() = 0;
// Header returns the header map that will be sent by WriteHeader.
// Changing the header after a call to WriteHeader (or Write) has
@ -193,12 +193,12 @@ public:
// Content-Type line, Write adds a Content-Type set to the result of passing
// the initial 512 bytes of written data to DetectContentType.
// @param data, the data to send. NULL to flush header only.
virtual int write(char* data, int size) = 0;
virtual srs_error_t write(char* data, int size) = 0;
/**
* for the HTTP FLV, to writev to improve performance.
* @see https://github.com/ossrs/srs/issues/405
*/
virtual int writev(const iovec* iov, int iovcnt, ssize_t* pnwrite) = 0;
virtual srs_error_t writev(const iovec* iov, int iovcnt, ssize_t* pnwrite) = 0;
// WriteHeader sends an HTTP response header with status code.
// If WriteHeader is not called explicitly, the first call to Write
@ -235,7 +235,7 @@ public:
* or by chunked), because the sdk never know whether there is no data or
* infinite chunked.
*/
virtual int read(char* data, int nb_data, int* nb_read) = 0;
virtual srs_error_t read(char* data, int nb_data, int* nb_read) = 0;
};
// Objects implementing the Handler interface can be
@ -538,12 +538,12 @@ public:
* which is chunked encoding without chunked header.
* @remark error when message is in chunked or content-length specified.
*/
virtual int enter_infinite_chunked() = 0;
virtual srs_error_t enter_infinite_chunked() = 0;
/**
* read body to string.
* @remark for small http body.
*/
virtual int body_read_all(std::string& body) = 0;
virtual srs_error_t body_read_all(std::string& body) = 0;
/**
* get the body reader, to read one by one.
* @remark when body is very large, or chunked, use this.

View file

@ -1104,7 +1104,7 @@ int SrsKafkaProducerPartitionMessages::decode(SrsBuffer* buf)
// for the message set decode util empty, we must create a new buffer when
// there exists other objects after message set.
if (buf->size() - buf->pos() != message_set_size) {
if (buf->left() != message_set_size) {
SrsBuffer* tbuf = new SrsBuffer();
SrsAutoFree(SrsBuffer, tbuf);