Simplify relay

This commit is contained in:
9seconds
2021-03-29 10:37:09 +03:00
parent 3992054560
commit 4c3f42e264
3 changed files with 23 additions and 12 deletions
+10 -6
View File
@@ -1,19 +1,23 @@
package relay
import "io"
import (
"context"
"io"
)
type conn struct {
io.ReadWriteCloser
relay *Relay
ctx context.Context
tickChannel chan struct{}
}
func (c conn) Read(p []byte) (int, error) {
n, err := c.ReadWriteCloser.Read(p)
select {
case <-c.relay.ctx.Done():
case c.relay.tickChannel <- struct{}{}:
case <-c.ctx.Done():
case c.tickChannel <- struct{}{}:
}
return n, err // nolint: wrapcheck
@@ -23,8 +27,8 @@ func (c conn) Write(p []byte) (int, error) {
n, err := c.ReadWriteCloser.Write(p)
select {
case <-c.relay.ctx.Done():
case c.relay.tickChannel <- struct{}{}:
case <-c.ctx.Done():
case c.tickChannel <- struct{}{}:
}
return n, err // nolint: wrapcheck