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