当前位置: 首页>>代码示例>>C++>>正文


C++ StreamSocket::poll方法代码示例

本文整理汇总了C++中StreamSocket::poll方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamSocket::poll方法的具体用法?C++ StreamSocket::poll怎么用?C++ StreamSocket::poll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StreamSocket的用法示例。


在下文中一共展示了StreamSocket::poll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testSelect

void SocketTest::testSelect()
{
	Timespan timeout(250000);

	EchoServer echoServer;
	StreamSocket ss;
	ss.connect(SocketAddress("localhost", echoServer.port()));

	Socket::SocketList readList;
	Socket::SocketList writeList;
	Socket::SocketList exceptList;

	readList.push_back(ss);
	assert (Socket::select(readList, writeList, exceptList, timeout) == 0);
	assert (readList.empty());
	assert (writeList.empty());
	assert (exceptList.empty());
	
	ss.sendBytes("hello", 5);

	ss.poll(timeout, Socket::SELECT_READ);

	readList.push_back(ss);
	writeList.push_back(ss);
	assert (Socket::select(readList, writeList, exceptList, timeout) == 2);
	assert (!readList.empty());
	assert (!writeList.empty());
	assert (exceptList.empty());

	char buffer[256];
	int n = ss.receiveBytes(buffer, sizeof(buffer));
	assert (n == 5);
	assert (std::string(buffer, n) == "hello");
	ss.close();
}
开发者ID:Alcibiades586,项目名称:roadrunner,代码行数:35,代码来源:SocketTest.cpp

示例2: testNonBlocking

void SocketTest::testNonBlocking()
{
	EchoServer echoServer;
	StreamSocket ss;
	ss.connect(SocketAddress("localhost", echoServer.port()));
	ss.setBlocking(false);

	Timespan timeout(1000000);
	assert (ss.poll(timeout, Socket::SELECT_WRITE));
	int n = ss.sendBytes("hello", 5);
	assert (n == 5);

	char buffer[256];
	assert (ss.poll(timeout, Socket::SELECT_READ));
	n = ss.receiveBytes(buffer, sizeof(buffer));
	assert (n == 5);
	assert (std::string(buffer, n) == "hello");
	ss.close();
}
开发者ID:Alcibiades586,项目名称:roadrunner,代码行数:19,代码来源:SocketTest.cpp

示例3: testPoll

void SocketTest::testPoll()
{
	EchoServer echoServer;
	StreamSocket ss;
	ss.connect(SocketAddress("localhost", echoServer.port()));
	Stopwatch sw;
	sw.start();
	Timespan timeout(1000000);
	assert (!ss.poll(timeout, Socket::SELECT_READ));
	assert (sw.elapsed() >= 900000);
	sw.restart();
	assert (ss.poll(timeout, Socket::SELECT_WRITE));
	assert (sw.elapsed() < 100000);
	ss.sendBytes("hello", 5);
	char buffer[256];
	sw.restart();
	assert (ss.poll(timeout, Socket::SELECT_READ));
	assert (sw.elapsed() < 100000);
	int n = ss.receiveBytes(buffer, sizeof(buffer));
	assert (n == 5);
	assert (std::string(buffer, n) == "hello");
	ss.close();
}
开发者ID:Alcibiades586,项目名称:roadrunner,代码行数:23,代码来源:SocketTest.cpp


注:本文中的StreamSocket::poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。