first version, unittest not fin
This commit is contained in:
+10
-9
@@ -49,7 +49,7 @@ type setNoDelayer interface {
|
||||
SetNoDelay(bool) error
|
||||
}
|
||||
|
||||
func (p *Proxy) Start() (err error) {
|
||||
func (p *Proxy) Start(ctx context.Context) (err error) {
|
||||
defer p.lconn.Close()
|
||||
|
||||
if p.tlsUnwrapp {
|
||||
@@ -76,18 +76,19 @@ func (p *Proxy) Start() (err error) {
|
||||
//display both ends
|
||||
p.Log.Info("Opened %s >>>> %s", p.laddr.String(), p.raddr.String())
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
//bidirectional copy
|
||||
go p.pipe(ctx, p.lconn, p.rconn)
|
||||
go p.pipe(ctx, p.rconn, p.lconn)
|
||||
|
||||
// wait for close
|
||||
err = <-p.errsig
|
||||
p.Log.Info("Closed (%d bytes send, %d bytes received)", p.sendBytes, p.receivedBytes)
|
||||
cancel()
|
||||
|
||||
return
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
p.Log.Info("Context Done (%d bytes send, %d bytes received)", p.sendBytes, p.receivedBytes)
|
||||
return
|
||||
// wait for close
|
||||
case err = <-p.errsig:
|
||||
p.Log.Info("Closed (%d bytes send, %d bytes received)", p.sendBytes, p.receivedBytes)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Proxy) err(s string, err error) {
|
||||
|
||||
Reference in New Issue
Block a user