Callisto82 / tftp.net

Implements the TFTP (Trivial File Transfer) protocol (client/server) in an easy-to-use C#/.NET library.
Microsoft Public License
81 stars 38 forks source link

Closing the stream. #40

Closed xiejiang2014 closed 3 months ago

xiejiang2014 commented 3 months ago

It may not be appropriate to close the stream object passed in from the outside, as it is not possible to determine whether the stream will continue to be used.

https://github.com/Callisto82/tftp.net/blob/38c03ff43458b37ae65ea776e1ef90b4cecd6b27/Tftp.Net/Transfer/TftpTransfer.cs#L213

Callisto82 commented 3 months ago

Well, that's the convention that I was using within the library and I think it works quite well for most use cases. The stream must not be closed before the TFTP transfer is completed, which happens asynchronously. That's not easy to do, so I found it more appropriate for the library to close the stream. If you really don't want that to happen, just pass in a decorator that overrides the Stream.Close() with an empty implementation. That allows you to control closing the stream yourself.