Skip to content

Commit aebbbad

Browse files
committed
For #913, Service support complex error.
1 parent 15aea68 commit aebbbad

7 files changed

+151
-208
lines changed

trunk/src/protocol/srs_http_stack.cpp

+6-18
Original file line numberDiff line numberDiff line change
@@ -3028,22 +3028,19 @@ SrsHttpUri::~SrsHttpUri()
30283028
{
30293029
}
30303030

3031-
int SrsHttpUri::initialize(string _url)
3031+
srs_error_t SrsHttpUri::initialize(string _url)
30323032
{
3033-
int ret = ERROR_SUCCESS;
3033+
srs_error_t err = srs_success;
30343034

30353035
schema = host = path = query = "";
30363036

30373037
url = _url;
30383038
const char* purl = url.c_str();
30393039

30403040
http_parser_url hp_u;
3041-
if((ret = http_parser_parse_url(purl, url.length(), 0, &hp_u)) != 0){
3042-
int code = ret;
3043-
ret = ERROR_HTTP_PARSE_URI;
3044-
3045-
srs_error("parse url %s failed, code=%d, ret=%d", purl, code, ret);
3046-
return ret;
3041+
int r0;
3042+
if((r0 = http_parser_parse_url(purl, url.length(), 0, &hp_u)) != 0){
3043+
return srs_error_new(ERROR_HTTP_PARSE_URI, "parse url %s failed, code=%d", purl, r0);
30473044
}
30483045

30493046
std::string field = get_uri_field(url, &hp_u, UF_SCHEMA);
@@ -3062,12 +3059,9 @@ int SrsHttpUri::initialize(string _url)
30623059
}
30633060

30643061
path = get_uri_field(url, &hp_u, UF_PATH);
3065-
srs_info("parse url %s success", purl);
3066-
30673062
query = get_uri_field(url, &hp_u, UF_QUERY);
3068-
srs_info("parse query %s success", query.c_str());
30693063

3070-
return ret;
3064+
return err;
30713065
}
30723066

30733067
string SrsHttpUri::get_url()
@@ -3106,12 +3100,6 @@ string SrsHttpUri::get_uri_field(string uri, http_parser_url* hp_u, http_parser_
31063100
return "";
31073101
}
31083102

3109-
srs_verbose("uri field matched, off=%d, len=%d, value=%.*s",
3110-
hp_u->field_data[field].off,
3111-
hp_u->field_data[field].len,
3112-
hp_u->field_data[field].len,
3113-
uri.c_str() + hp_u->field_data[field].off);
3114-
31153103
int offset = hp_u->field_data[field].off;
31163104
int len = hp_u->field_data[field].len;
31173105

trunk/src/protocol/srs_http_stack.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ class SrsHttpUri
900900
/**
901901
* initialize the http uri.
902902
*/
903-
virtual int initialize(std::string _url);
903+
virtual srs_error_t initialize(std::string _url);
904904
public:
905905
virtual std::string get_url();
906906
virtual std::string get_schema();

trunk/src/service/srs_service_http_client.cpp

+10-16
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ SrsHttpClient::~SrsHttpClient()
5555
// TODO: FIXME: use ms for timeout.
5656
srs_error_t SrsHttpClient::initialize(string h, int p, int64_t tm)
5757
{
58-
int ret = ERROR_SUCCESS;
5958
srs_error_t err = srs_success;
6059

6160
srs_freep(parser);
6261
parser = new SrsHttpParser();
6362

64-
if ((ret = parser->initialize(HTTP_RESPONSE, false)) != ERROR_SUCCESS) {
65-
return srs_error_new(ret, "http: init parser");
63+
if ((err = parser->initialize(HTTP_RESPONSE, false)) != srs_success) {
64+
return srs_error_wrap(err, "http: init parser");
6665
}
6766

6867
// Always disconnect the transport.
@@ -97,7 +96,6 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg
9796
{
9897
*ppmsg = NULL;
9998

100-
int ret = ERROR_SUCCESS;
10199
srs_error_t err = srs_success;
102100

103101
// always set the content length.
@@ -119,15 +117,15 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg
119117
ss << SRS_HTTP_CRLF << req;
120118

121119
std::string data = ss.str();
122-
if ((ret = transport->write((void*)data.c_str(), data.length(), NULL)) != ERROR_SUCCESS) {
120+
if ((err = transport->write((void*)data.c_str(), data.length(), NULL)) != srs_success) {
123121
// Disconnect the transport when channel error, reconnect for next operation.
124122
disconnect();
125-
return srs_error_new(ret, "http: write");
123+
return srs_error_wrap(err, "http: write");
126124
}
127125

128126
ISrsHttpMessage* msg = NULL;
129-
if ((ret = parser->parse_message(transport, NULL, &msg)) != ERROR_SUCCESS) {
130-
return srs_error_new(ret, "http: parse response");
127+
if ((err = parser->parse_message(transport, NULL, &msg)) != srs_success) {
128+
return srs_error_wrap(err, "http: parse response");
131129
}
132130
srs_assert(msg);
133131

@@ -136,7 +134,6 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg
136134
} else {
137135
srs_freep(msg);
138136
}
139-
srs_info("parse http post response success.");
140137

141138
return err;
142139
}
@@ -145,7 +142,6 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg)
145142
{
146143
*ppmsg = NULL;
147144

148-
int ret = ERROR_SUCCESS;
149145
srs_error_t err = srs_success;
150146

151147
// always set the content length.
@@ -167,15 +163,15 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg)
167163
ss << SRS_HTTP_CRLF << req;
168164

169165
std::string data = ss.str();
170-
if ((ret = transport->write((void*)data.c_str(), data.length(), NULL)) != ERROR_SUCCESS) {
166+
if ((err = transport->write((void*)data.c_str(), data.length(), NULL)) != srs_success) {
171167
// Disconnect the transport when channel error, reconnect for next operation.
172168
disconnect();
173-
return srs_error_new(ret, "http: write");
169+
return srs_error_wrap(err, "http: write");
174170
}
175171

176172
ISrsHttpMessage* msg = NULL;
177-
if ((ret = parser->parse_message(transport, NULL, &msg)) != ERROR_SUCCESS) {
178-
return srs_error_new(ret, "http: parse response");
173+
if ((err = parser->parse_message(transport, NULL, &msg)) != srs_success) {
174+
return srs_error_wrap(err, "http: parse response");
179175
}
180176
srs_assert(msg);
181177

@@ -184,7 +180,6 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg)
184180
} else {
185181
srs_freep(msg);
186182
}
187-
srs_info("parse http get response success.");
188183

189184
return err;
190185
}
@@ -228,7 +223,6 @@ srs_error_t SrsHttpClient::connect()
228223
disconnect();
229224
return srs_error_wrap(err, "http: tcp connect %s:%d to=%d", host.c_str(), port, (int)timeout);
230225
}
231-
srs_info("connect to server success. server=%s, port=%d", host.c_str(), port);
232226

233227
// Set the recv/send timeout in ms.
234228
transport->set_recv_timeout(timeout);

0 commit comments

Comments
 (0)