本文整理汇总了C++中IOBuffer::ReadFromUDPFd方法的典型用法代码示例。如果您正苦于以下问题:C++ IOBuffer::ReadFromUDPFd方法的具体用法?C++ IOBuffer::ReadFromUDPFd怎么用?C++ IOBuffer::ReadFromUDPFd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOBuffer
的用法示例。
在下文中一共展示了IOBuffer::ReadFromUDPFd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnEvent
bool UDPCarrier::OnEvent(struct epoll_event &event) {
//1. Read data
if ((event.events & EPOLLIN) != 0) {
IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
o_assert(pInputBuffer != NULL);
if (!pInputBuffer->ReadFromUDPFd(_inboundFd, _ioAmount, _peerAddress)) {
FATAL("Unable to read data");
return false;
}
if (_ioAmount == 0) {
FATAL("Connection closed");
return false;
}
_rx += _ioAmount;
ADD_IN_BYTES_MANAGED(_type, _ioAmount);
if (!_pProtocol->SignalInputData(_ioAmount, &_peerAddress)) {
FATAL("Unable to signal data available");
return false;
}
}
//2. Write data
if ((event.events & EPOLLOUT) != 0) {
NYIR;
}
return true;
}
示例2: OnEvent
bool UDPCarrier::OnEvent(select_event &event) {
//3. Do the I/O
switch (event.type) {
case SET_READ:
{
IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
o_assert(pInputBuffer != NULL);
if (!pInputBuffer->ReadFromUDPFd(_inboundFd, _ioAmount, _peerAddress)) {
FATAL("Unable to read data");
return false;
}
_rx += _ioAmount;
ADD_IN_BYTES_MANAGED(_type, _ioAmount);
return _pProtocol->SignalInputData(_ioAmount, &_peerAddress);
}
case SET_WRITE:
{
_pProtocol->ReadyForSend();
return true;
}
default:
{
ASSERT("Invalid state: %hhu", event.type);
return false;
}
}
}
示例3: OnEvent
bool UDPCarrier::OnEvent(struct kevent &event) {
int32_t recvAmount = 0;
//3. Do the I/O
switch (event.filter) {
case EVFILT_READ:
{
IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer();
assert(pInputBuffer != NULL);
if (!pInputBuffer->ReadFromUDPFd(event.ident, recvAmount, _peerAddress)) {
FATAL("Unable to read data");
return false;
}
_rx += recvAmount;
return _pProtocol->SignalInputData(recvAmount, &_peerAddress);
}
case EVFILT_WRITE:
{
NYIR;
}
default:
{
ASSERT("Invalid state: %hu", event.filter);
return false;
}
}
}