mirror of
https://github.com/go-i2p/go-i2ptunnel.git
synced 2025-07-15 02:01:59 -04:00
Add interrupt handlers to tcp server/client
This commit is contained in:
@ -89,13 +89,18 @@ func (t *TCPClient) Start() error {
|
||||
defer listener.Close()
|
||||
t.I2PTunnelStatus = i2ptunnel.I2PTunnelStatusRunning
|
||||
for {
|
||||
con, err := listener.Accept()
|
||||
if err != nil {
|
||||
continue
|
||||
select {
|
||||
case <-t.done:
|
||||
return nil
|
||||
default:
|
||||
con, err := listener.Accept()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defer con.Close()
|
||||
ctx := context.Background()
|
||||
stream.Forward(ctx, con, i2pConn, config.DefaultConfig())
|
||||
}
|
||||
defer con.Close()
|
||||
ctx := context.Background()
|
||||
stream.Forward(ctx, con, i2pConn, config.DefaultConfig())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,19 +79,24 @@ func (t *TCPServer) Start() error {
|
||||
t.I2PTunnelStatus = i2ptunnel.I2PTunnelStatusRunning
|
||||
limitedI2PListener := limitedlistener.NewLimitedListener(i2pListener, limitedlistener.WithMaxConnections(t.LimitedConfig.MaxConns), limitedlistener.WithRateLimit(t.LimitedConfig.RateLimit))
|
||||
for {
|
||||
con, err := limitedI2PListener.Accept()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
select {
|
||||
case <-t.done:
|
||||
return nil
|
||||
default:
|
||||
con, err := limitedI2PListener.Accept()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
defer con.Close()
|
||||
lCon, err := net.Dial("tcp", t.Target())
|
||||
if err != nil {
|
||||
continue
|
||||
defer con.Close()
|
||||
lCon, err := net.Dial("tcp", t.Target())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defer lCon.Close()
|
||||
ctx := context.Background()
|
||||
stream.Forward(ctx, con, lCon, config.DefaultConfig())
|
||||
}
|
||||
defer lCon.Close()
|
||||
ctx := context.Background()
|
||||
stream.Forward(ctx, con, lCon, config.DefaultConfig())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user