mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
listen for interrupt in websockets
This commit is contained in:
parent
0a0c0bfd32
commit
8afc75f1fc
3 changed files with 10 additions and 0 deletions
|
@ -152,6 +152,10 @@ func (c *Croc) sendReceive(websocketAddress, fname, codephrase string, isSender
|
|||
return nil
|
||||
case <-interrupt:
|
||||
log.Debug("interrupt")
|
||||
err = sock.WriteMessage(websocket.TextMessage, []byte("interrupt"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Cleanly close the connection by sending a close message and then
|
||||
// waiting (with timeout) for the server to close the connection.
|
||||
|
|
|
@ -73,6 +73,9 @@ func receive(isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool,
|
|||
if messageType == websocket.PongMessage || messageType == websocket.PingMessage {
|
||||
continue
|
||||
}
|
||||
if messageType == websocket.TextMessage && bytes.Equal(messsage, "interrupt") {
|
||||
return errors.New("interrupted by other party")
|
||||
}
|
||||
|
||||
log.Debugf("got %d: %s", messageType, message)
|
||||
switch step {
|
||||
|
|
|
@ -78,6 +78,9 @@ func send(isLocal bool, c *websocket.Conn, fname string, codephrase string, useC
|
|||
if messageType == websocket.PongMessage || messageType == websocket.PingMessage {
|
||||
continue
|
||||
}
|
||||
if messageType == websocket.TextMessage && bytes.Equal(messsage, "interrupt") {
|
||||
return errors.New("interrupted by other party")
|
||||
}
|
||||
log.Debugf("got %d: %s", messageType, message)
|
||||
switch step {
|
||||
case 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue