一段给人两种不同感觉的代码
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifboolhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifXmlRpcServer::bindAndListen(int port, int backlog /**//*= 5*/)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif int fd = XmlRpcSocket::socket();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if (fd < 0)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not create socket (%s).", XmlRpcSocket::getErrorMsg().c_str());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif this->setfd(fd);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // Don't block on reads/writes
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if ( ! XmlRpcSocket::setNonBlocking(fd))
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif this->close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not set socket to non-blocking input mode (%s).", XmlRpcSocket::getErrorMsg().c_str());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // Allow this port to be re-bound immediately so server re-starts are not delayed
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if ( ! XmlRpcSocket::setReuseAddr(fd))
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif this->close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not set SO_REUSEADDR socket option (%s).", XmlRpcSocket::getErrorMsg().c_str());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // Bind to the specified port on the default interface
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if ( ! XmlRpcSocket::bind(fd, port))
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif this->close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not bind to specified port (%s).", XmlRpcSocket::getErrorMsg().c_str());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // Set in listening mode
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if ( ! XmlRpcSocket::listen(fd, backlog))
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif this->close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not set socket in listening mode (%s).", XmlRpcSocket::getErrorMsg().c_str());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif XmlRpcUtil::log(2, "XmlRpcServer::bindAndListen: server listening on port %d fd %d", port, fd);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // Notify the dispatcher to listen on this source when we are in work()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif _disp.addSource(this, XmlRpcDispatch::ReadableEvent);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return true;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
页:
[1]