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


C++ IOBuffer::ReadFromTCPFd方法代码示例

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


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

示例1: OnEvent

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

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

			while ((pOutputBuffer = _pProtocol->GetOutputBuffer()) != NULL) {
				if (!pOutputBuffer->WriteToTCPFd(_outboundFd,
						_sendBufferSize, writeAmount)) {
					FATAL("Unable to send data. %s:%hu -> %s:%hu",
							STR(_farIp), _farPort,
							STR(_nearIp), _nearPort);
					IOHandlerManager::EnqueueForDelete(this);
					return false;
				}
				_tx += writeAmount;
				_pProtocol->OnSendAmount(writeAmount);
				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:jacklgp,项目名称:xhome,代码行数:53,代码来源:tcpcarrier.cpp

示例2: OnEvent

bool TCPCarrier::OnEvent(struct kevent &event) {
	//3. Do the I/O
	switch (event.filter) {
		case EVFILT_READ:
		{
			IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
			o_assert(pInputBuffer != NULL);
			if (!pInputBuffer->ReadFromTCPFd(event.ident, event.data, _ioAmount,
					_lastRecvError)) {
				FATAL("Unable to read data from connection: %s. Error was (%d): %s",
						(_pProtocol != NULL) ? STR(*_pProtocol) : "", _lastRecvError,
						strerror(_lastRecvError));
				return false;
			}
			_rx += _ioAmount;
			ADD_IN_BYTES_MANAGED(_type, _ioAmount);
			if (!_pProtocol->SignalInputData(_ioAmount)) {
				FATAL("Unable to read data from connection: %s. Signaling upper protocols failed",
						(_pProtocol != NULL) ? STR(*_pProtocol) : "");
				return false;
			}
			return true;
		}
		case EVFILT_WRITE:
		{
			IOBuffer *pOutputBuffer = NULL;
			if ((pOutputBuffer = _pProtocol->GetOutputBuffer()) != NULL) {
				if (!pOutputBuffer->WriteToTCPFd(event.ident, event.data,
						_ioAmount, _lastSendError)) {
					FATAL("Unable to write data on connection: %s. Error was (%d): %s",
							(_pProtocol != NULL) ? STR(*_pProtocol) : "", _lastSendError,
							strerror(_lastSendError));
					IOHandlerManager::EnqueueForDelete(this);
					return false;
				}
				_tx += _ioAmount;
				ADD_OUT_BYTES_MANAGED(_type, _ioAmount);
				if (GETAVAILABLEBYTESCOUNT(*pOutputBuffer) == 0) {
					DISABLE_WRITE_DATA;
				}
			} else {
				DISABLE_WRITE_DATA;
			}
			return true;
		}
		default:
		{
			FATAL("Unable to read/write data from/to connection: %s. Invalid event type: %d",
					(_pProtocol != NULL) ? STR(*_pProtocol) : "", event.filter);
			return false;
		}
	}
}
开发者ID:9aa5,项目名称:crtmpserver,代码行数:53,代码来源:tcpcarrier.cpp

示例3: OnEvent

bool TCPCarrier::OnEvent(struct kevent &event) {
	//3. Do the I/O
	switch (event.filter) {
		case EVFILT_READ:
		{
			IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
			o_assert(pInputBuffer != NULL);
			if (!pInputBuffer->ReadFromTCPFd(event.ident, event.data, _ioAmount)) {
				FATAL("Unable to read data. %s:%"PRIu16" -> %s:%"PRIu16" %s",
						STR(_farIp), _farPort,
						STR(_nearIp), _nearPort,
						(_pProtocol != NULL) ? STR(*_pProtocol) : ""
						);
				return false;
			}
			_rx += _ioAmount;
			ADD_IN_BYTES_MANAGED(_type, _ioAmount);
			return _pProtocol->SignalInputData(_ioAmount);
		}
		case EVFILT_WRITE:
		{
			IOBuffer *pOutputBuffer = NULL;

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

示例4: OnEvent

bool TCPCarrier::OnEvent(struct epoll_event &event) {
	//1. Read data
	if ((event.events & EPOLLIN) != 0) {
		IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
		o_assert(pInputBuffer != NULL);
		if (!pInputBuffer->ReadFromTCPFd(_inboundFd, _recvBufferSize, _ioAmount)) {
			FATAL("Unable to read data. %s:%hu -> %s:%hu",
					STR(_farIp), _farPort,
					STR(_nearIp), _nearPort);
			return false;
		}
		_rx += _ioAmount;
		ADD_IN_BYTES_MANAGED(_type, _ioAmount);
		if (_ioAmount == 0) {
			FATAL("Connection closed");
			return false;
		}

		if (!_pProtocol->SignalInputData(_ioAmount)) {
			FATAL("Unable to signal data available");
			return false;
		}
	}

	//2. Write data
	if ((event.events & EPOLLOUT) != 0) {
		IOBuffer *pOutputBuffer = NULL;

		if ((pOutputBuffer = _pProtocol->GetOutputBuffer()) != NULL) {
			if (!pOutputBuffer->WriteToTCPFd(_inboundFd, _sendBufferSize, _ioAmount)) {
				FATAL("Unable to send data. %s:%hu -> %s:%hu",
						STR(_farIp), _farPort,
						STR(_nearIp), _nearPort);
				IOHandlerManager::EnqueueForDelete(this);
				return false;
			}
			_tx += _ioAmount;
			ADD_OUT_BYTES_MANAGED(_type, _ioAmount);
			if (GETAVAILABLEBYTESCOUNT(*pOutputBuffer) == 0) {
				DISABLE_WRITE_DATA;
			}
		} else {
			DISABLE_WRITE_DATA;
		}
	}

	return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:48,代码来源:tcpcarrier.cpp

示例5: OnEvent

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


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