HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_NetFDSet.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_NetFDSet.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_NetFDSet__
12 #define __UT_NetFDSet__
13 
14 #include "UT_API.h"
15 #include "UT_UniquePtr.h"
16 class UT_NetFDSetImpl;
17 
18 
19 // ============================================================================
20 /// Types of IO events that UT_NetFDSet can monitor a file descriptor for.
21 enum class UT_NetFDEvent
22 {
23  NETFD_READ,
26 };
27 
28 // ============================================================================
29 /// Abstracts the socket file descriptor set for select() or poll() calls.
31 {
32 public:
33  /// Constructor and desctructor.
34  UT_NetFDSet();
35  ~UT_NetFDSet();
36 
37  /// Adds a file descriptor to the set with the intent of monitoring
38  /// the given IO event.
39  void add(int fd, UT_NetFDEvent event);
40 
41  /// Test whether a file descriptor is in the set
42  bool contains(int fd) const;
43 
44  /// Removes all added file descriptors for all events (resets the set).
45  void removeAll();
46 
47  /// Checks or waits for the IO events on the file descriptors in the set.
48  /// Essentially it's a wrapper for select() or poll().
49  /// @param timeout_ms The timeout to wait for connection (in miliseconds).
50  /// If zero, the call does not wait for the events, but instead
51  /// checks for the current state of the FDs in the set.
52  /// If negative, the call blocks indefinitely, waiting for the
53  /// first event. This is equivalent to passing NULL to select() or
54  /// -1 to poll() as time value.
55  /// @param force_socket On Windows, indicates to use sockets rather than
56  /// resorting to pipes.
57  ///
58  /// @return The total number of file descriptors on which there was
59  /// activitiy (events of the registered type), or -1 if error
60  /// occured. If time limit expires, returns 0.
61  int checkEvents(int timeout_ms,
62  bool force_socket = false) const;
63 
64  /// Constants denoting special wait times for checkEvents()
65  static const int INDEFINITE_WAIT; // blocking indefinitely for events
66  static const int NO_WAIT; // returning immediately
67 
68  /// Returns true if the set contains no file descriptors.
69  bool isEmpty() const;
70 
71  /// Returns true if there was any IO activity of the given type
72  /// on the given file descriptor.
73  bool isActive(int fd, UT_NetFDEvent event) const;
74 
75 private:
76  /// Delegate that implements actual IO check (eg, select() or poll()).
78 };
79 
80 
81 #endif
82 
UT_NetFDEvent
Types of IO events that UT_NetFDSet can monitor a file descriptor for.
Definition: UT_NetFDSet.h:21
Abstracts the socket file descriptor set for select() or poll() calls.
Definition: UT_NetFDSet.h:30
#define UT_API
Definition: UT_API.h:12
struct _cl_event * event
Definition: glcorearb.h:2960
static const int NO_WAIT
Definition: UT_NetFDSet.h:66
static const int INDEFINITE_WAIT
Constants denoting special wait times for checkEvents()
Definition: UT_NetFDSet.h:65