一段给人两种不同感觉的代码
2008-03-31 18:04
218 查看
bool
XmlRpcServer::bindAndListen(int port, int backlog /**//*= 5*/)
...{
int fd = XmlRpcSocket::socket();
if (fd < 0)
...{
XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not create socket (%s).", XmlRpcSocket::getErrorMsg().c_str());
return false;
}
this->setfd(fd);
// Don't block on reads/writes
if ( ! XmlRpcSocket::setNonBlocking(fd))
...{
this->close();
XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not set socket to non-blocking input mode (%s).", XmlRpcSocket::getErrorMsg().c_str());
return false;
}
// Allow this port to be re-bound immediately so server re-starts are not delayed
if ( ! XmlRpcSocket::setReuseAddr(fd))
...{
this->close();
XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not set SO_REUSEADDR socket option (%s).", XmlRpcSocket::getErrorMsg().c_str());
return false;
}
// Bind to the specified port on the default interface
if ( ! XmlRpcSocket::bind(fd, port))
...{
this->close();
XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not bind to specified port (%s).", XmlRpcSocket::getErrorMsg().c_str());
return false;
}
// Set in listening mode
if ( ! XmlRpcSocket::listen(fd, backlog))
...{
this->close();
XmlRpcUtil::error("XmlRpcServer::bindAndListen: Could not set socket in listening mode (%s).", XmlRpcSocket::getErrorMsg().c_str());
return false;
}
XmlRpcUtil::log(2, "XmlRpcServer::bindAndListen: server listening on port %d fd %d", port, fd);
// Notify the dispatcher to listen on this source when we are in work()
_disp.addSource(this, XmlRpcDispatch::ReadableEvent);
return true;
}
这是XML RPC++ 里面的一段实现端口绑定与监听的代码。
两种完全不同的感觉:
1、非常完美,考虑非常完善,每一步都考虑了执行结果是否正确,根据每一步的执行结果来决定下一步的操作;
2、非常丑陋。真正执行的功能代码淹没在众多异常处理代码中;
相关文章推荐
- 点石互动--highdiy之:Google Sitelinks分析
- CLR via C# 读书笔记(九)静态类,类型对象的生存周期
- 使用VBScript开发自动化测试脚本3
- c# IDictionary接口的应用
- struts应用中重复提交的问题的三种解决方案
- CLR via C# 读书笔记(八)静态类和线程安全
- C#,ArcGIS Engine开发入门教程
- 在ASP.NET中使用JSON
- ASP中---无组件上传的原理
- java的九种排序算法
- C#委托之个人理解
- UBuntu中增加中文字符编码的方法
- C#,Cshape, ArcEngine的命令调用的形式区别
- 认识Delphi的线程类
- ASP.NET MVC+LINQ开发一个图书销售站点
- Weblogic92+CXF+XDoclet+Spring轻松搞定webservice
- Asp.Net中获取Castle容器中的服务的另一方法
- eclipse.ini内存设置
- C#中DataGridView多層表頭的制作(2)
- Castle IOC容器与Spring.NET配置之比较