HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_PacketConnectionHandler.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: NET_PacketConnectionHandler.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __NET_PACKETCONNECTIONHANDLER_H__
14 #define __NET_PACKETCONNECTIONHANDLER_H__
15 
16 #include "NET_API.h"
17 
18 #include "NET_ConnectionHandler.h"
19 #include "NET_PacketSocket.h"
20 
21 #include <UT/UT_BoostAsio.h>
22 #include <UT/UT_SharedPtr.h>
23 #include <UT/UT_WorkBuffer.h>
24 
25 #include <vector>
26 
28  : public NET_ConnectionHandler,
29  public UTenable_shared_from_this<NET_IPacketConnectionHandler>
30 {
31 public:
34  ASIO_TCPSocket socket);
35  ~NET_IPacketConnectionHandler() override;
36 
37  void start() override;
38 protected:
39  /// Called each time the socket has read a full packet that is ready to
40  /// be handled.
41  virtual void onPacket(UT_WorkBuffer&& data) = 0;
42  /// Called whenever the received ec was an error.
43  virtual void fail(const hboost::system::error_code& ec, const char* what);
44 
45  void write(const UT_StringHolder& message);
46 
47  virtual void requestStop(bool force);
48 
49  NET_PacketSocket& socket() { return mySocket; }
50 
51 private:
52  void stop(bool force) override;
53  void startRead_();
54  void flush_();
55 
56  std::vector<char> myInternalBuffer;
57  hboost::asio::dynamic_vector_buffer<char, std::allocator<char>> myBuffer;
58  NET_PacketSocket mySocket;
59  bool myShutdownRequested = false;
60  bool myIsWriting = false;
61  UT_StringArray myWriteQueue;
62 };
63 
64 #endif // __NET_PACKETCONNECTIONHANDLER_H__
65 
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
hboost::asio::ip::tcp::socket ASIO_TCPSocket
Definition: UT_BoostAsio.h:44
#define NET_API
Definition: NET_API.h:9
std::enable_shared_from_this< T > UTenable_shared_from_this
Definition: UT_SharedPtr.h:39
virtual void start()=0
SIM_API const UT_StringHolder force
virtual void stop(bool force)=0
void write(T &out, bool v)
Definition: ImfXdr.h:287
Definition: format.h:895