first version, unittest not fin

This commit is contained in:
Jay
2020-01-14 09:58:05 +00:00
parent c15c1c0421
commit ae33d3da00
11 changed files with 458 additions and 62 deletions
+10 -9
View File
@@ -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) {