removed loop accept and connect and added more debug info #4313

This commit is contained in:
XinyuHou 2015-01-29 15:40:30 +00:00
parent d15c99f41d
commit 767802f111
3 changed files with 41 additions and 27 deletions

View File

@ -59,6 +59,8 @@ SecureSocket::SecureSocket(
SecureSocket::~SecureSocket() SecureSocket::~SecureSocket()
{ {
SSL_shutdown(m_ssl->m_ssl);
if (m_ssl->m_ssl != NULL) { if (m_ssl->m_ssl != NULL) {
SSL_free(m_ssl->m_ssl); SSL_free(m_ssl->m_ssl);
m_ssl->m_ssl = NULL; m_ssl->m_ssl = NULL;
@ -72,6 +74,14 @@ SecureSocket::~SecureSocket()
delete[] m_error; delete[] m_error;
} }
void
SecureSocket::close()
{
SSL_shutdown(m_ssl->m_ssl);
TCPSocket::close();
}
void void
SecureSocket::secureConnect() SecureSocket::secureConnect()
{ {
@ -210,14 +220,6 @@ SecureSocket::secureAccept(int socket)
int r = SSL_accept(m_ssl->m_ssl); int r = SSL_accept(m_ssl->m_ssl);
bool retry = checkResult(r); bool retry = checkResult(r);
//TODO: don't use this infinite loop
while (retry) {
ARCH->sleep(.5f);
SSL_set_fd(m_ssl->m_ssl, socket);
r = SSL_accept(m_ssl->m_ssl);
retry = checkResult(r);
}
m_secureReady = !retry; m_secureReady = !retry;
return retry; return retry;
} }
@ -234,17 +236,12 @@ SecureSocket::secureConnect(int socket)
int r = SSL_connect(m_ssl->m_ssl); int r = SSL_connect(m_ssl->m_ssl);
bool retry = checkResult(r); bool retry = checkResult(r);
//TODO: don't use this infinite loop m_secureReady = !retry;
while (retry) {
ARCH->sleep(.5f); if (m_secureReady) {
r = SSL_connect(m_ssl->m_ssl); showCertificate();
retry = checkResult(r);
} }
m_secureReady= true;
showCertificate();
m_secureReady = !retry;
return retry; return retry;
} }
@ -276,6 +273,12 @@ SecureSocket::checkResult(int n)
switch (errorCode) { switch (errorCode) {
case SSL_ERROR_NONE: case SSL_ERROR_NONE:
// the TLS/SSL I/O operation completed
break;
case SSL_ERROR_ZERO_RETURN:
// the TLS/SSL connection has been closed
LOG((CLOG_DEBUG2 "SSL_ERROR_ZERO_RETURN"));
break; break;
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
@ -299,15 +302,18 @@ SecureSocket::checkResult(int n)
break; break;
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
// some I/O error occurred
throwError("Secure socket syscall error"); throwError("Secure socket syscall error");
break; break;
case SSL_ERROR_SSL: case SSL_ERROR_SSL:
throwError("Secure socket error"); // a failure in the SSL library occurred
LOG((CLOG_DEBUG2 "SSL_ERROR_SSL"));
throwError("Secure socket SSL error");
break; break;
default: default:
// possible cases: // possible cases:
// SSL_ERROR_WANT_X509_LOOKUP, SSL_ERROR_ZERO_RETURN // SSL_ERROR_WANT_X509_LOOKUP
showError(); showError();
} }
@ -326,7 +332,7 @@ void
SecureSocket::throwError(const char* reason) SecureSocket::throwError(const char* reason)
{ {
if (getError()) { if (getError()) {
throw XSecureSocket(synergy::string::sprintf( throw XSocket(synergy::string::sprintf(
"%s: %s", reason, m_error)); "%s: %s", reason, m_error));
} }
} }
@ -342,7 +348,7 @@ SecureSocket::getError()
errorUpdated = true; errorUpdated = true;
} }
else { else {
LOG((CLOG_DEBUG "can not detect any error in secure socket")); LOG((CLOG_DEBUG2 "can not detect any error in secure socket"));
} }
return errorUpdated; return errorUpdated;
@ -376,5 +382,6 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
#elif SYSAPI_UNIX #elif SYSAPI_UNIX
retry = secureAccept(getSocket()->m_fd); retry = secureAccept(getSocket()->m_fd);
#endif #endif
return retry ? job : newJob(); return retry ? job : newJob();
} }

View File

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "net/TCPSocket.h" #include "net/TCPSocket.h"
#include "base/XBase.h" #include "net/XSocket.h"
class IEventQueue; class IEventQueue;
class SocketMultiplexer; class SocketMultiplexer;
@ -26,10 +26,6 @@ class ISocketMultiplexerJob;
struct Ssl; struct Ssl;
//! Generic socket exception
XBASE_SUBCLASS(XSecureSocket, XBase);
//! Secure socket //! Secure socket
/*! /*!
A secure socket using SSL. A secure socket using SSL.
@ -42,8 +38,12 @@ public:
ArchSocket socket); ArchSocket socket);
~SecureSocket(); ~SecureSocket();
// ISocket overrides
void close();
void secureConnect(); void secureConnect();
void secureAccept(); void secureAccept();
bool isReady() const { return m_secureReady; }
bool isSecureReady(); bool isSecureReady();
bool isSecure() { return true; } bool isSecure() { return true; }
UInt32 secureRead(void* buffer, UInt32 n); UInt32 secureRead(void* buffer, UInt32 n);

View File

@ -137,7 +137,8 @@ void
ClientListener::handleClientConnecting(const Event&, void*) ClientListener::handleClientConnecting(const Event&, void*)
{ {
// accept client connection // accept client connection
synergy::IStream* stream = m_listen->accept(); IDataSocket* socket = m_listen->accept();
synergy::IStream* stream = socket;
if (stream == NULL) { if (stream == NULL) {
return; return;
@ -157,6 +158,12 @@ ClientListener::handleClientConnecting(const Event&, void*)
assert(m_server != NULL); assert(m_server != NULL);
if (m_useSecureNetwork) {
while(!socket->isReady()) {
ARCH->sleep(.5f);
}
}
// create proxy for unknown client // create proxy for unknown client
ClientProxyUnknown* client = new ClientProxyUnknown(stream, 30.0, m_server, m_events); ClientProxyUnknown* client = new ClientProxyUnknown(stream, 30.0, m_server, m_events);
m_newClients.insert(client); m_newClients.insert(client);