Skip to content

Commit

Permalink
For #1657, handle on_message_done
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 5, 2020
1 parent 4b082ea commit c3d2900
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_caster_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* r, SrsHttpRespo
return srs_success;
}

srs_error_t SrsDynamicHttpConn::on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
{
return srs_success;
}

srs_error_t SrsDynamicHttpConn::on_conn_done(srs_error_t r0)
{
// Because we use manager to manage this object,
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_caster_flv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class SrsDynamicHttpConn : virtual public ISrsStartableConneciton, virtual publi
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_conn_done(srs_error_t r0);
// Interface ISrsResource.
public:
Expand Down
7 changes: 7 additions & 0 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,13 @@ srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* r, SrsHttpResponseWrite
//SrsHttpHeader* hdr = w->header();
//hdr->set("Connection", "Close");

return err;
}

srs_error_t SrsHttpApi::on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
{
srs_error_t err = srs_success;

// read all rest bytes in request body.
char buf[SRS_HTTP_READ_CACHE_BYTES];
ISrsHttpResponseReader* br = r->body_reader();
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_http_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class SrsHttpApi : virtual public ISrsStartableConneciton, virtual public ISrsHt
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_conn_done(srs_error_t r0);
// Interface ISrsResource.
public:
Expand Down
10 changes: 10 additions & 0 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ srs_error_t SrsHttpConn::do_cycle()
if ((err = process_request(&writer, req)) != srs_success) {
break;
}

// After the request is processed.
if ((err = handler_->on_message_done(req, &writer)) != srs_success) {
break;
}

// donot keep alive, disconnect it.
// @see https://github.com/ossrs/srs/issues/399
Expand Down Expand Up @@ -386,6 +391,11 @@ srs_error_t SrsResponseOnlyHttpConn::on_http_message(ISrsHttpMessage* r, SrsHttp
return err;
}

srs_error_t SrsResponseOnlyHttpConn::on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
{
return srs_success;
}

srs_error_t SrsResponseOnlyHttpConn::on_conn_done(srs_error_t r0)
{
// Because we use manager to manage this object,
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ISrsHttpConnOwner
// For the static service or api, discard any body.
// For the stream caster, for instance, http flv streaming, may discard the flv header or not.
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w) = 0;
// When message is processed, we may need to do more things.
virtual srs_error_t on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w) = 0;
// When connection is destroy, should use manager to dispose it.
// The r0 is the original error, we will use the returned new error.
virtual srs_error_t on_conn_done(srs_error_t r0) = 0;
Expand Down Expand Up @@ -171,6 +173,7 @@ class SrsResponseOnlyHttpConn : virtual public ISrsStartableConneciton, virtual
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_conn_done(srs_error_t r0);
// Extract APIs from SrsTcpConnection.
public:
Expand Down

0 comments on commit c3d2900

Please sign in to comment.