1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
package toxics
import "time"
// The SlowCloseToxic stops the TCP connection from closing until after a delay.
type SlowCloseToxic struct {
// Times in milliseconds
Delay int64 `json:"delay"`
}
func (t *SlowCloseToxic) Pipe(stub *ToxicStub) {
for {
select {
case <-stub.Interrupt:
return
case c := <-stub.Input:
if c == nil {
delay := time.Duration(t.Delay) * time.Millisecond
select {
case <-time.After(delay):
stub.Close()
return
case <-stub.Interrupt:
return
}
}
stub.Output <- c
}
}
}
func init() {
Register("slow_close", new(SlowCloseToxic))
}
|