[pan2/testing: 225/279] removed ssl context creation from _every_ socket to the socket-creator thread
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/testing: 225/279] removed ssl context creation from _every_ socket to the socket-creator thread
- Date: Sat, 3 Dec 2011 22:40:29 +0000 (UTC)
commit 3da72f61da9828e8c65bc688f0ee6a917e737ebf
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date: Wed Nov 2 13:25:59 2011 +0100
removed ssl context creation from _every_ socket to the socket-creator
thread
pan/tasks/socket-impl-main.cc | 11 +++++++----
pan/tasks/socket-impl-main.h | 4 +++-
pan/tasks/socket-impl-openssl.cc | 14 +++++++-------
pan/tasks/socket-impl-openssl.h | 11 ++++++++---
4 files changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/pan/tasks/socket-impl-main.cc b/pan/tasks/socket-impl-main.cc
index 7e7fccc..f5a09d7 100644
--- a/pan/tasks/socket-impl-main.cc
+++ b/pan/tasks/socket-impl-main.cc
@@ -59,15 +59,16 @@ namespace pan
Socket * socket;
std::string err;
bool use_ssl;
+ SSL_CTX * context;
- ThreadWorker (const StringView& h, int p, Socket::Creator::Listener *l, bool ssl):
- host(h), port(p), listener(l), ok(false), socket(0), use_ssl(ssl) {}
+ ThreadWorker (const StringView& h, int p, Socket::Creator::Listener *l, bool ssl, SSL_CTX* ctx):
+ host(h), port(p), listener(l), ok(false), socket(0), use_ssl(ssl), context(ctx) {}
void do_work ()
{
#ifdef HAVE_OPENSSL
if (use_ssl)
- socket = new GIOChannelSocketSSL ();
+ socket = new GIOChannelSocketSSL (context);
else
#endif
socket = new GIOChannelSocket ();
@@ -124,6 +125,7 @@ SocketCreator :: SocketCreator()
SSL_load_error_strings();
/* init static locks for threads */
ssl_thread_setup();
+ ssl_ctx = SSL_CTX_new(SSLv3_client_method());
#endif
}
@@ -131,6 +133,7 @@ SocketCreator :: ~SocketCreator()
{
#ifdef HAVE_OPENSSL
ssl_thread_cleanup();
+ SSL_CTX_free(ssl_ctx);
#endif
}
@@ -143,6 +146,6 @@ SocketCreator :: create_socket (const StringView & host,
{
ensure_module_init ();
- ThreadWorker * w = new ThreadWorker (host, port, listener, use_ssl);
+ ThreadWorker * w = new ThreadWorker (host, port, listener, use_ssl, ssl_ctx);
threadpool.push_work (w, w, true);
}
diff --git a/pan/tasks/socket-impl-main.h b/pan/tasks/socket-impl-main.h
index db7da4a..8942357 100644
--- a/pan/tasks/socket-impl-main.h
+++ b/pan/tasks/socket-impl-main.h
@@ -112,7 +112,9 @@ namespace
namespace pan
{
-
+#ifdef HAVE_OPENSSL
+ static SSL_CTX* ssl_ctx;
+#endif
class SocketCreator
{
public:
diff --git a/pan/tasks/socket-impl-openssl.cc b/pan/tasks/socket-impl-openssl.cc
index d45176c..83f17da 100644
--- a/pan/tasks/socket-impl-openssl.cc
+++ b/pan/tasks/socket-impl-openssl.cc
@@ -106,14 +106,15 @@ extern t_freeaddrinfo p_freeaddrinfo;
#ifdef HAVE_OPENSSL // without libssl this class is just a stub....
-GIOChannelSocketSSL :: GIOChannelSocketSSL ():
+GIOChannelSocketSSL :: GIOChannelSocketSSL (SSL_CTX* ctx):
_channel (0),
_tag_watch (0),
_tag_timeout (0),
_listener (0),
_out_buf (g_string_new (0)),
_in_buf (g_string_new (0)),
- _io_performed (false)
+ _io_performed (false),
+ _ctx(ctx)
{
debug ("GIOChannelSocketSSL ctor " << (void*)this);
}
@@ -319,7 +320,7 @@ namespace
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
g_io_channel_unref(chan->giochan);
SSL_free(chan->ssl);
- SSL_CTX_free(chan->ctx);
+
g_free(chan);
}
}
@@ -382,8 +383,7 @@ namespace
SSL_CTX* ssl_init(void)
{
- SSL_CTX* ctx (SSL_CTX_new(SSLv3_client_method()));
- return ctx;
+ return 0;
}
static GIOStatus ssl_errno(gint e)
@@ -750,8 +750,8 @@ GIOChannelSocketSSL :: ssl_get_iochannel(GIOChannel *handle, gboolean verify)
g_return_val_if_fail(handle != 0, 0);
- if(!(ctx = ssl_init()))
- return 0;
+ ctx = _ctx;
+ if (!ctx) return 0;
if(!(fd = g_io_channel_unix_get_fd(handle)))
{
diff --git a/pan/tasks/socket-impl-openssl.h b/pan/tasks/socket-impl-openssl.h
index 93a6c87..9529522 100644
--- a/pan/tasks/socket-impl-openssl.h
+++ b/pan/tasks/socket-impl-openssl.h
@@ -48,9 +48,12 @@ namespace pan
class GIOChannelSocketSSL: public GIOChannelSocket
{
public:
- GIOChannelSocketSSL ();
virtual ~GIOChannelSocketSSL ();
-#ifdef HAVE_OPENSSL
+#ifndef HAVE_OPENSSL
+ GIOChannelSocketSSL ();
+#else
+ GIOChannelSocketSSL (SSL_CTX* ctx=0);
+#endif
virtual bool open (const StringView& address, int port, std::string& setme_err);
virtual void write_command (const StringView& chars, Listener *);
virtual void get_host (std::string& setme) const;
@@ -65,6 +68,9 @@ namespace pan
std::string _partial_read;
std::string _host;
bool _io_performed;
+#ifdef HAVE_OPENSSL
+ SSL_CTX * _ctx;
+#endif
private:
enum WatchMode { READ_NOW, WRITE_NOW, IGNORE_NOW };
@@ -81,7 +87,6 @@ namespace pan
private:
GIOChannel* ssl_get_iochannel(GIOChannel *handle, gboolean verify=true);
-#endif
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]