确定流何时关闭
我正在尝试实现一个网络协议类,其接口类似于 WebRequest 特别是 GetRequestStream 返回的输入流,但是我很难确定请求流何时完成,因为它没有任何事件(处置等)。
如何监视流以确定其何时关闭/处置?我唯一的选择是将其包装在实现 Stream?
特别是,我正在实现 FTP,其中包含 FtpWebRequest 没有的一些功能(SITE
、ALLOC
等)。我需要知道数据流何时关闭/完成,以便我可以检查命令流是否成功或错误消息。
I'm trying to implement a network protocol class with an interface similar to WebRequest specifically with the input stream returned by GetRequestStream, however I am having difficulty determining when the request stream is complete, as it does not have any events (disposing, etc).
How can I monitor a Stream to determine when it is Closed/Disposed? Is my only choice to wrap it in a class that implements Stream?
In particular I'm implementing FTP with some features that the FtpWebRequest does not (SITE
, ALLOC
, etc). I need to know when the data stream is closed/complete so I can check the command stream for a success or error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信流不提供处置/关闭事件的原因是唯一需要知道的是它的所有者 - 并且所有者会调用它本身。
处理流必须是显式操作,因此事件没有多大意义。话虽如此,流的所有者可以公开事件并通知其客户端操作结束。
此外,举办活动意味着可以在多个客户端之间共享流,我再次认为这不是一个好的做法。
I believe the reason stream does not provide an event for disposing/closing is that the only person needs to know is the owner of it - and the owner would call it itself.
Disposing a stream must be an explicit operation hence an event would not make much sense. Having said that, owner of the stream can expose an event and inform its clients about Operation ending.
Also having an event means that the stream can be shared among multiple clients which again I believe is not a good practice.