温和的关闭连接
2008-04-09 04:25:55来源:互联网 阅读 ()
Connection Closed Gracefully
温和的关闭连接
Many Indy users are annoyed by the EIdConnClosedGracefully exception that is raised with Indy servers, especially the HTTP and other servers. EIdConnClosedGracefully is an exception signaling that the connection has been closed by the other side intentionally. This is not the same as a broken connection which would cause a connection reset error. If the other side has closed the connection and the socket is read or written to, EIdConnClosedGracefully will be raised by Indy. This is similar to attempting to read or write to a file that has been closed without your knowledge.
很多Indy组件的用户常常因为Indy server抛出的EIdConnClosedGracefully异常而烦恼,特别是HTTP和其他的server。EIdConnClosedGracefully是连接已经被另一方故意的关闭的象征。这与导致连接复位的错误所致的断开的连接不同。如果另一方已经关闭了连接,并且仍然向套接字中读写,Indy组件将会抛出EIdConnClosedGracefully异常。这与您尝试向一个在您不知情的情况下被关闭的文件中读写数据是很相似的。
In some cases this is a true exception and your code needs to handle it. In other cases (typically servers) this is a normal part of the functioning of the protocol and Indy handles this exception for you. Even though Indy catches it, when running in the IDE the debugger will be triggered first. You can simply press F9 to continue and Indy will handle the exception, but the constant stopping during debugging can be quite annoying. In the cases where Indy catches the exception, your users will never see an exception in your program unless it is run from the IDE.
在有些情况下这是一个真的异常,你需要编程处理它。在另外一些情况下(典型的服务器),这是协议功能的正常的一部分,Indy组件会为您处理这个异常。即使Indy组件捕捉到了这个异常,当在IDE编程环境中运行时,调试器也将会首先触发它。你只要按F9键继续运行,Indy组件将会处理这个异常,但是在调试期间不断的停止运行是非常烦人的。在Indy组件捕捉到这个异常的情况下,除非在IDE中运行,否则您的用户将不会再看到异常提示。
Simple solution
简单的解决方法
Because the EIdConnClosedGracefully is a common exception especially with certain servers it descends from EIdSilentException. On the Language Exceptions tab of Debugger Options (Tools Menu) you can add EIdSilentException to the list of exceptions to ignore. After this is added the exceptions will still occur in the code and be handled, but the debugger will not stop the program to debug them.
因为对于从EIdSilentException继承来的服务器,EIdConnClosedGracefully是一个正常的异常。您可以在“Tools”菜单的“Debugger Options”的“Language Exceptions”选项卡中将EIdSilentException加到忽略的异常的列表中。当加到忽略的异常的列表中后这个异常仍然会在代码中触发并被处理,但是调试器将不会停止程序的运行。
Is it an error?
这是一个错误吗?
All exceptions are not errors. Many developers have been taught or assumed that all exceptions are errors. However this is not the case, and this is why they are called exceptions and not errors.
异常不一定是错误。很多开发者都认为所有的异常都是错误。但是事实不是这样的,这就是为什么之所以叫异常而不叫错误的原因。
Exceptions are exactly that - exceptions. Delphi and C Builder use exceptions to handle errors in an elegant way. However exceptions have other uses besides errors as well. EAbort is one example of an exception that is not necessarily an error. Exceptions such as these are used to modify standard program flow and communicate information to a higher calling level where they are trapped. Indy uses exceptions in such a way as well.
异常就是异常。Delphi 和 C Builder 使用异常处理错误。但是异常有错误之外的其他用途。EAbort是一个异常不一定是错误的例子。这样的异常用来将标准的程序流程和交流信息调整到一个更高的能被捕捉到的层次
。Indy组件也是这样使用异常的。
Why is it an exception?
它为什么是一个异常?
Many users have commented that maybe it there should be a return value to signal this condition instead of an exception. However this is the wrong approach in this case.
许多用户说它应该返回一个信号而不是一个异常。但是在这种情况下这是一个错误的方式。
The EIdConnClosedGracefully is raised from a core routine, however when this routine is called it is normally several method calls deep. The EIdConnClosedGracefully is in fact an exception and needs to be trapped by the topmost caller in most cases. The proper way to handle this is an exception.
EIdConnClosedGracefully异常从核心循环抛出,但是当这个循环被调用时,有几种在深层调用的方法。 EIdConnClosedGracefully实际上是一个异常,并且在很多情况下需要被顶层调用者捕捉。处理它的正确的方法是捕获异常。
When is it an error?
什么时候它是一个错误呢?
When EIdConnClosedGracefully is raised in a client, it is an error and you should trap and handle this exception.
当客户端抛出一个EIdConnClosedGracefully时,它就是一个错误,您就应当捕捉并且处理这个异常。
In servers it is an exception. However sometimes it is an error, and sometimes it is an exception. For many protocols this exception is part of the normal functioning of the protocol. Because of this common behavior, if you do not catch the EIdConnClosedGracefully in your server code, Indy will. It will then mark the connection as closed and stop the thread assigned to the connection. If you wish to handle this exception yourself you may, otherwise Indy will handle it and take the appropriate actions for you automatically.
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:delphi7从入门到精通之四
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash