示例#1
0
ssize_t
UnixSocketRawData::Receive(int aFd)
{
  if (!GetTrailingSpace()) {
    if (!GetLeadingSpace()) {
      return -1; /* buffer is full */
    }
    /* free up space at the end of data buffer */
    if (GetSize() <= GetLeadingSpace()) {
      memcpy(mData, GetData(), GetSize());
    } else {
      memmove(mData, GetData(), GetSize());
    }
    mOffset = 0;
  }

  ssize_t res =
    TEMP_FAILURE_RETRY(read(aFd, GetTrailingBytes(), GetTrailingSpace()));

  if (res < 0) {
    /* I/O error */
    return -1;
  } else if (!res) {
    /* EOF or peer shutdown sending */
    return 0;
  }

  mSize += res;

  return res;
}
示例#2
0
	static u8 *Resize(T *buffer, u32 new_trailing_bytes)
	{
		if (!buffer) return Acquire(new_trailing_bytes);

		if (new_trailing_bytes <= buffer->GetBytes())
			return GetTrailingBytes(buffer);

		// Grow buffer ahead of requested bytes according to golden ratio
		new_trailing_bytes = (new_trailing_bytes << 3) / 5;

		buffer = StdAllocator::ref()->ResizeTrailing(buffer, new_trailing_bytes);
		if (!buffer) return 0;

		buffer->SetBytes(new_trailing_bytes);

		return GetTrailingBytes(buffer);
	}
示例#3
0
    u8 *GetPostBuffer(u32 bytes)
    {
        TypedOverlapped *sendOv = reinterpret_cast<TypedOverlapped*>(
			RegionAllocator::ii->Acquire(sizeof(TypedOverlapped) + bytes) );

		if (!sendOv)
        {
            FATAL("IOCPSockets") << "Unable to allocate a send buffer: Out of memory";
            return 0;
        }

        return GetTrailingBytes(sendOv);
    }
示例#4
0
	static u8 *Acquire(u32 trailing_bytes)
	{
		u32 allocated = trailing_bytes;
		if (allocated < RESIZABLE_BUFFER_PREALLOCATION)
			allocated = RESIZABLE_BUFFER_PREALLOCATION;

		T *buffer = StdAllocator::ref()->AcquireTrailing<T>(allocated);
		if (!buffer) return 0;

		//buffer->allocated_bytes = trailing_bytes;
		buffer->SetBytes(allocated);
		return GetTrailingBytes(buffer);
	}
示例#5
0
    void *ResizePostBuffer(void *buffer, u32 newBytes)
    {
        TypedOverlapped *sendOv = reinterpret_cast<TypedOverlapped*>(
			RegionAllocator::ii->Resize(
				reinterpret_cast<u8*>(buffer) - sizeof(TypedOverlapped),
				sizeof(TypedOverlapped) + newBytes) );

        if (!sendOv)
        {
            FATAL("IOCPSockets") << "Unable to resize a send buffer: Out of memory";
            return 0;
        }

        return GetTrailingBytes(sendOv);
    }