0
0
Fork 0
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:
Zack Scholl 2018-09-23 05:39:23 -07:00
parent 0a0c0bfd32
commit 8afc75f1fc
3 changed files with 10 additions and 0 deletions

View file

@ -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.

View file

@ -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 {

View file

@ -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: