Skip to content

Commit

Permalink
Use leaky buffer to when piping data.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Feb 28, 2013
1 parent eb62155 commit c34a655
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion shadowsocks/pipe.go
Expand Up @@ -2,6 +2,7 @@ package shadowsocks

import (
// "io"
"github.com/cyfdecyf/leakybuf"
"net"
"time"
)
Expand All @@ -17,10 +18,16 @@ func SetReadTimeout(c net.Conn) {
}
}

const bufSize = 4096
const nBuf = 2048

var pipeBuf = leakybuf.NewLeakyBuf(nBuf, bufSize)

// PipeThenClose copies data from src to dst, closes dst when done.
func PipeThenClose(src, dst net.Conn, timeoutOpt int) {
defer dst.Close()
buf := make([]byte, 4096)
buf := pipeBuf.Get()
defer pipeBuf.Put(buf)
for {
if timeoutOpt == SET_TIMEOUT {
SetReadTimeout(src)
Expand Down

0 comments on commit c34a655

Please sign in to comment.