github.com/wangyougui/gf/v2@v2.6.5/os/gfpool/gfpool.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  // Package gfpool provides io-reusable pool for file pointer.
     8  package gfpool
     9  
    10  import (
    11  	"os"
    12  	"time"
    13  
    14  	"github.com/wangyougui/gf/v2/container/gmap"
    15  	"github.com/wangyougui/gf/v2/container/gpool"
    16  	"github.com/wangyougui/gf/v2/container/gtype"
    17  )
    18  
    19  // Pool pointer pool.
    20  type Pool struct {
    21  	id   *gtype.Int    // Pool id, which is used to mark this pool whether recreated.
    22  	pool *gpool.Pool   // Underlying pool.
    23  	init *gtype.Bool   // Whether initialized, used for marking this file added to fsnotify, and it can only be added just once.
    24  	ttl  time.Duration // Time to live for file pointer items.
    25  }
    26  
    27  // File is an item in the pool.
    28  type File struct {
    29  	*os.File             // Underlying file pointer.
    30  	stat     os.FileInfo // State of current file pointer.
    31  	pid      int         // Belonging pool id, which is set when file pointer created. It's used to check whether the pool is recreated.
    32  	pool     *Pool       // Belonging ool.
    33  	flag     int         // Flash for opening file.
    34  	perm     os.FileMode // Permission for opening file.
    35  	path     string      // Absolute path of the file.
    36  }
    37  
    38  var (
    39  	// Global file pointer pool.
    40  	pools = gmap.NewStrAnyMap(true)
    41  )