Skip to content

Commit 4181ca4

Browse files
authored
Merge pull request #623 from bryghtlabs-richard/feat/sh2lib/splitSendRecv
feat(sh2lib): distinct recv and send funcs (IEC-429)
2 parents 9f3f581 + 2e3f5e5 commit 4181ca4

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

sh2lib/sh2lib.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,49 @@ void sh2lib_free(struct sh2lib_handle *hd)
328328
int sh2lib_execute(struct sh2lib_handle *hd)
329329
{
330330
int ret;
331-
ret = nghttp2_session_send(hd->http2_sess);
331+
ret = sh2lib_execute_send(hd);
332332
if (ret != 0) {
333-
ESP_LOGE(TAG, "[sh2-execute] HTTP2 session send failed %d", ret);
334333
return ret;
335334
}
336335

337-
ret = nghttp2_session_recv(hd->http2_sess);
336+
ret = sh2lib_execute_recv(hd);
338337
if (ret != 0) {
339-
ESP_LOGE(TAG, "[sh2-execute] HTTP2 session recv failed %d", ret);
340338
return ret;
341339
}
342340

343341
return 0;
344342
}
345343

344+
int sh2lib_execute_recv(struct sh2lib_handle *hd)
345+
{
346+
if (hd == NULL) {
347+
ESP_LOGE(TAG, "[sh2-execute-recv] pointer to sh2lib handle cannot be NULL");
348+
return -1;
349+
}
350+
351+
int ret = nghttp2_session_recv(hd->http2_sess);
352+
if (ret != 0) {
353+
ESP_LOGE(TAG, "[sh2-execute-recv] HTTP2 session recv failed %d", ret);
354+
}
355+
356+
return ret;
357+
}
358+
359+
int sh2lib_execute_send(struct sh2lib_handle *hd)
360+
{
361+
if (hd == NULL) {
362+
ESP_LOGE(TAG, "[sh2-execute-recv] pointer to sh2lib handle cannot be NULL");
363+
return -1;
364+
}
365+
366+
int ret = nghttp2_session_send(hd->http2_sess);
367+
if (ret != 0) {
368+
ESP_LOGE(TAG, "[sh2-execute-send] HTTP2 session send failed %d", ret);
369+
}
370+
371+
return ret;
372+
}
373+
346374
int sh2lib_do_get_with_nv(struct sh2lib_handle *hd, const nghttp2_nv *nva, size_t nvlen, sh2lib_frame_data_recv_cb_t recv_cb)
347375
{
348376
int ret = nghttp2_submit_request(hd->http2_sess, NULL, nva, nvlen, NULL, recv_cb);

sh2lib/sh2lib.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,38 @@ int sh2lib_do_put(struct sh2lib_handle *hd, const char *path,
203203
*/
204204
int sh2lib_execute(struct sh2lib_handle *hd);
205205

206+
/**
207+
* @brief Execute receive on an HTTP/2 connection
208+
*
209+
* While the API sh2lib_do_get(), sh2lib_do_post() setup the requests to be
210+
* initiated with the server, this API performs the actual data send/receive
211+
* operations on the HTTP/2 connection. The callback functions are accordingly
212+
* called during the processing of these requests.
213+
*
214+
* @param[in] hd Pointer to a variable of the type 'struct sh2lib_handle'
215+
*
216+
* @return
217+
* - 0 if it succeeds
218+
* - Negative error code from nghttp2 on failure
219+
*/
220+
int sh2lib_execute_recv(struct sh2lib_handle *hd);
221+
222+
/**
223+
* @brief Execute send on an HTTP/2 connection
224+
*
225+
* While the API sh2lib_do_get(), sh2lib_do_post() setup the requests to be
226+
* initiated with the server, this API performs the actual data send/receive
227+
* operations on the HTTP/2 connection. The callback functions are accordingly
228+
* called during the processing of these requests.
229+
*
230+
* @param[in] hd Pointer to a variable of the type 'struct sh2lib_handle'
231+
*
232+
* @return
233+
* - 0 if it succeeds
234+
* - Negative error code from nghttp2 on failure
235+
*/
236+
int sh2lib_execute_send(struct sh2lib_handle *hd);
237+
206238
#define SH2LIB_MAKE_NV(NAME, VALUE) \
207239
{ \
208240
(uint8_t *)NAME, (uint8_t *)VALUE, strlen(NAME), strlen(VALUE), \

0 commit comments

Comments
 (0)