github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/common/fdlimit/fdlimit_windows.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package fdlimit
    13  
    14  import "errors"
    15  
    16  // Raise tries to maximize the file descriptor allowance of this process
    17  // to the maximum hard-limit allowed by the OS.
    18  func Raise(max uint64) error {
    19  	// This method is NOP by design:
    20  	//  * Linux/Darwin counterparts need to manually increase per process limits
    21  	//  * On Windows Go uses the CreateFile API, which is limited to 16K files, non
    22  	//    changeable from within a running process
    23  	// This way we can always "request" raising the limits, which will either have
    24  	// or not have effect based on the platform we're running on.
    25  	if max > 16384 {
    26  		return errors.New("file descriptor limit (16384) reached")
    27  	}
    28  	return nil
    29  }
    30  
    31  // Current retrieves the number of file descriptors allowed to be opened by this
    32  // process.
    33  func Current() (int, error) {
    34  	// Please see Raise for the reason why we use hard coded 16K as the limit
    35  	return 16384, nil
    36  }
    37  
    38  // Maximum retrieves the maximum number of file descriptors this process is
    39  // allowed to request for itself.
    40  func Maximum() (int, error) {
    41  	return Current()
    42  }