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