examples: Set TCP_NODELAY option

This commit is contained in:
Tatsuhiro Tsujikawa 2013-12-24 00:01:06 +09:00
parent 4e01ed1a95
commit 0fb7e430d7
2 changed files with 7 additions and 0 deletions

View File

@ -24,6 +24,7 @@
*/
#include <sys/types.h>
#include <unistd.h>
#include <netinet/tcp.h>
#include <err.h>
#include <signal.h>
@ -310,7 +311,10 @@ static void eventcb(struct bufferevent *bev, short events, void *ptr)
{
http2_session_data *session_data = (http2_session_data*)ptr;
if(events & BEV_EVENT_CONNECTED) {
int fd = bufferevent_getfd(bev);
int val = 1;
fprintf(stderr, "Connected\n");
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
initialize_nghttp2_session(session_data);
send_client_connection_header(session_data);
submit_request(session_data);

View File

@ -6,6 +6,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <netinet/tcp.h>
#include <err.h>
#include <openssl/ssl.h>
@ -154,11 +155,13 @@ static http2_session_data* create_http2_session_data(app_context *app_ctx,
http2_session_data *session_data;
SSL *ssl;
char host[NI_MAXHOST];
int val = 1;
ssl = create_ssl(app_ctx->ssl_ctx);
session_data = malloc(sizeof(http2_session_data));
memset(session_data, 0, sizeof(http2_session_data));
session_data->app_ctx = app_ctx;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
session_data->bev = bufferevent_openssl_socket_new
(app_ctx->evbase, fd, ssl,
BUFFEREVENT_SSL_ACCEPTING,