本文整理汇总了C++中NetworkPacket::set_data_size方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::set_data_size方法的具体用法?C++ NetworkPacket::set_data_size怎么用?C++ NetworkPacket::set_data_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPacket
的用法示例。
在下文中一共展示了NetworkPacket::set_data_size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: FilePath
//.........这里部分代码省略.........
update_status (STATUS_ERROR, 0,0);
return;
}
//
// Downloading Phase
//
update_status (STATUS_DOWNLOADING, 0,0);
// Hash the URL
FilePath temp_file_path = FilePath(HAL::save_dir().full_path() + "/" + MoreStrings::cast_to_string(MoreStrings::hash(url.full_url())));
// Create a temporary file
BinaryFileStream temp_file;
err = FileManager::open(temp_file, temp_file_path, false);
if (err != DT3_ERR_NONE) {
network->tcp_close(socket);
LOG_MESSAGE << "HTTPRequest: Unable to open file for writing.";
update_status (STATUS_ERROR, 0,0);
return;
}
LOG_MESSAGE << "HTTPRequest: Opened temp file at " << temp_file_path.full_path();
// Temporary storage for buffer
std::string data;
// Timer for timeout
TimerHires timeout_timer;
do {
// Get the results
NetworkPacket packet;
packet.set_data_size(1024*16);
err = network->tcp_recv(packet,socket);
// If we recieved some data, append it to the buffer
if (packet.data_size() > 0) {
data += packet.data_as_string();
append_data(data, temp_file);
timeout_timer.reset_abs_time();
}
// Check complete
if ( (_current_size == _total_size) && (_total_size > 0) ) {
break;
}
// If we hit our timeout, then we abort
if (timeout_timer.abs_time() > timeout) {
network->tcp_close(socket);
LOG_MESSAGE << "Http request timed out!";
update_status (STATUS_ERROR, 0,0);
// Remove the temporary file
temp_file_path.del();
return;
}
// Check for cancel
if (_cancelled) {
network->tcp_close(socket);
LOG_MESSAGE << "Http request cancelled!";
update_status (STATUS_CANCELLED, 0,0);
// Remove the temporary file
temp_file_path.del();
return;
}
} while (err == DT3_ERR_NET_WOULD_BLOCK || err == DT3_ERR_NONE);
// Close the connection, we're done
network->tcp_close(socket);
// Close off the stream
finalize_data(data, temp_file);
//
// Finalizing phase
//
// Move the file
save_path.del();
temp_file_path.move(save_path);
LOG_MESSAGE << "Saving file to " << save_path.full_path();
// Final update of status
update_status (STATUS_COMPLETE, _current_size, _total_size);
}