Network - OysterByte += operator

This commit is contained in:
Pontus Fransson 2013-12-17 08:45:47 +01:00
parent e4e0e1c189
commit 23a05bf431
4 changed files with 45 additions and 2 deletions

View File

@ -109,6 +109,25 @@ OysterByte::operator unsigned char*()
return byteArray;
}
OysterByte& OysterByte::operator +=(const OysterByte& obj)
{
int newSize = this->size + obj.size;
if(newSize >= (int)capacity)
{
IncreaseCapacity(this->size);
}
for(int i = size, j = 0; i < newSize; i++, j++)
{
this->byteArray[i] = obj.byteArray[j];
}
this->size = newSize;
return *this;
}
/////////////
// Private //
/////////////

View File

@ -40,6 +40,8 @@ namespace Oyster
operator const char*();
operator unsigned char*();
OysterByte& operator +=(const OysterByte& obj);
private:
//Expands the byteArray
void IncreaseCapacity(unsigned int cap);

View File

@ -41,11 +41,21 @@ int main()
}
//client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function);
OysterByte bytes, bytes2, bytes3;
bytes.AddSize(4);
bytes2.AddSize(5);
strcpy_s(bytes, 5, "asda");
strcpy_s(bytes2, 6, "asdab");
bytes += bytes2;
bytes += bytes;
bytes += bytes;
bytes3 = bytes;
cout << "Done" << endl;
while(1)
{
}
ShutdownWinSock();

View File

@ -1,15 +1,22 @@
#include <iostream>
#include <vector>
#include <vld.h>
#include <mutex>
#include "../NetworkDependencies/WinsockFunctions.h"
#include "../NetworkAPI/NetworkServer.h"
using namespace Oyster::Network;
using namespace std;
vector<NetworkClient> clients;
std::mutex m;
void proc(NetworkClient client)
{
cout << "Hej" << endl;
m.lock();
clients.push_back(client);
m.unlock();
}
int main()
@ -38,9 +45,14 @@ int main()
while(1)
{
Sleep(1000);
m.lock();
cout << clients.size() << endl;
m.unlock();
break;
}
server.Stop();
system("pause");