diff --git a/examples/spdycat.cc b/examples/spdycat.cc index b433958e..69f337af 100644 --- a/examples/spdycat.cc +++ b/examples/spdycat.cc @@ -138,6 +138,8 @@ int communicate(const std::string& host, uint16_t port, std::cerr << "Could not connect to the host" << std::endl; return -1; } + make_non_block(fd); + set_tcp_nodelay(fd); SSL_CTX *ssl_ctx; ssl_ctx = SSL_CTX_new(SSLv23_client_method()); if(!ssl_ctx) { @@ -153,8 +155,6 @@ int communicate(const std::string& host, uint16_t port, if(ssl_handshake(ssl, fd) == -1) { return -1; } - make_non_block(fd); - set_tcp_nodelay(fd); Spdylay sc(fd, ssl, callbacks); nfds_t npollfds = 1; diff --git a/examples/spdylay_ssl.cc b/examples/spdylay_ssl.cc index f6964228..3b52a67f 100644 --- a/examples/spdylay_ssl.cc +++ b/examples/spdylay_ssl.cc @@ -476,7 +476,22 @@ int ssl_handshake(SSL *ssl, int fd) std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl; return -1; } + int loop_count = 0; int r = SSL_connect(ssl); + nfds_t npollfds = 1; + pollfd pollfds[1]; + pollfds[0].fd = fd; + + while(r == -1) { + ++loop_count; + int nfds = poll(pollfds, npollfds, -1); + if(nfds == -1) + continue; + r = SSL_connect(ssl); + } + std::cerr << "Loop iterated #" << loop_count << " times." << std::endl; + //std::cerr << "Event is " << pollfds[0].events << ":" << pollfds[0].revents << std::endl; + if(r <= 0) { std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl; return -1; diff --git a/lib/spdylay_submit.c b/lib/spdylay_submit.c index 2b156810..d3d7e34f 100644 --- a/lib/spdylay_submit.c +++ b/lib/spdylay_submit.c @@ -154,7 +154,7 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri, } spdylay_frame_nv_downcase(nv_copy); spdylay_frame_nv_sort(nv_copy); - if(data_prd == NULL) { + if(data_prd_copy == NULL) { flags |= SPDYLAY_FLAG_FIN; } spdylay_frame_syn_stream_init(&frame->syn_stream, flags, 0, 0, pri, nv_copy); diff --git a/tests/main.c b/tests/main.c index 2383848e..d1c94c71 100644 --- a/tests/main.c +++ b/tests/main.c @@ -87,6 +87,8 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "submit_response", test_spdylay_submit_response) || !CU_add_test(pSuite, "submit_request_with_data", test_spdylay_submit_request_with_data) || + !CU_add_test(pSuite, "submit_request_without_data", + test_spdylay_submit_request_with_null_data_read_callback) || !CU_add_test(pSuite, "session_reply_fail", test_spdylay_session_reply_fail) || !CU_add_test(pSuite, "session_on_headers_received", diff --git a/tests/spdylay_session_test.c b/tests/spdylay_session_test.c index 50524eea..807534e4 100644 --- a/tests/spdylay_session_test.c +++ b/tests/spdylay_session_test.c @@ -590,6 +590,28 @@ void test_spdylay_submit_request_with_data() spdylay_session_del(session); } +void test_spdylay_submit_request_with_null_data_read_callback() +{ + spdylay_session *session; + spdylay_session_callbacks callbacks = { + null_send_callback, + NULL, + NULL, + NULL + }; + const char *nv[] = { "Version", "HTTP/1.1", NULL }; + spdylay_data_provider data_prd = {{-1}, NULL}; + spdylay_outbound_item *item; + + CU_ASSERT(0 == spdylay_session_client_new(&session, &callbacks, NULL)); + CU_ASSERT(0 == spdylay_submit_request(session, 3, nv, &data_prd, NULL)); + item = spdylay_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("version", item->frame->syn_stream.nv[0])); + CU_ASSERT(item->frame->syn_stream.hd.flags & SPDYLAY_FLAG_FIN); + + spdylay_session_del(session); +} + void test_spdylay_session_reply_fail() { spdylay_session *session; diff --git a/tests/spdylay_session_test.h b/tests/spdylay_session_test.h index a7aec87b..36b438fe 100644 --- a/tests/spdylay_session_test.h +++ b/tests/spdylay_session_test.h @@ -35,6 +35,7 @@ void test_spdylay_session_send_syn_stream(); void test_spdylay_session_send_syn_reply(); void test_spdylay_submit_response(); void test_spdylay_submit_request_with_data(); +void test_spdylay_submit_request_with_null_data_read_callback(); void test_spdylay_session_reply_fail(); void test_spdylay_session_on_headers_received(); void test_spdylay_session_on_ping_received();