1 module hunt.imf.protocol.protobuf.ProtobufTcpConnection;
2 
3 import hunt.net;
4 import hunt.imf.ConnectBase;
5 import hunt.imf.EvBuffer;
6 import hunt.String;
7 import hunt.imf.MessageBuffer;
8 import std.stdio;
9 import google.protobuf;
10 import std.array;
11 
12 class ProtobufTcpConnection : ConnectBase {
13 
14 private {
15     Connection _conn = null;
16 }
17 public:
18 
19     this(Connection connection)
20     {
21         _conn = connection;
22     }
23 
24     void onConnectionClosed()
25     {
26         _conn = null;
27     }
28 
29     override void sendMsg(MessageBuffer message)
30     {
31         if (_conn.isConnected())
32         {
33             _conn.write(message);
34         }
35     }
36 
37     override Connection getConnection()
38     {
39         return _conn;
40     }
41 
42     override string getProtocol()
43     {
44         return (cast(String)_conn.getAttribute(SESSION.PROTOCOL)).value;
45     }
46 
47     override void close()
48     {
49         if (_conn !is null && _conn.getState() !is ConnectionState.Closed)
50         {
51             _conn.close();
52         }
53     }
54 
55     override bool isConnected()
56     {
57          return _conn.isConnected();
58     }
59 }