commit 70a7c61f74fc6dfa75d5a57b7599dee5e13be749
parent 3b9e9c85b8dab59b73039c5bade324e07504da72
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date: Fri, 5 Jul 2013 15:15:55 +0000
spdy: init library changed
Diffstat:
4 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/src/include/microspdy.h b/src/include/microspdy.h
@@ -298,6 +298,27 @@ struct SPDY_Settings;
/**
+ * SPDY IO sybsystem flags used by SPDY_init() and SPDY_deinit().<p>
+ *
+ * The values are used internally as flags, that is why they must be
+ * powers of 2.
+ */
+enum SPDY_IO_SUBSYSTEM
+{
+
+ /**
+ * No subsystem. For internal use.
+ */
+ SPDY_IO_SUBSYSTEM_NONE = 0,
+
+ /**
+ * Default TLS implementation provided by openSSL/libssl.
+ */
+ SPDY_IO_SUBSYSTEM_OPENSSL = 1,
+};
+
+
+/**
* SPDY daemon options. Passed in the varargs portion of
* SPDY_start_daemon to customize the daemon. Each option must
* be followed by a value of a specific type.<p>
@@ -514,7 +535,6 @@ enum SPDY_RESPONSE_RESULT
SPDY_RESPONSE_RESULT_STREAM_CLOSED = 2,
};
-
/**
* Callback for serious error condition. The default action is to print
* an error message and abort().
@@ -736,12 +756,16 @@ typedef void
* and possibly other stuff needed by the lib. Currently the call
* always returns SPDY_YES.
*
+ * @param enum SPDY_IO_SUBSYSTEM io_subsystem the IO subsystem that will
+ * be initialized. Several can be used with bitwise OR. If no
+ * parameter is set, the default openssl subsystem will be used.
* @return SPDY_YES if the library was correctly initialized and its
* functions can be used now;
* SPDY_NO on error
*/
int
-SPDY_init (void);
+(SPDY_init) (enum SPDY_IO_SUBSYSTEM io_subsystem, ...);
+#define SPDY_init() SPDY_init(SPDY_IO_SUBSYSTEM_OPENSSL)
/**
@@ -750,7 +774,7 @@ SPDY_init (void);
* SPDY_init. Currently the function does not do anything.
*/
void
-SPDY_deinit (void);
+SPDY_deinit ();
/**
@@ -1295,5 +1319,4 @@ SPDY_send_ping(struct SPDY_Session * session,
SPDY_PingCallback rttcb,
void * rttcb_cls);
-
#endif
diff --git a/src/microspdy/applicationlayer.c b/src/microspdy/applicationlayer.c
@@ -233,13 +233,24 @@ spdy_handler_response_queue_result(void * cls,
int
-SPDY_init ()
+(SPDY_init) (enum SPDY_IO_SUBSYSTEM io_subsystem, ...)
{
SPDYF_ASSERT(SPDYF_BUFFER_SIZE >= SPDY_MAX_SUPPORTED_FRAME_SIZE,
"Buffer size is less than max supported frame size!");
SPDYF_ASSERT(SPDY_MAX_SUPPORTED_FRAME_SIZE >= 32,
"Max supported frame size must be bigger than the minimal value!");
- SPDYF_openssl_global_init();
+ SPDYF_ASSERT(SPDY_IO_SUBSYSTEM_NONE == spdyf_io_initialized,
+ "SPDY_init must be called only once per program or after SPDY_deinit");
+
+ if(SPDY_IO_SUBSYSTEM_OPENSSL & io_subsystem)
+ {
+ SPDYF_openssl_global_init();
+ spdyf_io_initialized |= SPDY_IO_SUBSYSTEM_OPENSSL;
+ }
+
+ SPDYF_ASSERT(SPDY_IO_SUBSYSTEM_NONE != spdyf_io_initialized,
+ "SPDY_init could not find even one IO subsystem");
+
return SPDY_YES;
}
@@ -247,9 +258,13 @@ SPDY_init ()
void
SPDY_deinit ()
{
+ SPDYF_ASSERT(SPDY_IO_SUBSYSTEM_NONE != spdyf_io_initialized,
+ "SPDY_init has not been called!");
+
//currently nothing to be freed/deinited
//SPDYF_openssl_global_deinit doesn't do anything now
//SPDYF_openssl_global_deinit();
+ spdyf_io_initialized = SPDY_IO_SUBSYSTEM_NONE;
}
@@ -317,6 +332,11 @@ SPDY_start_daemon (uint16_t port,
struct SPDY_Daemon *daemon;
va_list valist;
+ if(SPDY_IO_SUBSYSTEM_NONE == spdyf_io_initialized)
+ {
+ SPDYF_DEBUG("library not initialized");
+ return NULL;
+ }
if(NULL == certfile)
{
SPDYF_DEBUG("certfile is NULL");
diff --git a/src/microspdy/daemon.h b/src/microspdy/daemon.h
@@ -29,6 +29,12 @@
/**
+ * Global flags containing the initialized IO subsystems.
+ */
+enum SPDY_IO_SUBSYSTEM spdyf_io_initialized;
+
+
+/**
* Start a SPDDY webserver on the given port.
*
* @param port port to bind to
diff --git a/src/testspdy/test_misc.c b/src/testspdy/test_misc.c
@@ -193,8 +193,6 @@ parentproc()
int maxfd = -1;
struct SPDY_Daemon *daemon;
- SPDY_init();
-
daemon = SPDY_start_daemon(port,
DATA_DIR "cert-and-key.pem",
DATA_DIR "cert-and-key.pem",