statianzo / Fleck

C# Websocket Implementation
MIT License
2.25k stars 583 forks source link

fix: Send()-task is now properly awaitable and reacts to exceptions #334

Closed VinzSpring closed 10 months ago

VinzSpring commented 11 months ago

Previously, exceptions triggered by the closure of the underlying TCP-Socket were not adequately relayed to the caller of Send(...). Consequently, awaiting the outcome of connection.Send(...) was not feasible. This problem was prevalent in all connections where the client lost connectivity due to network issues, as it would not dispatch a close-event.

This update addresses these shortcomings, enabling the following:

try {
    conn.Send("Hello World!")
} catch (Exception e) {
   // pursue appropriate handling
}

Furthermore, the Task returned by Send was always instantly completed, which is now fixed too.

AppVeyorBot commented 11 months ago

:white_check_mark: Build Fleck 0.0.69-ci completed (commit https://github.com/statianzo/Fleck/commit/487b121e71 by @)

AppVeyorBot commented 11 months ago

:white_check_mark: Build Fleck 0.0.69-ci completed (commit https://github.com/statianzo/Fleck/commit/487b121e71 by @)

statianzo commented 11 months ago

Thanks for the contribution @VinzSpring. Is this something that should be fixed at the SocketWrapper.Send level so it returns a properly awaitable task?

VinzSpring commented 11 months ago

@statianzo yes, fixing it at the SocketWrapper level would be an option too. Do you want me to update my pull request or is it fine as is?

statianzo commented 11 months ago

If you could move it to the SocketWrapper, it may help establish a pattern for the other Task producing methods that may be in need of a change.