reconstruction in connection.

This commit is contained in:
Sam Mario Svensson 2013-11-25 14:03:32 +01:00
parent 82b8ef7b05
commit ca5e578af5
2 changed files with 19 additions and 5 deletions

View File

@ -36,8 +36,7 @@ bool Connection::Connect(unsigned short port , const char serverName[])
bool Connection::InitiateServer(unsigned short port) bool Connection::InitiateServer(unsigned short port)
{ {
this->socket = ::socket(AF_INET, SOCK_STREAM, 0); if(!initiateSocket())
if(this->socket == SOCKET_ERROR)
{ {
//Error opening socket! //Error opening socket!
return false; return false;
@ -69,10 +68,8 @@ bool Connection::InitiateServer(unsigned short port)
bool Connection::InitiateClient() bool Connection::InitiateClient()
{ {
this->socket = ::socket(AF_INET, SOCK_STREAM, 0); if(!initiateSocket())
if(this->socket == SOCKET_ERROR)
{ {
//error opening socket
return false; return false;
} }
@ -126,3 +123,18 @@ int Connection::Listen()
return clientSocket; 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;
}

View File

@ -30,6 +30,8 @@ namespace Oyster
virtual int Listen(); virtual int Listen();
private: private:
bool initiateSocket();
int socket; int socket;
}; };