summaryrefslogtreecommitdiff
path: root/lib/server
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:08 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:08 +0000
commit426a506afd1ffb3bd67e61b4693ee9bb968097a1 (patch)
treea6a726552411a781e692de657e3a630fa8d65d65 /lib/server
parent75ad60bcc4d33589bb5afb307a87fd19b220a9e8 (diff)
Simplify code with macros, update comments and fix whitespace.
Hopefully all of these changes are inconsequential. Merged back changes from the test refactor branch to reduce diffs.
Diffstat (limited to 'lib/server')
-rw-r--r--lib/server/ServerTLS.h3
-rw-r--r--lib/server/SocketStream.cpp25
-rw-r--r--lib/server/SocketStreamTLS.cpp15
-rwxr-xr-xlib/server/makeprotocol.pl.in2
4 files changed, 24 insertions, 21 deletions
diff --git a/lib/server/ServerTLS.h b/lib/server/ServerTLS.h
index 20e55964..f748f4b2 100644
--- a/lib/server/ServerTLS.h
+++ b/lib/server/ServerTLS.h
@@ -52,7 +52,8 @@ public:
std::string certFile(serverconf.GetKeyValue("CertificateFile"));
std::string keyFile(serverconf.GetKeyValue("PrivateKeyFile"));
std::string caFile(serverconf.GetKeyValue("TrustedCAsFile"));
- mContext.Initialise(true /* as server */, certFile.c_str(), keyFile.c_str(), caFile.c_str());
+ mContext.Initialise(true /* as server */, certFile.c_str(),
+ keyFile.c_str(), caFile.c_str());
// Then do normal stream server stuff
ServerStream<SocketStreamTLS, Port, ListenBacklog,
diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp
index db71227f..ab0a54ae 100644
--- a/lib/server/SocketStream.cpp
+++ b/lib/server/SocketStream.cpp
@@ -323,15 +323,15 @@ bool SocketStream::Poll(short Events, int Timeout)
// --------------------------------------------------------------------------
void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout)
{
- if(mSocketHandle == INVALID_SOCKET_VALUE)
+ if(mSocketHandle == INVALID_SOCKET_VALUE)
{
THROW_EXCEPTION(ServerException, BadSocketHandle)
}
-
+
// Buffer in byte sized type.
ASSERT(sizeof(char) == 1);
const char *buffer = (char *)pBuffer;
-
+
// Bytes left to send
int bytesLeft = NBytes;
box_time_t start = GetCurrentBoxTime();
@@ -348,22 +348,21 @@ void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout)
{
// Error.
mWriteClosed = true; // assume can't write again
- BOX_LOG_SYS_ERROR("Failed to write to socket");
- THROW_EXCEPTION(ConnectionException,
- SocketWriteError);
+ THROW_SYS_ERROR("Failed to write to socket",
+ ConnectionException, SocketWriteError);
}
-
+
// Knock off bytes sent
bytesLeft -= sent;
// Move buffer pointer
buffer += sent;
mBytesWritten += sent;
-
+
// Need to wait until it can send again?
if(bytesLeft > 0)
{
- BOX_TRACE("Waiting to send data on socket " <<
+ BOX_TRACE("Waiting to send data on socket " <<
mSocketHandle << " (" << bytesLeft <<
" of " << NBytes << " bytes left)");
@@ -388,7 +387,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout)
// --------------------------------------------------------------------------
void SocketStream::Close()
{
- if(mSocketHandle == INVALID_SOCKET_VALUE)
+ if(mSocketHandle == INVALID_SOCKET_VALUE)
{
THROW_EXCEPTION(ServerException, BadSocketHandle)
}
@@ -419,14 +418,14 @@ void SocketStream::Shutdown(bool Read, bool Write)
{
THROW_EXCEPTION(ServerException, BadSocketHandle)
}
-
+
// Do anything?
if(!Read && !Write) return;
-
+
int how = SHUT_RDWR;
if(Read && !Write) how = SHUT_RD;
if(!Read && Write) how = SHUT_WR;
-
+
// Shut it down!
if(::shutdown(mSocketHandle, how) == -1)
{
diff --git a/lib/server/SocketStreamTLS.cpp b/lib/server/SocketStreamTLS.cpp
index e31ac13f..953012d1 100644
--- a/lib/server/SocketStreamTLS.cpp
+++ b/lib/server/SocketStreamTLS.cpp
@@ -132,7 +132,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
tOSSocketHandle socket = GetSocketHandle();
BIO_set_fd(mpBIO, socket, BIO_NOCLOSE);
-
+
// Then the SSL object
mpSSL = ::SSL_new(rContext.GetRawContext());
if(mpSSL == 0)
@@ -155,7 +155,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
}
#endif
-
+
// FIXME: This is less portable than the above. However, it MAY be needed
// for cygwin, which has/had bugs with fcntl
//
@@ -223,8 +223,9 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
//
// Function
// Name: WaitWhenRetryRequired(int, int)
-// Purpose: Waits until the condition required by the TLS layer is met.
-// Returns true if the condition is met, false if timed out.
+// Purpose: Waits until the condition required by the TLS layer
+// is met. Returns true if the condition is met, false
+// if timed out.
// Created: 2003/08/15
//
// --------------------------------------------------------------------------
@@ -320,20 +321,20 @@ int SocketStreamTLS::Read(void *pBuffer, int NBytes, int Timeout)
void SocketStreamTLS::Write(const void *pBuffer, int NBytes, int Timeout)
{
if(!mpSSL) {THROW_EXCEPTION(ServerException, TLSNoSSLObject)}
-
+
// Make sure zero byte writes work as expected
if(NBytes == 0)
{
return;
}
-
+
// from man SSL_write
//
// SSL_write() will only return with success, when the
// complete contents of buf of length num has been written.
//
// So no worries about partial writes and moving the buffer around
-
+
while(true)
{
// try the write
diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in
index 7dfab7b3..ed0f1ee6 100755
--- a/lib/server/makeprotocol.pl.in
+++ b/lib/server/makeprotocol.pl.in
@@ -811,10 +811,12 @@ foreach my $type ('Client', 'Server', 'Local')
{
push @base_classes, $replyable_base_class;
}
+
if (not $writing_server)
{
push @base_classes, $callable_base_class;
}
+
if (not $writing_local)
{
push @base_classes, $custom_protocol_subclass;