本文整理汇总了C++中TCPSocket::set_timeout方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::set_timeout方法的具体用法?C++ TCPSocket::set_timeout怎么用?C++ TCPSocket::set_timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::set_timeout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_tcp_echo_async
/**
* Test TCP data exchange via the asynchronous sigio() mechanism
*/
void test_tcp_echo_async()
{
TCPSocket sock;
SocketAddress host_address;
bool callback_triggered = false;
int x;
int size;
driver.disconnect();
TEST_ASSERT(do_connect(&driver) == 0);
TEST_ASSERT(
driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0);
host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT);
tr_debug("TCP: Server %s address: %s on port %d.",
MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(),
host_address.get_port());
TEST_ASSERT(sock.open(&driver) == 0)
// Set up the async callback and set the timeout to zero
sock.sigio(callback(async_cb, &callback_triggered));
sock.set_timeout(0);
TEST_ASSERT(sock.connect(host_address) == 0);
// Test min, max, and some random sizes in-between
do_tcp_echo_async(&sock, 1, &callback_triggered);
do_tcp_echo_async(&sock, MBED_CONF_APP_TCP_MAX_PACKET_SIZE,
&callback_triggered);
sock.close();
drop_connection(&driver);
tr_debug("TCP packets of size up to %d byte(s) echoed asynchronously and successfully.",
MBED_CONF_APP_TCP_MAX_PACKET_SIZE);
}