#if HAVE_BYTESWAP_H
#include <byteswap.h>
#endif
+#include <cstdlib>
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
Packet::Packet(size_t size) :
+ mBuffer((char*)malloc(size)),
+ mSize(size),
mR(0),
mW(0),
mBoolR(0),
mBoolNumR(0),
mBoolNumW(0)
{
- mBuffer = boost::shared_array<char>(new char[size]);
- mSize = size;
}
Packet::Packet(const char* data, size_t size) :
+ mBuffer((char*)malloc(size)),
+ mSize(size),
mR(0),
+ mW(size),
mBoolR(0),
mBoolW(0),
mBoolNumR(0),
mBoolNumW(0)
{
- mBuffer = boost::shared_array<char>(new char[size]);
- mSize = size;
- mW = size;
- memcpy(mBuffer.get(), data, mSize);
+ memcpy(mBuffer, data, size);
+}
+
+
+Packet::~Packet()
+{
+ free(mBuffer);
}
size_t Packet::write(const void* bytes, size_t size)
{
size_t nBytes = std::min(size, mSize - mW);
+ if (!mBuffer || nBytes < size)
+ {
+ int numPages = 1 + size / PAGE_SIZE;
+ int newSize = mSize + numPages * PAGE_SIZE;
+ char* newBuffer = (char*)realloc(mBuffer, newSize);
+ if (newBuffer)
+ {
+ mBuffer = newBuffer;
+ mSize = newSize;
+ }
+ }
memcpy(&mBuffer[mW], bytes, nBytes);
mW += nBytes;
return nBytes;
#include <string>
#include <vector>
-#include <boost/shared_array.hpp>
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
namespace Mf {
{
public:
- Packet(size_t size = 1024);
+ Packet(size_t size = PAGE_SIZE);
Packet(const char* data, size_t size);
+ ~Packet();
+
Packet& operator<<(bool value);
Packet& operator<<(int8_t value);
Packet& operator<<(int16_t value);
const char* bytes() const
{
- return &mBuffer.get()[mR];
+ return mBuffer + mR;
}
size_t size() const
private:
- boost::shared_array<char> mBuffer;
- size_t mSize;
+ char* mBuffer;
+ size_t mSize;
- size_t mR;
- size_t mW;
+ size_t mR;
+ size_t mW;
- size_t mBoolR;
- size_t mBoolW;
- size_t mBoolNumR;
- size_t mBoolNumW;
+ size_t mBoolR;
+ size_t mBoolW;
+ size_t mBoolNumR;
+ size_t mBoolNumW;
};
service.length() > 0 ? service.c_str() : 0, &hints, &list);
if (status == 0)
{
- struct addrinfo* addr = list;
- while (addr != 0)
+ for (struct addrinfo* addr = list;
+ addr != 0; addr = addr->ai_next)
{
resolved.push_back(SocketAddress(addr, name));
- addr = addr->ai_next;
}
freeaddrinfo(list);