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