lxzan / gws

simple, fast, reliable websocket server & client, supports running over tcp/kcp/unix domain socket. keywords: ws, proxy, chat, go, golang...
https://pkg.go.dev/github.com/lxzan/gws
Apache License 2.0
1.34k stars 84 forks source link

Graceful termination of ReadLoop #48

Closed RandoMan70 closed 11 months ago

RandoMan70 commented 11 months ago

Something like WriteClose() but really closing connection and terminating ReadLoop?

lxzan commented 11 months ago

Calling WriteClose immediately exits the loop and closes the connection If you don't want to send a close frame, try socket.NetConn().Close()

lxzan commented 11 months ago

Are you worried that WriteClose won't make the loop exit immediately?

RandoMan70 commented 11 months ago

Thank you, NetConn().Close() works fine. I actually found that in my conditions WriteClose() does not exit loop, but I'm using custom Conn over raw sockets.

lxzan commented 11 months ago

I've just committed some code that calls the underlying connection's Close method in WriteClose. You can experience this with this command:

go get -v github.com/lxzan/gws@90819f9bb947a83d073061285be6e3a54c317cd3

There's very little change, and it'll be a while before I put an official tag on it.