]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/fdsel.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // fdsel - select-style file descriptor set management
25 #include <Security/utilities.h>
26 #include <sys/types.h>
27 #include <Security/debugging.h>
31 namespace UnixPlusPlus
{
35 // An FDSet object maintains a single select(2) compatible bitmap.
36 // Size is implicitly kept by the caller (who needs to call grow() as
37 // needed, starting at zero). As long as this is done correctly, we are
38 // not bound by the FD_SETSIZE limit.
39 // An FDSet can self-copy for select(2) use; after that, the [] operator
40 // investigates the copy.
42 // Why are we using the FD_* macros even though we know these
43 // are fd_mask arrays? Some implementations use optimized assembly
44 // for these operations, and we want to pick those up.
46 // This whole mess is completely UNIX specific. If your system has
47 // the poll(2) system call, ditch this and use it.
51 FDSet() : mBits(NULL
), mUseBits(NULL
) { }
54 void grow(int oldWords
, int newWords
);
55 void set(int fd
, bool on
);
57 fd_set
*make(int words
);
58 bool operator [] (int fd
) const { return FD_ISSET(fd
, (fd_set
*)mUseBits
); }
60 inline static int words(int fd
) { return (fd
- 1) / NFDBITS
+ 1; }
63 fd_mask
*mBits
; // base bits
64 fd_mask
*mUseBits
; // mutable copy for select(2)
66 void grow(fd_mask
* &bits
, int oldWords
, int newWords
);
70 } // end namespace UnixPlusPlus
71 } // end namespace Security