commit 9f6372506d35dc824693c2136116383b90d3959e
parent fc73de2bc9583ba2d30691d62b60ee87fe8fb26a
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date: Fri, 5 Jul 2013 17:16:11 +0000
spdy: max num frames added as an option for the daemon
Diffstat:
5 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/README b/README
@@ -120,9 +120,6 @@ a file will block all responses with same or smaller priority
Additional ideas for features include:
- Individual callbacks for each session
- Individual timeout for each session
-- Setting number of frames that can be written to the output at once.
- A big number means faster sending of a big resource, but the other
- sessions will wait longer.
Unimplemented API functions of libmicrospdy:
- SPDY_settings_create ();
diff --git a/src/include/microspdy.h b/src/include/microspdy.h
@@ -367,6 +367,18 @@ enum SPDY_DAEMON_OPTION
* SPDY_IO_SUBSYSTEM value.
*/
SPDY_DAEMON_OPTION_IO_SUBSYSTEM = 8,
+
+ /**
+ * Maximum number of frames to be written to the socket at once. The
+ * library tries to send max_num_frames in a single call to SPDY_run
+ * for a single session. This means no requests can be received nor
+ * other sessions can send data as long the current one has enough
+ * frames to send and there is no error on writing. Thus, a big value
+ * will affect the performance. Small value gives fairnes for sessions.
+ * Must be followed by a positive integer (uin32_t). If not set, the
+ * default value 10 will be used.
+ */
+ SPDY_DAEMON_OPTION_MAX_NUM_FRAMES = 16,
};
diff --git a/src/microspdy/daemon.c b/src/microspdy/daemon.c
@@ -145,6 +145,9 @@ spdyf_parse_options_va (struct SPDY_Daemon *daemon,
case SPDY_DAEMON_OPTION_IO_SUBSYSTEM:
daemon->io_subsystem = va_arg (valist, enum SPDY_IO_SUBSYSTEM);
break;
+ case SPDY_DAEMON_OPTION_MAX_NUM_FRAMES:
+ daemon->max_num_frames = va_arg (valist, uint32_t);
+ break;
default:
SPDYF_DEBUG("Wrong option for the daemon %i",opt);
return SPDY_NO;
@@ -200,6 +203,9 @@ SPDYF_start_daemon_va (uint16_t port,
SPDYF_DEBUG("parse");
goto free_and_fail;
}
+
+ if(0 == daemon->max_num_frames)
+ daemon->max_num_frames = SPDYF_NUM_SENT_FRAMES_AT_ONCE;
if(!port && NULL == daemon->address)
{
diff --git a/src/microspdy/session.c b/src/microspdy/session.c
@@ -861,7 +861,7 @@ SPDYF_session_read (struct SPDY_Session *session)
int
SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame)
{
- int i;
+ unsigned int i;
int bytes_written;
struct SPDYF_Response_Queue *queue_head;
struct SPDYF_Response_Queue *response_queue;
@@ -872,7 +872,7 @@ SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame)
for(i=0;
only_one_frame
? i < 1
- : i < SPDYF_NUM_SENT_FRAMES_AT_ONCE;
+ : i < session->max_num_frames;
++i)
{
//if the buffer is not null, part of the last frame is still
@@ -1294,6 +1294,7 @@ SPDYF_session_accept(struct SPDY_Daemon *daemon)
session->daemon = daemon;
session->socket_fd = new_socket_fd;
+ session->max_num_frames = daemon->max_num_frames;
ret = SPDYF_io_set_session(session, daemon->io_subsystem);
SPDYF_ASSERT(SPDY_YES == ret, "Somehow daemon->io_subsystem iswrong here");
diff --git a/src/microspdy/structures.h b/src/microspdy/structures.h
@@ -772,6 +772,15 @@ struct SPDY_Session
* frame, e.g. larger than supported.
*/
uint32_t current_stream_id;
+
+ /**
+ * Maximum number of frames to be written to the socket at once. The
+ * library tries to send max_num_frames in a single call to SPDY_run
+ * for a single session. This means no requests can be received nor
+ * other sessions can send data as long the current one has enough
+ * frames to send and there is no error on writing.
+ */
+ uint32_t max_num_frames;
/**
* Shows the current receiving state the session, i.e. what is
@@ -908,6 +917,16 @@ struct SPDY_Daemon
* Listen socket.
*/
int socket_fd;
+
+ /**
+ * This value is inherited by all sessions of the daemon.
+ * Maximum number of frames to be written to the socket at once. The
+ * library tries to send max_num_frames in a single call to SPDY_run
+ * for a single session. This means no requests can be received nor
+ * other sessions can send data as long the current one has enough
+ * frames to send and there is no error on writing.
+ */
+ uint32_t max_num_frames;
/**
* Daemon's options.