mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 00:11:56 +03:00
Simplify relay
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user