本文整理汇总了C++中NetworkPacket::data方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::data方法的具体用法?C++ NetworkPacket::data怎么用?C++ NetworkPacket::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPacket
的用法示例。
在下文中一共展示了NetworkPacket::data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: udp_send
DTerr DeviceNetworkSockets::udp_send (const NetworkPacket &packet, const NetworkSocket &socket)
{
if (socket.is_empty())
return DT3_ERR_NONE;
DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());
struct sockaddr_storage sast = string_to_address(packet.network_address().network_address());
struct sockaddr *sa = (struct sockaddr *) &sast;
#if DT3_OS == DT3_ANDROID
::sendto( socket_raw,
packet.data(),
packet.data_size(),
0,
sa,
sizeof(sockaddr));
#else
::sendto( socket_raw,
packet.data(),
(DTuint) packet.data_size(),
0,
sa,
sa->sa_len);
#endif
return DT3_ERR_NONE;
}
示例2: tcp_recv
DTerr DeviceNetworkSockets::tcp_recv (NetworkPacket &packet, const NetworkSocket &socket)
{
if (socket.is_empty())
return DT3_ERR_NONE;
DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());
ssize_t size = ::recv( socket_raw,
packet.data(),
(DTuint) packet.data_size(),
0
);
if (size < 0) {
packet.set_data_size(0);
switch (errno) {
//case EAGAIN: // Same as EWOULDBLOCK
case EWOULDBLOCK:
return DT3_ERR_NET_WOULD_BLOCK;
default:
LOG_MESSAGE << "TCPRecv: recv: " << strerror(errno) << " (" << (DTuint) errno << ")";
return DT3_ERR_NET_UNKNOWN;
};
} else {
packet.set_data_size(size);
}
return DT3_ERR_NONE;
}
示例3: udp_recv
DTerr DeviceNetworkSockets::udp_recv (NetworkPacket &packet, const NetworkSocket &socket)
{
if (socket.is_empty())
return DT3_ERR_NONE;
DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());
struct sockaddr from;
socklen_t from_size = sizeof(from);
DTsize size = ::recvfrom( socket_raw,
packet.data(),
(DTuint) packet.data_size(),
0,
&from,
&from_size
);
if (size > 0) {
packet.set_network_address( address_to_string(&from) );
packet.set_data_size(size);
} else {
switch (errno) {
case EWOULDBLOCK: return DT3_ERR_NET_WOULD_BLOCK;
default: return DT3_ERR_NET_UNKNOWN;
};
}
return DT3_ERR_NONE;
}
示例4: tcp_send
DTerr DeviceNetworkSockets::tcp_send (const NetworkPacket &packet, const NetworkSocket &socket)
{
if (socket.is_empty())
return DT3_ERR_NONE;
DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());
::send( socket_raw,
packet.data(),
(DTuint) packet.data_size(),
0
);
return DT3_ERR_NONE;
}