示例#1
0
文件: Buffer.cpp 项目: guker/utility
const char* Buffer::findCRLF(const char* start) const
{
    assert(peek() <= start);
    assert(start <= beginWrite());
    const char* crlf = std::search(start, beginWrite(), kCRLF, kCRLF+2);
    return crlf == beginWrite() ? NULL : crlf;
}
std::pair<std::ostream *, std::ostream *> HTTPServerResponseImpl::beginSend()
{
	poco_assert (!_pStream);
	poco_assert (!_pHeaderStream);

	// NOTE Code is not exception safe.

	if ((_pRequest && _pRequest->getMethod() == HTTPRequest::HTTP_HEAD) ||
		getStatus() < 200 ||
		getStatus() == HTTPResponse::HTTP_NO_CONTENT ||
		getStatus() == HTTPResponse::HTTP_NOT_MODIFIED)
	{
		throw Exception("HTTPServerResponse::beginSend is invalid for HEAD request");
	}
	else if (getChunkedTransferEncoding())
	{
		_pHeaderStream = new HTTPHeaderOutputStream(_session);
		beginWrite(*_pHeaderStream);
		_pStream = new HTTPChunkedOutputStream(_session);
	}
	else if (hasContentLength())
	{
		throw Exception("HTTPServerResponse::beginSend is invalid for response with Content-Length header");
	}
	else
	{
		_pStream = new HTTPOutputStream(_session);
		_pHeaderStream = _pStream;
		setKeepAlive(false);
		beginWrite(*_pStream);
	}

	return std::make_pair(_pHeaderStream, _pStream);
}
示例#3
0
文件: Buffer.cpp 项目: guker/utility
const char* Buffer::peekUntilCRLFCRLF(string& outLine)
{
    outLine.clear();
    const char* crlf2 = std::search(peek(), (const char*)beginWrite(), kCRLFCRLF+0, kCRLFCRLF+4);
    crlf2 = (crlf2 == beginWrite())?NULL:crlf2;
    if(crlf2)
    {
        assert( crlf2 < beginWrite());
        outLine.append(peek(),crlf2);
    }
    return crlf2;
}
示例#4
0
  bool SdioDmaSdCard::writeBlock(const void *src,uint32_t blockIndex) {

    _dmaFinished=_sdioFinished=false;

    // enable the relevant interrupts

    SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR);
    SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR);

    // issue the command

    if(!writeBlockCommand(blockIndex,BLOCK_SIZE))
      return false;

    // use DMA to transfer the data

    beginWrite(src,BLOCK_SIZE);

    // wait for completion or error

    if(!waitForTransfer())
      return false;

    // wait for the peripheral to go quiet

    SdCardSdioFeature::waitForTransmitComplete();
    return true;
  }
