github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/util/fdutil.go (about)

     1  /*
     2  Copyright 2018 The OpenEBS Author
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package util
    18  
    19  import "syscall"
    20  
    21  //FD_SET add a given file descriptor from  a  set
    22  //it perform bit shift operations and set fdset.
    23  //ie if value of i is 2 then it will set fdset's value as {[16]int64{4}}
    24  func FD_SET(p *syscall.FdSet, i int) {
    25  	p.Bits[i/64] |= 1 << (uint(i) % 64)
    26  }
    27  
    28  //FD_ISSET tests to see if a file descriptor is part of the set
    29  func FD_ISSET(p *syscall.FdSet, i int) bool {
    30  	return (p.Bits[i/64] & (1 << (uint(i) % 64))) != 0
    31  }
    32  
    33  //FD_ZERO clears a set
    34  //it perform bit shift operations and clear fdset.
    35  func FD_ZERO(p *syscall.FdSet) {
    36  	for i := range p.Bits {
    37  		p.Bits[i] = 0
    38  	}
    39  }