From ca5e578af5c79e00aaf8162e7adf98efb5020d79 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 25 Nov 2013 14:03:32 +0100 Subject: [PATCH] reconstruction in connection. --- .../NetworkDependencies/Connection.cpp | 22 ++++++++++++++----- Code/Network/NetworkDependencies/Connection.h | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 26db50f8..792654f8 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -36,8 +36,7 @@ bool Connection::Connect(unsigned short port , const char serverName[]) bool Connection::InitiateServer(unsigned short port) { - this->socket = ::socket(AF_INET, SOCK_STREAM, 0); - if(this->socket == SOCKET_ERROR) + if(!initiateSocket()) { //Error opening socket! return false; @@ -69,10 +68,8 @@ bool Connection::InitiateServer(unsigned short port) bool Connection::InitiateClient() { - this->socket = ::socket(AF_INET, SOCK_STREAM, 0); - if(this->socket == SOCKET_ERROR) + if(!initiateSocket()) { - //error opening socket return false; } @@ -126,3 +123,18 @@ int Connection::Listen() return clientSocket; } + +/////////////////////////////////////// +//Private functions +/////////////////////////////////////// +bool Connection::initiateSocket() +{ + this->socket = ::socket(AF_INET, SOCK_STREAM, 0); + if(this->socket == SOCKET_ERROR) + { + //error opening socket + return false; + } + + return true; +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 6c679371..a0019a26 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -30,6 +30,8 @@ namespace Oyster virtual int Listen(); private: + bool initiateSocket(); + int socket; };