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 <SYS/SYS_Types.h>
19 
20 typedef enum
21 {
26 
27 class UT_NetSocket;
28 class UT_Thread;
29 
31 public:
32  /// Calls stop().
33  virtual ~UT_SocketListener();
34 
35  /// Returns a bitmask of UT_SocketListenerEvents indicating which
36  /// events trigger a call to onSocketEvent().
37  int getEventTypes() const { return myEventTypes; }
38 
39  /// Returns the socket that is being monitored.
40  UT_NetSocket *getSocket() const { return mySocket; }
41 
42  /// Returns true if the socket is being monitored for events.
43  bool isListening() const { return myListening; }
44 
45  /// Sets the events that trigger a call to onSocketEvent().
46  /// event_types is a bitmask of UT_SocketListenerEvents.
47  void setEventTypes(int event_types);
48 
49  /// Start/stop listening on the socket provided to create().
50  /// Successive calls to either method have no effect.
51  void start();
52  void stop();
53 
54  /// Returns the amount of memory owned by this UT_SocketListener
55  virtual int64 getMemoryUsage(bool inclusive) const;
56 
57 protected:
58  /// Constructs an instance of UT_SocketListener that monitors
59  /// the specified socket for the specified event types.
60  /// onSocketEvent() is called whenever the specified events
61  /// occur.
63  UT_NetSocket *socket,
64  int event_types = UT_SOCKET_READ_READY);
65 
66  /// Subclasses must implement this method in order to receive
67  /// notification of socket events (such as data being available
68  /// for reading). event_types is a bitmask of UT_SocketListenerEvents
69  /// and indicates which events were fired.
70  virtual void onSocketEvent(int event_types) = 0;
71 
72 private:
73  static void *doListenThread(void *data);
74 
75  UT_NetSocket *mySocket;
76  UT_Thread *myThread;
77  int myEventTypes;
78  bool myListening;
79 };
80 
81 #endif
82 
bool isListening() const
Returns true if the socket is being monitored for events.
GLuint start
Definition: glcorearb.h:474
#define UT_API
Definition: UT_API.h:13
UT_NetSocket * getSocket() const
Returns the socket that is being monitored.
long long int64
Definition: SYS_Types.h:107
UT_SocketListenerEvent
GLboolean * data
Definition: glcorearb.h:130
int getEventTypes() const