当前位置: 首页>>代码示例>>C++>>正文


C++ IOBuffer类代码示例

本文整理汇总了C++中IOBuffer的典型用法代码示例。如果您正苦于以下问题:C++ IOBuffer类的具体用法?C++ IOBuffer怎么用?C++ IOBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IOBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandleFixedLengthContent

bool BaseHTTPProtocol::HandleFixedLengthContent(IOBuffer &buffer) {
	//1. Compute the chunk size that we areg going to read
	//which is how many bytes we have available, but no more than _contentLength
	uint32_t chunkSize = GETAVAILABLEBYTESCOUNT(buffer);
	assert(_sessionDecodedBytesCount <= _contentLength);
	uint32_t remaining = _contentLength - _sessionDecodedBytesCount;
	chunkSize = chunkSize > remaining ? remaining : chunkSize;

	//2. Update the session decoded bytes count and decoded bytes count
	_sessionDecodedBytesCount += chunkSize;
	_decodedBytesCount += chunkSize;

	//3. Make the copy and ignore the chunk size
	_inputBuffer.ReadFromBuffer(GETIBPOINTER(buffer), chunkSize);
	buffer.Ignore(chunkSize);

	//3. Call the near protocol
	if (!_pNearProtocol->SignalInputData(_inputBuffer)) {
		FATAL("Unable to call the next protocol in stack");
		return false;
	}

	//4. reset the state if necessary
	if (TransferCompleted()) {
		_headers.Reset();
		_contentLength = 0;
		_chunkedContent = false;
		_lastChunk = false;
		_state = HTTP_STATE_HEADERS;
		_sessionDecodedBytesCount = 0;
	}

	//5. we are done
	return true;
}
开发者ID:Undev,项目名称:crtmpserver,代码行数:35,代码来源:basehttpprotocol.cpp

示例2: SignalInputData

bool NATTraversalProtocol::SignalInputData(IOBuffer &buffer, sockaddr_in *pPeerAddress) {
	//FINEST("_inputBuffer:\n%s", STR(buffer));
	buffer.IgnoreAll();
	if (_pOutboundAddress == NULL)
		return true;
	if (_pOutboundAddress->sin_addr.s_addr != pPeerAddress->sin_addr.s_addr) {
		WARN("Attempt to divert traffic. DoS attack!?");
		return true;
	}
	string ipAddress = inet_ntoa(_pOutboundAddress->sin_addr);
	if (_pOutboundAddress->sin_port == pPeerAddress->sin_port) {
		INFO("The client has public endpoint: %s:%"PRIu16,
				STR(ipAddress),
				ENTOHS(_pOutboundAddress->sin_port));
	} else {
		INFO("The client is behind firewall: %s:%"PRIu16" -> %s:%"PRIu16,
				STR(ipAddress),
				ENTOHS(_pOutboundAddress->sin_port),
				STR(ipAddress),
				ENTOHS(pPeerAddress->sin_port));
		_pOutboundAddress->sin_port = pPeerAddress->sin_port;
	}
	_pOutboundAddress = NULL;
	return true;
}
开发者ID:2php,项目名称:crtmpserver,代码行数:25,代码来源:nattraversalprotocol.cpp

示例3: SignalInputData

