// put back reader to the chan, if chan is full then discard it func (b *TCPReadBuf) Put(buf *bufio.Reader, idx int) { buf.Reset(nil) select { case b.instance[idx] <- buf: default: } }
// putBufioReader pub back a Reader to chan, if chan full discard it. func putBufioReader(c chan *bufio.Reader, r *bufio.Reader) { r.Reset(nil) select { case c <- r: default: log.Warn("tcp bufioReader cache full") } }
func (rpool *ReaderPool) Put(reader *bufio.Reader) error { reader.Reset(nil) select { case rpool.buf <- reader: default: return errors.New("poolfull") } return nil }
// tunneling to backend func tunneling(addr string, rdr *bufio.Reader, c net.Conn, header *bytes.Buffer) error { backend, err := dialTimeout("tcp", addr, time.Second*time.Duration(_BackendDialTimeout)) if err != nil { // handle error switch err := err.(type) { case net.Error: if err.Timeout() { writeErrCode(c, []byte("4101"), false) return err } } writeErrCode(c, []byte("4102"), false) return err } defer backend.Close() if header != nil { header.WriteTo(backend) } if n := rdr.Buffered(); n > 0 { var data []byte data, err = rdr.Peek(n) if err != nil { writeErrCode(c, []byte("4103"), false) return err } _, err = backend.Write(data) if err != nil { writeErrCode(c, []byte("4102"), false) return err } } rdr.Reset(nil) _BufioReaderPool.Put(rdr) // Start transfering data go pipe(c, backend) pipe(backend, c) return nil }
func (ac *addrCache) scan() ([]Account, error) { files, err := ioutil.ReadDir(ac.keydir) if err != nil { return nil, err } var ( buf = new(bufio.Reader) addrs []Account keyJSON struct { Address common.Address `json:"address"` } ) for _, fi := range files { path := filepath.Join(ac.keydir, fi.Name()) if skipKeyFile(fi) { glog.V(logger.Detail).Infof("ignoring file %s", path) continue } fd, err := os.Open(path) if err != nil { glog.V(logger.Detail).Infoln(err) continue } buf.Reset(fd) // Parse the address. keyJSON.Address = common.Address{} err = json.NewDecoder(buf).Decode(&keyJSON) switch { case err != nil: glog.V(logger.Debug).Infof("can't decode key %s: %v", path, err) case (keyJSON.Address == common.Address{}): glog.V(logger.Debug).Infof("can't decode key %s: missing or zero address", path) default: addrs = append(addrs, Account{Address: keyJSON.Address, File: path}) } fd.Close() } return addrs, err }
// Put puts the bufio.Reader back into the pool. func (bufPool *BufioReaderPool) Put(b *bufio.Reader) { b.Reset(nil) bufPool.pool.Put(b) }
func PutBufioReader(br *bufio.Reader) { br.Reset(nil) bufioReaderPool.Put(br) }
func (bcl *BufferedConnListener) putBufioReader(br *bufio.Reader) { br.Reset(nil) bcl.bufioReaderPool.Put(br) }
func (c *HostClient) releaseReader(br *bufio.Reader) { br.Reset(nil) c.readerPool.Put(br) }
func releaseReader(s *Server, r *bufio.Reader) { r.Reset(nil) s.readerPool.Put(r) }
func putBufioReader(r *bufio.Reader) { r.Reset(nil) bufioReaderPool.Put(r) }
func putBufioReader(br *bufio.Reader) { br.Reset(nil) bufioReaderCache.Put(br) }
func releaseReader(ctx *RequestCtx, r *bufio.Reader) { r.Reset(nil) ctx.s.readerPool.Put(r) }
func PutBufioReader(pool *sync.Pool, br *bufio.Reader) { br.Reset(nil) pool.Put(br) }