refactored SecureSocket to use interface #4313

This commit is contained in:
Xinyu Hou 2015-01-14 17:24:45 +00:00 committed by XinyuHou
parent be2b87fd39
commit 141b778477
28 changed files with 484 additions and 158 deletions

View file

@ -18,28 +18,62 @@
#include "ns.h"
#include "SecureSocket.h"
#include "SecureListenSocket.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include <iostream>
SecureSocket* g_secureSocket = NULL;
SecureListenSocket* g_secureListenSocket = NULL;
Arch* g_arch = NULL;
Log* g_log = NULL;
extern "C" {
void
init(void* log, void* arch)
{
if (g_log == NULL) {
g_log = new Log(reinterpret_cast<Log*>(log));
}
if (g_arch == NULL) {
g_arch = new Arch(reinterpret_cast<Arch*>(arch));
}
}
int
init(void (*sendEvent)(const char*, void*), void (*log)(const char*))
initEvent(void (*sendEvent)(const char*, void*))
{
return 0;
}
void*
invoke(const char* command, void* args)
invoke(const char* command, void** args)
{
IEventQueue* arg1 = NULL;
SocketMultiplexer* arg2 = NULL;
if (args != NULL) {
arg1 = reinterpret_cast<IEventQueue*>(args[0]);
arg2 = reinterpret_cast<SocketMultiplexer*>(args[1]);
}
if (strcmp(command, "getSecureSocket") == 0) {
if (g_secureSocket == NULL) {
g_secureSocket = new SecureSocket();
if (g_secureSocket != NULL) {
delete g_secureSocket;
}
g_secureSocket = new SecureSocket(arg1, arg2);
g_secureSocket->initSsl(false);
return g_secureSocket;
}
else if (strcmp(command, "getSecureListenSocket") == 0) {
if (g_secureListenSocket != NULL) {
delete g_secureListenSocket;
}
g_secureListenSocket = new SecureListenSocket(arg1, arg2);
return g_secureListenSocket;
}
else {
return NULL;
}
@ -52,6 +86,10 @@ cleanup()
delete g_secureSocket;
}
if (g_secureListenSocket != NULL) {
delete g_secureListenSocket;
}
return 0;
}