Network - Fixed small errors
This commit is contained in:
parent
e81062b875
commit
df1594a43b
|
@ -116,7 +116,6 @@ int Connection::Recieve(Utility::DynamicMemory::SmartPointer<OysterByte> &bytes)
|
||||||
{
|
{
|
||||||
int nBytes;
|
int nBytes;
|
||||||
|
|
||||||
bytes.Get()->Resize(1000);
|
|
||||||
bytes->Resize(1000);
|
bytes->Resize(1000);
|
||||||
nBytes = recv(this->socket, *bytes , 500, 0);
|
nBytes = recv(this->socket, *bytes , 500, 0);
|
||||||
if(nBytes == SOCKET_ERROR)
|
if(nBytes == SOCKET_ERROR)
|
||||||
|
@ -138,7 +137,7 @@ int Connection::Listen()
|
||||||
int clientSocket;
|
int clientSocket;
|
||||||
if((clientSocket = accept(this->socket, NULL, NULL)) == INVALID_SOCKET)
|
if((clientSocket = accept(this->socket, NULL, NULL)) == INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
return WSAGetLastError();
|
return INVALID_SOCKET;//WSAGetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientSocket;
|
return clientSocket;
|
||||||
|
|
|
@ -44,9 +44,12 @@ int Listener::Accept()
|
||||||
SmartPointer<int> clientSocket = SmartPointer<int>(new int());
|
SmartPointer<int> clientSocket = SmartPointer<int>(new int());
|
||||||
*clientSocket = connection->Listen();
|
*clientSocket = connection->Listen();
|
||||||
|
|
||||||
|
if(*clientSocket != -1)
|
||||||
|
{
|
||||||
mutex.LockMutex();
|
mutex.LockMutex();
|
||||||
postBox->PostMessage(clientSocket);
|
postBox->PostMessage(clientSocket);
|
||||||
mutex.UnlockMutex();
|
mutex.UnlockMutex();
|
||||||
|
}
|
||||||
|
|
||||||
return clientSocket;
|
return clientSocket;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,19 @@ OysterByte::OysterByte(int cap)
|
||||||
byteArray = new unsigned char[capacity];
|
byteArray = new unsigned char[capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OysterByte::OysterByte(const OysterByte& obj)
|
||||||
|
{
|
||||||
|
delete[] this->byteArray;
|
||||||
|
this->byteArray = new unsigned char[obj.capacity];
|
||||||
|
|
||||||
|
for(int i = 0; i < obj.size; i++)
|
||||||
|
{
|
||||||
|
this->byteArray[i] = obj.byteArray[i];
|
||||||
|
}
|
||||||
|
this->size = obj.size;
|
||||||
|
this->capacity = obj.capacity;
|
||||||
|
}
|
||||||
|
|
||||||
OysterByte::~OysterByte()
|
OysterByte::~OysterByte()
|
||||||
{
|
{
|
||||||
delete[] byteArray;
|
delete[] byteArray;
|
||||||
|
@ -67,6 +80,21 @@ void OysterByte::SetSize(unsigned int size)
|
||||||
this->size = size;
|
this->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OysterByte& OysterByte::operator =(const OysterByte& obj)
|
||||||
|
{
|
||||||
|
delete[] this->byteArray;
|
||||||
|
this->byteArray = new unsigned char[obj.capacity];
|
||||||
|
|
||||||
|
for(int i = 0; i < obj.size; i++)
|
||||||
|
{
|
||||||
|
this->byteArray[i] = obj.byteArray[i];
|
||||||
|
}
|
||||||
|
this->size = obj.size;
|
||||||
|
this->capacity = obj.capacity;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
OysterByte::operator char*()
|
OysterByte::operator char*()
|
||||||
{
|
{
|
||||||
return (char*)byteArray;
|
return (char*)byteArray;
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace Oyster
|
||||||
public:
|
public:
|
||||||
OysterByte();
|
OysterByte();
|
||||||
OysterByte(int cap);
|
OysterByte(int cap);
|
||||||
|
OysterByte(const OysterByte& obj);
|
||||||
virtual ~OysterByte();
|
virtual ~OysterByte();
|
||||||
|
|
||||||
void Clear(); //Resets size to 0
|
void Clear(); //Resets size to 0
|
||||||
|
@ -28,6 +29,8 @@ namespace Oyster
|
||||||
void SetBytes(unsigned char* bytes);
|
void SetBytes(unsigned char* bytes);
|
||||||
void SetSize(unsigned int size); //Only sets the private variable 'size'
|
void SetSize(unsigned int size); //Only sets the private variable 'size'
|
||||||
|
|
||||||
|
OysterByte& operator =(const OysterByte& obj);
|
||||||
|
|
||||||
operator char*();
|
operator char*();
|
||||||
operator const char*();
|
operator const char*();
|
||||||
operator unsigned char*();
|
operator unsigned char*();
|
||||||
|
|
|
@ -75,7 +75,7 @@ int ThreadedClient::Recv()
|
||||||
{
|
{
|
||||||
int errorCode = 0;
|
int errorCode = 0;
|
||||||
|
|
||||||
SmartPointer<OysterByte> temp = SmartPointer<OysterByte>(new OysterByte());
|
SmartPointer<OysterByte> temp = new OysterByte();
|
||||||
errorCode = this->connection->Recieve(temp);
|
errorCode = this->connection->Recieve(temp);
|
||||||
|
|
||||||
if(errorCode == 0)
|
if(errorCode == 0)
|
||||||
|
|
|
@ -59,7 +59,7 @@ void chat(ThreadedClient &client)
|
||||||
|
|
||||||
client.setRecvPostBox(postBox);
|
client.setRecvPostBox(postBox);
|
||||||
|
|
||||||
SmartPointer<OysterByte> msgRecv = NULL;
|
SmartPointer<OysterByte> msgRecv = SmartPointer<OysterByte>(new OysterByte());
|
||||||
SmartPointer<OysterByte> msgSend = SmartPointer<OysterByte>(new OysterByte());
|
SmartPointer<OysterByte> msgSend = SmartPointer<OysterByte>(new OysterByte());
|
||||||
|
|
||||||
ProtocolSet* set = new ProtocolSet;
|
ProtocolSet* set = new ProtocolSet;
|
||||||
|
@ -83,7 +83,6 @@ void chat(ThreadedClient &client)
|
||||||
if(postBox->FetchMessage(msgRecv))
|
if(postBox->FetchMessage(msgRecv))
|
||||||
{
|
{
|
||||||
t->Unpack(set, msgRecv);
|
t->Unpack(set, msgRecv);
|
||||||
delete msgRecv;
|
|
||||||
|
|
||||||
PrintOutMessage(set);
|
PrintOutMessage(set);
|
||||||
set->Release();
|
set->Release();
|
||||||
|
|
|
@ -26,7 +26,7 @@ void PrintOutMessage(ProtocolSet* set);
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
SmartPointer<OysterByte> sendBuffer = SmartPointer<OysterByte>(new OysterByte);
|
SmartPointer<OysterByte> sendBuffer = SmartPointer<OysterByte>(new OysterByte);
|
||||||
SmartPointer<OysterByte> recvBuffer = NULL;
|
SmartPointer<OysterByte> recvBuffer = SmartPointer<OysterByte>(new OysterByte());
|
||||||
ProtocolSet* set = new ProtocolSet;
|
ProtocolSet* set = new ProtocolSet;
|
||||||
IPostBox<SmartPointer<int>> *postBox = new PostBox<SmartPointer<int>>();
|
IPostBox<SmartPointer<int>> *postBox = new PostBox<SmartPointer<int>>();
|
||||||
IPostBox<SmartPointer<OysterByte>> *recvPostBox = new PostBox<SmartPointer<OysterByte>>();
|
IPostBox<SmartPointer<OysterByte>> *recvPostBox = new PostBox<SmartPointer<OysterByte>>();
|
||||||
|
@ -91,7 +91,6 @@ int main()
|
||||||
if(recvPostBox->FetchMessage(recvBuffer))
|
if(recvPostBox->FetchMessage(recvBuffer))
|
||||||
{
|
{
|
||||||
t.Unpack(set, recvBuffer);
|
t.Unpack(set, recvBuffer);
|
||||||
delete recvBuffer;
|
|
||||||
|
|
||||||
PrintOutMessage(set);
|
PrintOutMessage(set);
|
||||||
set->Release();
|
set->Release();
|
||||||
|
@ -100,9 +99,13 @@ int main()
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
}
|
}
|
||||||
listener.Shutdown();
|
listener.Shutdown();
|
||||||
|
Sleep(1000);
|
||||||
|
|
||||||
system("pause");
|
system("pause");
|
||||||
|
|
||||||
|
for(int i = 0; i < clients.size(); i++)
|
||||||
|
delete clients.at(i);
|
||||||
|
|
||||||
delete postBox;
|
delete postBox;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue