确定流何时关闭

发布于 2024-10-28 06:44:33 字数 592 浏览 1 评论 0原文

我正在尝试实现一个网络协议类,其接口类似于 WebRequest 特别是 GetRequestStream 返回的输入流,但是我很难确定请求流何时完成,因为它没有任何事件(处置等)。

如何监视流以确定其何时关闭/处置?我唯一的选择是将其包装在实现 Stream?


特别是,我正在实现 FTP,其中包含 FtpWebRequest 没有的一些功能(SITEALLOC 等)。我需要知道数据流何时关闭/完成,以便我可以检查命令流是否成功或错误消息。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半山落雨半山空 2024-11-04 06:44:33

我相信流不提供处置/关闭事件的原因是唯一需要知道的是它的所有者 - 并且所有者会调用它本身。

处理流必须是显式操作,因此事件没有多大意义。话虽如此,流的所有者可以公开事件并通知其客户端操作结束。

此外,举办活动意味着可以在多个客户端之间共享流,我再次认为这不是一个好的做法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文