@@ -654,6 +654,8 @@ namespace LibHttp2 {
654654LIB_VERSION (" Http2" , 1 , " Http2" , 1 , 1 );
655655
656656constexpr int HTTP2_ERROR_INVALID_ID = -2122641152 ; /* 0x817B1100 */
657+ constexpr int HTTP2_ERROR_BEFORE_SEND = -2122641307 ; /* 0x817B1065 */
658+ constexpr int HTTP2_ERROR_TIMEOUT = -2122641304 ; /* 0x817B1068 */
657659constexpr int HTTP2_ERROR_NULL_POINTER = -2122640859 ; /* 0x817B1225 */
658660
659661struct Http2Options {
@@ -694,14 +696,14 @@ struct Http2Request {
694696 std::string url;
695697 uint64_t content_length = 0 ;
696698 std::vector<std::pair<std::string, std::string>> headers;
697- bool sent = false ;
698- int status_code = 204 ;
699- std::string response_headers = " HTTP/2 204 No Content \r\n\r\n " ;
700- std::string response_body;
701- size_t read_offset = 0 ;
702- int async_result = 0 ;
703- int async_event = 0 ;
704- Http2Options options;
699+ int send_result = HTTP2_ERROR_BEFORE_SEND ;
700+ int status_code = 0 ;
701+ std::string response_headers ;
702+ std::string response_body;
703+ size_t read_offset = 0 ;
704+ int async_result = HTTP2_ERROR_BEFORE_SEND ;
705+ int async_event = 0 ;
706+ Http2Options options;
705707};
706708
707709struct Http2AsyncResult {
@@ -1114,9 +1116,9 @@ static int KYTY_SYSV_ABI Http2SendRequest(int req_id, const void* post_data, siz
11141116 return HTTP2_ERROR_INVALID_ID ;
11151117 }
11161118
1117- request->second .sent = true ;
1119+ request->second .send_result = HTTP2_ERROR_TIMEOUT ;
11181120
1119- return 0 ;
1121+ return request-> second . send_result ;
11201122}
11211123
11221124static int KYTY_SYSV_ABI Http2SendRequestAsync (int req_id, const void * post_data, size_t size,
@@ -1136,8 +1138,8 @@ static int KYTY_SYSV_ABI Http2SendRequestAsync(int req_id, const void* post_data
11361138 return HTTP2_ERROR_INVALID_ID ;
11371139 }
11381140
1139- request->second .sent = true ;
1140- request->second .async_result = 0 ;
1141+ request->second .send_result = HTTP2_ERROR_TIMEOUT ;
1142+ request->second .async_result = request-> second . send_result ;
11411143 request->second .async_event = 0 ;
11421144
11431145 return 0 ;
@@ -1159,11 +1161,10 @@ static int KYTY_SYSV_ABI Http2WaitAsync(int req_id, Http2AsyncResult* result, ui
11591161 return HTTP2_ERROR_INVALID_ID ;
11601162 }
11611163
1162- request->second .sent = true ;
1163- *result = {};
1164- result->event_type = request->second .async_event ;
1165- result->req_id = req_id;
1166- result->result = request->second .async_result ;
1164+ *result = {};
1165+ result->event_type = request->second .async_event ;
1166+ result->req_id = req_id;
1167+ result->result = request->second .async_result ;
11671168
11681169 return 0 ;
11691170}
@@ -1178,13 +1179,19 @@ static int KYTY_SYSV_ABI Http2GetStatusCode(int req_id, int* status_code) {
11781179 return HTTP2_ERROR_NULL_POINTER ;
11791180 }
11801181
1182+ *status_code = 0 ;
1183+
11811184 auto request = g_http2_requests.find (req_id);
11821185 if (request == g_http2_requests.end ()) {
11831186 return HTTP2_ERROR_INVALID_ID ;
11841187 }
11851188
1186- *status_code = request->second .status_code ;
1189+ const int send_result = request->second .send_result ;
1190+ if (send_result != 0 ) {
1191+ return send_result;
1192+ }
11871193
1194+ *status_code = request->second .status_code ;
11881195 return 0 ;
11891196}
11901197
@@ -1200,14 +1207,21 @@ static int KYTY_SYSV_ABI Http2GetResponseContentLength(int req_id, int* result,
12001207 return HTTP2_ERROR_NULL_POINTER ;
12011208 }
12021209
1210+ *result = 0 ;
1211+ *content_length = 0 ;
1212+
12031213 auto request = g_http2_requests.find (req_id);
12041214 if (request == g_http2_requests.end ()) {
12051215 return HTTP2_ERROR_INVALID_ID ;
12061216 }
12071217
1208- *result = 0 ; // SCE_HTTP2_CONTENTLEN_EXIST
1209- *content_length = request->second .response_body .size ();
1218+ const int send_result = request->second .send_result ;
1219+ if (send_result != 0 ) {
1220+ *result = -1 ;
1221+ return send_result;
1222+ }
12101223
1224+ *content_length = request->second .response_body .size ();
12111225 return 0 ;
12121226}
12131227
@@ -1223,14 +1237,21 @@ static int KYTY_SYSV_ABI Http2GetAllResponseHeaders(int req_id, char** header,
12231237 return HTTP2_ERROR_NULL_POINTER ;
12241238 }
12251239
1240+ *header = nullptr ;
1241+ *header_size = 0 ;
1242+
12261243 auto request = g_http2_requests.find (req_id);
12271244 if (request == g_http2_requests.end ()) {
12281245 return HTTP2_ERROR_INVALID_ID ;
12291246 }
12301247
1248+ const int send_result = request->second .send_result ;
1249+ if (send_result != 0 ) {
1250+ return send_result;
1251+ }
1252+
12311253 *header = const_cast <char *>(request->second .response_headers .c_str ());
12321254 *header_size = request->second .response_headers .size ();
1233-
12341255 return 0 ;
12351256}
12361257
@@ -1250,6 +1271,11 @@ static int KYTY_SYSV_ABI Http2ReadData(int req_id, void* data, size_t size) {
12501271 return HTTP2_ERROR_INVALID_ID ;
12511272 }
12521273
1274+ const int send_result = request->second .send_result ;
1275+ if (send_result != 0 ) {
1276+ return send_result;
1277+ }
1278+
12531279 const auto & body = request->second .response_body ;
12541280 const auto remaining =
12551281 request->second .read_offset < body.size () ? body.size () - request->second .read_offset : 0 ;
@@ -1280,6 +1306,13 @@ static int KYTY_SYSV_ABI Http2ReadDataAsync(int req_id, void* data, size_t size,
12801306 return HTTP2_ERROR_INVALID_ID ;
12811307 }
12821308
1309+ const int send_result = request->second .send_result ;
1310+ if (send_result != 0 ) {
1311+ request->second .async_result = send_result;
1312+ request->second .async_event = 1 ;
1313+ return 0 ;
1314+ }
1315+
12831316 const auto & body = request->second .response_body ;
12841317 const auto remaining =
12851318 request->second .read_offset < body.size () ? body.size () - request->second .read_offset : 0 ;
0 commit comments