static void pingconn(evutil_socket_t s, short evt, void *raw) { session *sess = raw; if(nghttp2_submit_ping(sess->S.h2sess, NGHTTP2_FLAG_NONE, NULL) || nghttp2_session_send(sess->S.h2sess)) { fprintf(stderr, "Ping failed\n"); cleanup_session(&sess->S); } }
static void run_nghttp2_session_send(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"), MAKE_NV(":scheme", "https")}; nghttp2_data_provider data_prd; nghttp2_settings_entry iv[2]; my_user_data ud; int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024; iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 4096; iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; iv[1].value = 100; rv = nghttp2_session_client_new3(&session, &callbacks, &ud, NULL, nghttp2_mem_fm()); if (rv != 0) { goto client_new_fail; } rv = nghttp2_submit_request(session, NULL, nv, ARRLEN(nv), &data_prd, NULL); if (rv < 0) { goto fail; } rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, nv, ARRLEN(nv), NULL); if (rv < 0) { goto fail; } rv = nghttp2_session_send(session); if (rv != 0) { goto fail; } /* The HEADERS submitted by the previous nghttp2_submit_headers will have stream ID 3. Send HEADERS to that stream. */ rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, NULL, nv, ARRLEN(nv), NULL); if (rv != 0) { goto fail; } rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd); if (rv != 0) { goto fail; } rv = nghttp2_session_send(session); if (rv != 0) { goto fail; } rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 3, NGHTTP2_CANCEL); if (rv != 0) { goto fail; } rv = nghttp2_session_send(session); if (rv != 0) { goto fail; } /* Sending against half-closed stream */ rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, NULL, nv, ARRLEN(nv), NULL); if (rv != 0) { goto fail; } rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd); if (rv != 0) { goto fail; } rv = nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); if (rv != 0) { goto fail; } rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2); if (rv != 0) { goto fail; } rv = nghttp2_session_send(session); if (rv != 0) { goto fail; } rv = nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 100, NGHTTP2_NO_ERROR, NULL, 0); if (rv != 0) { goto fail; } rv = nghttp2_session_send(session); if (rv != 0) { goto fail; } fail: nghttp2_session_del(session); client_new_fail:; }