Skip to content

Commit

Permalink
implement retry-now on SIGHUP (closes #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Nov 23, 2017
1 parent 03974d9 commit 12fec69
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (c *Client) loop() {
c.Debugf("Connection error: %s", connerr)
c.Infof("Retrying in %s...", d)
connerr = nil
time.Sleep(d)
chshare.SleepSignal(d)
}
d := websocket.Dialer{
ReadBufferSize: 1024,
Expand Down
23 changes: 23 additions & 0 deletions share/signal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//+build !windows

package chshare

import (
"os"
"os/signal"
"syscall"
"time"
)

//Sleep unless Signal
func SleepSignal(d time.Duration) {
//during this time, also listen for SIGHUP
//(this uses 0xc to allow windows to compile)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP)
select {
case <-time.After(d):
case <-sig:
}
signal.Stop(sig)
}
10 changes: 10 additions & 0 deletions share/signal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//+build windows

package chshare

import "time"

//Sleep unless Signal
func SleepSignal(d time.Duration) {
time.Sleep(d) //not supported
}

0 comments on commit 12fec69

Please sign in to comment.