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; 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 // // Private //
///////////// /////////////

View File

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

View File

@ -41,11 +41,21 @@ int main()
} }
//client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); //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; cout << "Done" << endl;
while(1) while(1)
{ {
} }
ShutdownWinSock(); ShutdownWinSock();

View File

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