diff options
Diffstat (limited to 'src/gatscon/proxythread.cpp')
-rw-r--r-- | src/gatscon/proxythread.cpp | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/src/gatscon/proxythread.cpp b/src/gatscon/proxythread.cpp deleted file mode 100644 index 574b56b..0000000 --- a/src/gatscon/proxythread.cpp +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | #include "proxythread.h" | ||
2 | |||
3 | #include <gats/types.h> | ||
4 | |||
5 | #include <bu/tcpsocket.h> | ||
6 | #include <bu/tcpserversocket.h> | ||
7 | #include <bu/sio.h> | ||
8 | #include <bu/membuf.h> | ||
9 | |||
10 | using namespace Bu; | ||
11 | |||
12 | ProxyThread::ProxyThread( QObject *pParent, int iPortIn, | ||
13 | const QByteArray &baHostOut, int iPortOut ) : | ||
14 | QThread( pParent ), | ||
15 | pHost( NULL ), | ||
16 | iPortIn( iPortIn ), | ||
17 | baHostOut( baHostOut ), | ||
18 | iPortOut( iPortOut ), | ||
19 | gsCli( ssCli ) | ||
20 | { | ||
21 | pHost = new ProxyHostThread( pParent, this ); | ||
22 | } | ||
23 | |||
24 | ProxyThread::~ProxyThread() | ||
25 | { | ||
26 | } | ||
27 | |||
28 | void ProxyThread::send( Gats::Object *pObj ) | ||
29 | { | ||
30 | MemBuf bg; | ||
31 | Gats::GatsStream gs( bg ); | ||
32 | gs.writeObject( pObj ); | ||
33 | ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); | ||
34 | } | ||
35 | |||
36 | void ProxyThread::run() | ||
37 | { | ||
38 | int iSockIn; | ||
39 | |||
40 | { | ||
41 | TcpServerSocket tsIn( iPortIn ); | ||
42 | do | ||
43 | { | ||
44 | iSockIn = tsIn.accept( 5 ); | ||
45 | } while( iSockIn < 0 ); | ||
46 | } | ||
47 | |||
48 | emit gotConnection(); | ||
49 | |||
50 | ssCli.setStream( new TcpSocket( iSockIn ) ); | ||
51 | ssCli.setBlocking( true ); | ||
52 | |||
53 | pHost->setStream( | ||
54 | new TcpSocket( baHostOut.constData(), iPortOut ) | ||
55 | ); | ||
56 | |||
57 | pHost->start(); | ||
58 | |||
59 | while( !ssCli.isEos() ) | ||
60 | { | ||
61 | Gats::Object *pObj = gsCli.readObject(); | ||
62 | if( pObj == NULL ) | ||
63 | continue; | ||
64 | |||
65 | pHost->send( pObj ); | ||
66 | emit recv( pObj ); | ||
67 | } | ||
68 | |||
69 | } | ||
70 | |||
71 | ProxyHostThread::ProxyHostThread( QObject *pParent, ProxyThread *pClient ) : | ||
72 | QThread( pParent ), | ||
73 | pClient( pClient ), | ||
74 | ssHst(), | ||
75 | gsHst( ssHst ) | ||
76 | { | ||
77 | } | ||
78 | |||
79 | ProxyHostThread::~ProxyHostThread() | ||
80 | { | ||
81 | } | ||
82 | |||
83 | void ProxyHostThread::send( Gats::Object *pObj ) | ||
84 | { | ||
85 | MemBuf bg; | ||
86 | Gats::GatsStream gs( bg ); | ||
87 | gs.writeObject( pObj ); | ||
88 | ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); | ||
89 | } | ||
90 | |||
91 | void ProxyHostThread::setStream( Bu::Stream *pStr ) | ||
92 | { | ||
93 | ssHst.setStream( pStr ); | ||
94 | } | ||
95 | |||
96 | void ProxyHostThread::run() | ||
97 | { | ||
98 | while( !ssHst.isEos() ) | ||
99 | { | ||
100 | Gats::Object *pObj = gsHst.readObject(); | ||
101 | if( pObj == NULL ) | ||
102 | continue; | ||
103 | |||
104 | pClient->send( pObj ); | ||
105 | emit recv( pObj ); | ||
106 | } | ||
107 | } | ||
108 | |||