Пример #1
0
// 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:
	}
}
Пример #2
0
// 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")
	}
}
Пример #3
0
func (rpool *ReaderPool) Put(reader *bufio.Reader) error {
	reader.Reset(nil)
	select {
	case rpool.buf <- reader:
	default:
		return errors.New("poolfull")
	}
	return nil
}
Пример #4
0
// 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
}
Пример #5
0
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
}
Пример #6
0
// Put puts the bufio.Reader back into the pool.
func (bufPool *BufioReaderPool) Put(b *bufio.Reader) {
	b.Reset(nil)
	bufPool.pool.Put(b)
}
Пример #7
0
func PutBufioReader(br *bufio.Reader) {
	br.Reset(nil)
	bufioReaderPool.Put(br)
}
Пример #8
0
func (bcl *BufferedConnListener) putBufioReader(br *bufio.Reader) {
	br.Reset(nil)
	bcl.bufioReaderPool.Put(br)
}
Пример #9
0
func (c *HostClient) releaseReader(br *bufio.Reader) {
	br.Reset(nil)
	c.readerPool.Put(br)
}
Пример #10
0
func releaseReader(s *Server, r *bufio.Reader) {
	r.Reset(nil)
	s.readerPool.Put(r)
}
Пример #11
0
Файл: gate.go Проект: hefju/cham
func putBufioReader(r *bufio.Reader) {
	r.Reset(nil)
	bufioReaderPool.Put(r)
}
Пример #12
0
func putBufioReader(br *bufio.Reader) {
	br.Reset(nil)
	bufioReaderCache.Put(br)
}
Пример #13
0
func releaseReader(ctx *RequestCtx, r *bufio.Reader) {
	r.Reset(nil)
	ctx.s.readerPool.Put(r)
}
Пример #14
0
func PutBufioReader(pool *sync.Pool, br *bufio.Reader) {
	br.Reset(nil)
	pool.Put(br)
}