]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/fdsel.cpp
3ea8f59e70bd59ca8b7e754423ecc2d139ca5221
   2  * Copyright (c) 2000-2001,2004,2011,2014 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  26 // fdsel - select-style file descriptor set management 
  32 namespace UnixPlusPlus 
{ 
  36 // Throw the bitvectors away on destruction 
  46 // Given the old and desired new sizes (in fd_mask words), grow 
  47 // the bitvectors. New storage is zero filled. Note that we preserve 
  48 // the mUseBits vector, so this is safe to do during a post-select scan. 
  49 // This function cannot shrink the bitmaps. 
  51 void FDSet::grow(int oldWords
, int newWords
) 
  53     assert(oldWords 
< newWords
); 
  54     grow(mBits
, oldWords
, newWords
); 
  55     grow(mUseBits
, oldWords
, newWords
); 
  58 void FDSet::grow(fd_mask 
* &bits
, int oldWords
, int newWords
) 
  60     fd_mask 
*newBits 
= new fd_mask
[newWords
]; 
  61     memcpy(newBits
, bits
, oldWords 
* sizeof(fd_mask
)); 
  62     memset(newBits 
+ oldWords
, 0, (newWords 
- oldWords
) * sizeof(fd_mask
)); 
  69 // Set or clear a single bit in the map. 
  70 // No check for overflow is perfomed. 
  72 void FDSet::set(int fd
, bool on
) 
  75         FD_SET(fd
, (fd_set 
*)mBits
); 
  77         FD_CLR(fd
, (fd_set 
*)mBits
); 
  78         FD_CLR(fd
, (fd_set 
*)mUseBits
); 
  84 // Copy only the first words fd_mask words from mBits to mUseBits 
  85 // and return that for select(2) use. 
  87 fd_set 
*FDSet::make(int words
) 
  89     //@@@ if empty -> return NULL (but check caller for [] use) 
  90     memcpy(mUseBits
, mBits
, words 
* sizeof(fd_mask
)); 
  91     return (fd_set 
*)mUseBits
; 
  95 }       // end namespace IPPlusPlus 
  96 }       // end namespace Security