HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SocketListener.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_SocketListener.h (UT Library, C++)
7  *
8  * COMMENTS:
9  * This class monitors a socket asynchronously and notifies
10  * subclasses (via onSocketEvent()) when socket events occur.
11  * This class is useful for reading from a socket asynchronously.
12  */
13 
14 #ifndef __UT_SocketListener__
15 #define __UT_SocketListener__
16 
17 #include "UT_API.h"
18 #include "UT_NonCopyable.h"
19 #include <SYS/SYS_Types.h>
20 
21 typedef enum
22 {
27 
28 class UT_NetSocket;
29 class UT_Thread;
30 
32 {
33 public:
34  /// Calls stop().
35  virtual ~UT_SocketListener();
36 
38 
39  /// Returns a bitmask of UT_SocketListenerEvents indicating which
40  /// events trigger a call to onSocketEvent().
41  int getEventTypes() const { return myEventTypes; }
42 
43  /// Returns the socket that is being monitored.
44  UT_NetSocket *getSocket() const { return mySocket; }
45 
46  /// Returns true if the socket is being monitored for events.
47  bool isListening() const { return myListening; }
48 
49  /// Sets the events that trigger a call to onSocketEvent().
50  /// event_types is a bitmask of UT_SocketListenerEvents.
51  void setEventTypes(int event_types);
52 
53  /// Start/stop listening on the socket provided to create().
54  /// Successive calls to either method have no effect.
55  void start();
56  void stop();
57 
58  /// Returns the amount of memory owned by this UT_SocketListener
59  virtual int64 getMemoryUsage(bool inclusive) const;
60 
61 protected:
62  /// Constructs an instance of UT_SocketListener that monitors
63  /// the specified socket for the specified event types.
64  /// onSocketEvent() is called whenever the specified events
65  /// occur.
67  UT_NetSocket *socket,
68  int event_types = UT_SOCKET_READ_READY);
69 
70  /// Subclasses must implement this method in order to receive
71  /// notification of socket events (such as data being available
72  /// for reading). event_types is a bitmask of UT_SocketListenerEvents
73  /// and indicates which events were fired.
74  virtual void onSocketEvent(int event_types) = 0;
75 
76 private:
77  static void *doListenThread(void *data);
78 
79  UT_NetSocket *mySocket;
80  UT_Thread *myThread;
81  int myEventTypes;
82  bool myListening;
83 };
84 
85 #endif
86 
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
bool isListening() const
Returns true if the socket is being monitored for events.
GLuint start
Definition: glcorearb.h:475
#define UT_API
Definition: UT_API.h:14
UT_NetSocket * getSocket() const
Returns the socket that is being monitored.
UT_SocketListenerEvent
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
Definition: format.h:895