bool InboundXMLCLIProtocol::SignalInputData(IOBuffer &buffer) {
  //1. Get the buffer and the length
  uint8_t *pBuffer = GETIBPOINTER(buffer);
  uint32_t length = GETAVAILABLEBYTESCOUNT(buffer);
  if (length == 0)
    return true;

  //2. Walk through the buffer and execute the commands
  string command = "";
  for (uint32_t i = 0; i < length; i++) {
    if ((pBuffer[i] == 0x0d) || (pBuffer[i] == 0x0a)) {
      if (command != "") {
        if (!ParseCommand(command)) {
          FATAL("Unable to parse command\n`%s`", STR(command));
          return false;
        }
      }
      command = "";
      buffer.Ignore(i);
      pBuffer = GETIBPOINTER(buffer);
      length = GETAVAILABLEBYTESCOUNT(buffer);
      i = 0;
      continue;
    }
    command += (char) pBuffer[i];
    if (command.length() >= MAX_COMMAND_LENGTH) {
      FATAL("Command too long");
      return false;
    }
  }

  //3. Done
  return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:34,代码来源:inboundxmlcliprotocol.cpp

示例4: SerializeToBuffer

void AtomURL::SerializeToBuffer(IOBuffer& data, uint32_t maxFrames) {
  uint32_t start=GETAVAILABLEBYTESCOUNT(data);
  VersionedAtom::SerializeToBuffer(data, maxFrames);
  data.ReadFromString(_location);
  _size=GETAVAILABLEBYTESCOUNT(data)-start;
  *(uint32_t*)(GETIBPOINTER(data)+start) = endianSwap32(_size);
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:7,代码来源:atomurl.cpp

示例5: switch

bool TCPCarrier::OnEvent(struct kevent &event) {
    int32_t readAmount = 0;
    int32_t writeAmount = 0;

    //3. Do the I/O
    switch (event.filter) {
    case EVFILT_READ:
    {
        IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
        assert(pInputBuffer != NULL);
        if (!pInputBuffer->ReadFromTCPFd(event.ident, event.data, readAmount)) {
            FATAL("Unable to read data. %s:%hu -> %s:%hu",
                  STR(_farIp), _farPort,
                  STR(_nearIp), _nearPort);
            return false;
        }
        _rx += readAmount;
        return _pProtocol->SignalInputData(readAmount);
    }
    case EVFILT_WRITE:
    {
        IOBuffer *pOutputBuffer = NULL;

        if ((pOutputBuffer = _pProtocol->GetOutputBuffer()) != NULL) {
            if (!pOutputBuffer->WriteToTCPFd(event.ident, event.data, writeAmount)) {
                FATAL("Unable to send data. %s:%hu -> %s:%hu",
                      STR(_farIp), _farPort,
                      STR(_nearIp), _nearPort);
                IOHandlerManager::EnqueueForDelete(this);
                return false;
            }
            _tx += writeAmount;
            if (GETAVAILABLEBYTESCOUNT(*pOutputBuffer) == 0) {
                DISABLE_WRITE_DATA;
            }
        } else {
            DISABLE_WRITE_DATA;
        }
        return true;
    }
    default:
    {
        ASSERT("Invalid state: %hd", event.filter);
        return false;
    }
    }
}
开发者ID:a4tunado,项目名称:crtmpserver,代码行数:47,代码来源:tcpcarrier.cpp

示例6: SignalInputData

bool InboundMJPGHTTPStreamProtocol::SignalInputData(IOBuffer &buffer) {
	//1. Is the stream name acquired?
	if (_streamNameAcquired) {
		buffer.IgnoreAll();
		return true;
	}

	if (!AcquireStreamName(buffer)) {
		FATAL("Unable to get the stream name");
		return false;
	}

	if (!_streamNameAcquired) {
		return true;
	}

	//7. Search for the stream called streamName and pick the first one
	map<uint32_t, BaseStream *> inStreams =
			GetApplication()->GetStreamsManager()->FindByTypeByName(
			ST_IN_CAM_MJPG, _streamName, false, true);
	if (inStreams.size() == 0) {
		if (lowerCase(_streamName) == "crossdomain.xml") {
			return SendCrossDomain();
		} else {
			FATAL("Stream %s not found", STR(_streamName));
			return Send404NotFound();
		}
	}
	BaseInStream *pInStream = (BaseInStream *) MAP_VAL(inStreams.begin());

	//8. Create our raw outbound stream
	_pOutStream = new OutNetMJPGHTTPStream(this,
			GetApplication()->GetStreamsManager(), _streamName);

	//9. Link it to the in stream
	if (!pInStream->Link(_pOutStream)) {
		FATAL("Unable to link to the in stream");
		return false;
	}

	//10. All done. Ignore all the traffic
	buffer.IgnoreAll();

	//11. Done
	return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:46,代码来源:inboundmjpghttpstreamprotocol.cpp

示例7: receive

 ReturnCode receive(IOBuffer &buffer)
 {
     MSS_BEGIN(ReturnCode);
     MSS(state == Connected, InvalidState);
     MSS(!buffer.full());
     auto nrReceived = ::recv(fid, buffer.freeData(), buffer.freeSize(), 0);
     MSS(nrReceived != -1, CouldNotReceive);
     if (nrReceived == 0)
     {
         //Peer closed connection
         changeState(Closed);
         MSS_Q(ReturnCode::ConnectionWasClosed);
     }
     else
         MSS(buffer.scrollEnd(nrReceived));
     MSS_END();
 }
开发者ID:RoboBuddie,项目名称:gubg,代码行数:17,代码来源:Socket.cpp

示例8: Bind

bool InboundHTTP4RTMP::ProcessIdle(vector<string> &parts) {

	BaseProtocol *pProtocol = Bind(parts[2]);
	if (pProtocol == NULL) {
		FATAL("Unable to bind protocol");
		return false;
	}

	_outputBuffer.ReadFromByte(1);
	IOBuffer *pBuffer = pProtocol->GetOutputBuffer();
	if (pBuffer != NULL) {
		_outputBuffer.ReadFromBuffer(GETIBPOINTER(*pBuffer), GETAVAILABLEBYTESCOUNT(*pBuffer));
		pBuffer->IgnoreAll();
	}

	return BaseProtocol::EnqueueForOutbound();
}
开发者ID:Undev,项目名称:crtmpserver,代码行数:17,代码来源:inboundhttp4rtmp.cpp

示例9: switch

bool StdioCarrier::OnEvent(select_event &event) {
	int32_t recvAmount = 0;

	//3. Do the I/O
	switch (event.type) {
		case SET_READ:
		{
			IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
			assert(pInputBuffer != NULL);
			if (!pInputBuffer->ReadFromStdio(_inboundFd,
					FD_READ_CHUNK, recvAmount)) {
				FATAL("Unable to read data");
				return false;
			}

			return _pProtocol->SignalInputData(recvAmount);
		}
		case SET_WRITE:
		{
			IOBuffer *pOutputBuffer = NULL;

			while ((pOutputBuffer = _pProtocol->GetOutputBuffer()) != NULL) {
				if (!pOutputBuffer->WriteToStdio(_outboundFd,
						FD_WRITE_CHUNK)) {
					FATAL("Unable to send data");
					IOHandlerManager::EnqueueForDelete(this);
					return false;
				}
				if (GETAVAILABLEBYTESCOUNT(*pOutputBuffer) > 0) {
					ENABLE_WRITE_DATA;
					break;
				}
			}
			if (pOutputBuffer == NULL) {
				DISABLE_WRITE_DATA;
			}
			return true;
		}
		default:
		{
			ASSERT("Invalid state: %hhu", event.type);
			return false;
		}
	}
}
开发者ID:Undev,项目名称:crtmpserver,代码行数:45,代码来源:stdiocarrier.cpp

示例10: synchronous_io

static status_t
synchronous_io(io_request* request, DoIO& io)
{
	TRACE_RIO("[%" B_PRId32 "] synchronous_io(request: %p (offset: %" B_PRIdOFF
		", length: %" B_PRIuGENADDR "))\n", find_thread(NULL), request,
		request->Offset(), request->Length());

	IOBuffer* buffer = request->Buffer();

	iovec vector;
	void* virtualVecCookie = NULL;
	off_t offset = request->Offset();
	generic_size_t length = request->Length();

	for (; length > 0
			&& buffer->GetNextVirtualVec(virtualVecCookie, vector) == B_OK;) {
		void* vecBase = (void*)(addr_t)vector.iov_base;
		size_t vecLength = min_c(vector.iov_len, length);

		TRACE_RIO("[%ld]   I/O: offset: %lld, vecBase: %p, length: %lu\n",
			find_thread(NULL), offset, vecBase, vecLength);

		size_t transferred = vecLength;
		status_t error = io.IO(offset, vecBase, &transferred);
		if (error != B_OK) {
			TRACE_RIO("[%ld]   I/O failed: %#lx\n", find_thread(NULL), error);
			buffer->FreeVirtualVecCookie(virtualVecCookie);
			request->SetStatusAndNotify(error);
			return error;
		}

		offset += transferred;
		length -= transferred;

		if (transferred != vecLength)
			break;
	}

	TRACE_RIO("[%ld] synchronous_io() succeeded\n", find_thread(NULL));

	buffer->FreeVirtualVecCookie(virtualVecCookie);
	request->SetTransferredBytes(length > 0, request->Length() - length);
	request->SetStatusAndNotify(B_OK);
	return B_OK;
}
开发者ID:RAZVOR,项目名称:haiku,代码行数:45,代码来源:vfs_request_io.cpp

示例11: read

Error VGA::read(IOBuffer & buffer, Size size, Size offset)
{
    if (offset + size > width * height * sizeof(u16))
    {
        return EFAULT;
    }
    buffer.write(vga + (offset / sizeof(u16)), size);
    return size;
}
开发者ID:0xbda2d2f8,项目名称:FreeNOS,代码行数:9,代码来源:VGA.cpp

示例12: write

Error VGA::write(IOBuffer & buffer, Size size, Size offset)
{
    if (offset + size > width * height * sizeof(u16))
    {
        return EFAULT;
    }
    memcpy(vga + (offset / sizeof(u16)), buffer.getBuffer(), size);    
    return size;
}
开发者ID:0xbda2d2f8,项目名称:FreeNOS,代码行数:9,代码来源:VGA.cpp

示例13: PerformHandshake

bool OutboundRTMPProtocol::PerformHandshake(IOBuffer &buffer) {
	switch (_rtmpState) {
		case RTMP_STATE_NOT_INITIALIZED:
		{
			_encrypted = (VariantType) _customParameters[CONF_PROTOCOL] == V_STRING &&
					_customParameters[CONF_PROTOCOL] == CONF_PROTOCOL_OUTBOUND_RTMPE;
			_usedScheme = _encrypted ? 1 : 0;

			if ((VariantType) _customParameters[CONF_PROTOCOL] == V_STRING &&
					_customParameters[CONF_PROTOCOL] == CONF_PROTOCOL_OUTBOUND_RTMPE) {
				return PerformHandshakeStage1(true);
			} else {
				return PerformHandshakeStage1(false);
			}
		}
		case RTMP_STATE_CLIENT_REQUEST_SENT:
		{
			if (GETAVAILABLEBYTESCOUNT(buffer) < 3073)
				return true;

			if (!PerformHandshakeStage2(buffer, _encrypted)) {
				FATAL("Unable to handshake");
				return false;
			}

			if (_pFarProtocol != NULL) {
				if (!_pFarProtocol->EnqueueForOutbound()) {
					FATAL("Unable to signal output data");
					return false;
				}
			}

			if (_pKeyIn != NULL && _pKeyOut != NULL) {
				//insert the RTMPE protocol in the current protocol stack
				BaseProtocol *pFarProtocol = GetFarProtocol();
				RTMPEProtocol *pRTMPE = new RTMPEProtocol(_pKeyIn, _pKeyOut,
						GETAVAILABLEBYTESCOUNT(_outputBuffer));
				ResetFarProtocol();
				pFarProtocol->SetNearProtocol(pRTMPE);
				pRTMPE->SetNearProtocol(this);
				//FINEST("New protocol chain: %s", STR(*pFarProtocol));
			}

			if (!buffer.Ignore(3073)) {
				FATAL("Unable to ignore 3073 bytes");
				return false;
			}
			_handshakeCompleted = true;
			return true;
		}
		default:
		{
			FATAL("Invalid RTMP state: %d", _rtmpState);
			return false;
		}
	}
}
开发者ID:focusware,项目名称:crtmpserver,代码行数:57,代码来源:outboundrtmpprotocol.cpp

示例14: createHTTPResponse

// prepends the headers to the buffer for a http resonse.
IOBuffer ofxAMFHTTPResponse::createHTTPResponse(IOBuffer& buffer) {
	IOBuffer http_buffer;
	http_buffer.setup(buffer.getNumBytesStored());
	http_buffer.storeString("HTTP/1.1 200 OK\r\n");

	stringstream ss;
	ss << "Content-Length: " << buffer.getNumBytesStored() << "\r\n";
	http_buffer.storeString(ss.str());
	
	http_buffer.storeString("Connection: close\r\n");
	http_buffer.storeString("Content-type: application/x-amf\r\n");
	http_buffer.storeString("\r\n");
	
	http_buffer.storeBuffer(buffer);
	return http_buffer;

	
}
开发者ID:deathmemory,项目名称:ofxFlashCommunication,代码行数:19,代码来源:ofxAMFHTTPResponse.cpp

示例15:

bool InFileRTMPStream::MP3Builder::BuildFrame(MediaFile *pFile,
		MediaFrame &mediaFrame, IOBuffer &buffer) {
	buffer.ReadFromRepeat(0x2f, 1);

	//2. Seek into the data file at the correct position
	if (!pFile->SeekTo(mediaFrame.start)) {
		FATAL("Unable to seek to position %"PRIu64, mediaFrame.start);
		return false;
	}

	//3. Read the data
	if (!buffer.ReadFromFs(*pFile, (uint32_t) mediaFrame.length)) {
		FATAL("Unable to read %"PRIu64" bytes from offset %"PRIu64, mediaFrame.length, mediaFrame.start);
		return false;
	}

	return true;
}
开发者ID:2php,项目名称:crtmpserver,代码行数:18,代码来源:infilertmpstream.cpp


注:本文中的IOBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。