Skip to content

Commit 12fec69

Browse files
committed
implement retry-now on SIGHUP (closes jpillora#51)
1 parent 03974d9 commit 12fec69

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (c *Client) loop() {
166166
c.Debugf("Connection error: %s", connerr)
167167
c.Infof("Retrying in %s...", d)
168168
connerr = nil
169-
time.Sleep(d)
169+
chshare.SleepSignal(d)
170170
}
171171
d := websocket.Dialer{
172172
ReadBufferSize: 1024,

share/signal.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//+build !windows
2+
3+
package chshare
4+
5+
import (
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
"time"
10+
)
11+
12+
//Sleep unless Signal
13+
func SleepSignal(d time.Duration) {
14+
//during this time, also listen for SIGHUP
15+
//(this uses 0xc to allow windows to compile)
16+
sig := make(chan os.Signal, 1)
17+
signal.Notify(sig, syscall.SIGHUP)
18+
select {
19+
case <-time.After(d):
20+
case <-sig:
21+
}
22+
signal.Stop(sig)
23+
}

share/signal_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//+build windows
2+
3+
package chshare
4+
5+
import "time"
6+
7+
//Sleep unless Signal
8+
func SleepSignal(d time.Duration) {
9+
time.Sleep(d) //not supported
10+
}

0 commit comments

Comments
 (0)