size_t GSM3MobileClientService::write(const uint8_t* buf)
{
	if(!(flags & GSM3MOBILECLIENTSERVICE_WRITING))
		beginWrite(true);
	theGSM3MobileClientProvider->writeSocket((const char*)(buf));
	return strlen((const char*)buf);
}
size_t GSM3MobileClientService::write(uint8_t c)
{	
	if(!(flags & GSM3MOBILECLIENTSERVICE_WRITING))
		beginWrite(true);
	theGSM3MobileClientProvider->writeSocket(c);
	return 1;
}
示例#7
0
文件: Buffer.cpp 项目: guker/utility
const char* Buffer::findEOL(const char* start) const
{
    assert(peek() <= start);
    assert(start <= beginWrite());
    const void* eol = memchr(start, '\n', readableBytes());
    return static_cast<const char*>(eol);
}
size_t GSM3MobileClientService::write(const uint8_t* buf, size_t sz)
{
	if(!(flags & GSM3MOBILECLIENTSERVICE_WRITING))
		beginWrite(true);
	for(int i=0;i<sz;i++)
		theGSM3MobileClientProvider->writeSocket(buf[i]);
	return sz;
}
void AsioSessionState::onAppReadWriteCompleted(
    size_t bytesTransferred)
{
    RCF_ASSERT(!mReflecting);
    switch(mState)
    {
    case ReadingDataCount:
    case ReadingData:

        if (mTransport.mCustomFraming)
        {
            doCustomFraming(bytesTransferred);
        }
        else
        {
            doRegularFraming(bytesTransferred);
        }

        break;

    case WritingData:

        RCF_ASSERT_LTEQ(bytesTransferred , mWriteBufferRemaining);

        mWriteBufferRemaining -= bytesTransferred;
        if (mWriteBufferRemaining > 0)
        {
            beginWrite();
        }
        else
        {
            if (mCloseAfterWrite)
            {
                // For TCP sockets, call shutdown() so client receives
                // the message before we close the connection.

                implCloseAfterWrite();
            }
            else
            {
                mState = Ready;

                mSlicedWriteByteBuffers.resize(0);
                mWriteByteBuffers.resize(0);

                mTransport.getSessionManager().onWriteCompleted(
                    getSessionPtr());
            }
        }
        break;

    default:
        RCF_ASSERT(0);
    }
}
示例#10
0
文件: Buffer.cpp 项目: guker/utility
const char* Buffer::peekUntilCRLF(string& outLine)
{
    outLine.clear();
    const char* crlf = findCRLF();
    if(crlf)
    {
        assert( crlf < beginWrite());
        outLine.append(peek(),crlf);
    }
    return crlf;
}
示例#11
0
BlobMetadata LocalStore::putBlob(const Hash& id, const Blob* blob) {
  // Since blob serialization is moderately complex, just delegate
  // the immediate putBlob to the method on the WriteBatch.
  // Pre-allocate a buffer of approximately the right size; it
  // needs to hold the blob content plus have room for a couple of
  // hashes for the keys, plus some padding.
  auto batch = beginWrite(blob->getContents().computeChainDataLength() + 64);
  auto result = batch->putBlob(id, blob);
  batch->flush();
  return result;
}
void AsioSessionState::postWrite(
    std::vector<ByteBuffer> &byteBuffers)
{
    if (mLastError)
    {
        return;
    }

    BOOST_STATIC_ASSERT(sizeof(unsigned int) == 4);

    mSlicedWriteByteBuffers.resize(0);
    mWriteByteBuffers.resize(0);

    std::copy(
        byteBuffers.begin(),
        byteBuffers.end(),
        std::back_inserter(mWriteByteBuffers));

    byteBuffers.resize(0);

    if (!mTransport.mCustomFraming)
    {
        // Add frame (4 byte length prefix).
        int messageSize =
            static_cast<int>(RCF::lengthByteBuffers(mWriteByteBuffers));

        ByteBuffer &byteBuffer = mWriteByteBuffers.front();

        RCF_ASSERT_GTEQ(byteBuffer.getLeftMargin() , 4);
        byteBuffer.expandIntoLeftMargin(4);
        memcpy(byteBuffer.getPtr(), &messageSize, 4);
        RCF::machineToNetworkOrder(byteBuffer.getPtr(), 4, 1);
    }

    mState = AsioSessionState::WritingData;

    mWriteBufferRemaining = RCF::lengthByteBuffers(mWriteByteBuffers);

    beginWrite();
}
示例#13
0
文件: Buffer.cpp 项目: guker/utility
bool Buffer::appendFromFile(const string path,const string mode)
{
    FILE* pfile = fopen(path.c_str(),mode.c_str());
    int32_t nlength = 0;
    if(pfile)
    {
        fseek(pfile,0,SEEK_END);
        nlength = ftell(pfile);
        if( nlength <= 0)
        {
            fclose(pfile);
            return false;
        }
        fseek(pfile,0,SEEK_SET);
        ensureWritableBytes(nlength);
        fread(beginWrite(),sizeof (int8_t),nlength,pfile);
        hasWritten(nlength);
        fclose(pfile);
		return true;
    }
    return false;
}
示例#14
0
  bool SdioDmaSdCard::writeBlocks(const void *src,uint32_t blockIndex,uint32_t numBlocks) {

    const uint8_t *ptr;

    for(ptr=static_cast<const uint8_t *>(src);numBlocks;numBlocks--,blockIndex++,ptr+=BLOCK_SIZE)
      if(!writeBlock(ptr,blockIndex))
        return false;

    return true;

#if 0
    _dmaFinished=_sdioFinished=false;

    // enable the relevant interrupts

    SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR);
    SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR);

    // issue the command

    if(!writeBlocksCommand(blockIndex,BLOCK_SIZE,numBlocks))
      return false;

    // use DMA to transfer the data

    beginWrite(dest,numBlocks*BLOCK_SIZE);

    // wait for completion or error

    if(!waitForTransfer())
      return false;

    // wait for the peripheral to go quiet

    SdCardSdioFeature::waitForTransmitComplete();
    return true;
#endif
  }
示例#15
0
文件: Buffer.cpp 项目: guker/utility
void Buffer::append(const char* data, size_t len)
{
    ensureWritableBytes(len);
    std::copy(data, data+len, beginWrite());
    hasWritten(len);
}
示例#16
0
文件: Buffer.cpp 项目: guker/utility
const char* Buffer::findCRLF() const
{
    const char* crlf = std::search(peek(), beginWrite(), kCRLF, kCRLF+2);
    return crlf == beginWrite() ? NULL : crlf;
}