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


C++ TCPSocket::setNonBlockingMode方法代码示例

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


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

示例1: accept

TCPSocket TCPServerSocket::accept(){
	if(!*this){
		throw setka::Exc("TCPServerSocket::Accept(): the socket is not opened");
	}

	this->clearCanReadFlag();

	sockaddr_storage sockAddr;

#if M_OS == M_OS_WINDOWS
	int sock_alen = sizeof(sockAddr);
#elif M_OS == M_OS_LINUX || M_OS == M_OS_MACOSX || M_OS == M_OS_UNIX
	socklen_t sock_alen = sizeof(sockAddr);
#else
#	error "Unsupported OS"
#endif

	TCPSocket sock;//allocate a new socket object

	sock.socket = ::accept(
			this->socket,
			reinterpret_cast<sockaddr*>(&sockAddr),
			&sock_alen
		);

	if(sock.socket == DInvalidSocket()){
		return sock;//no connections to be accepted, return invalid socket
	}

#if M_OS == M_OS_WINDOWS
	sock.createEventForWaitable();

	//NOTE: accepted socket is associated with the same event object as the listening socket which accepted it.
	//Re-associate the socket with its own event object.
	sock.setWaitingEvents(0);
#endif

	sock.setNonBlockingMode();

	if(this->disableNaggle){
		sock.disableNaggle();
	}

	return sock;//return a newly created socket
}
开发者ID:igagis,项目名称:setka,代码行数:45,代码来源:TCPServerSocket.cpp


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