diff options
author | Mike Buland <eichlan@xagasoft.com> | 2023-07-28 21:18:56 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2023-07-28 21:18:56 -0700 |
commit | 915005e218b5d00939b548de65ce6354f7acb487 (patch) | |
tree | 2f624a37f86f97cfd61c1995df7e4368b462bcac /src/stable/client.h | |
parent | e43a2cac32cb773994b11a3d964ec4acc372d273 (diff) | |
download | libbu++-915005e218b5d00939b548de65ce6354f7acb487.tar.gz libbu++-915005e218b5d00939b548de65ce6354f7acb487.tar.bz2 libbu++-915005e218b5d00939b548de65ce6354f7acb487.tar.xz libbu++-915005e218b5d00939b548de65ce6354f7acb487.zip |
Completely redesigned Server and Client.
Like, seriously, they're almost completely different.
Diffstat (limited to 'src/stable/client.h')
-rw-r--r-- | src/stable/client.h | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/src/stable/client.h b/src/stable/client.h index abde682..4cd8e3f 100644 --- a/src/stable/client.h +++ b/src/stable/client.h | |||
@@ -12,7 +12,7 @@ | |||
12 | 12 | ||
13 | #include "bu/config.h" | 13 | #include "bu/config.h" |
14 | #include "bu/string.h" | 14 | #include "bu/string.h" |
15 | #include "bu/queuebuf.h" | 15 | #include "bu/clientbuf.h" |
16 | #include "bu/mutex.h" | 16 | #include "bu/mutex.h" |
17 | #include "bu/readwritemutex.h" | 17 | #include "bu/readwritemutex.h" |
18 | 18 | ||
@@ -28,7 +28,6 @@ namespace Bu | |||
28 | { | 28 | { |
29 | class Protocol; | 29 | class Protocol; |
30 | class Stream; | 30 | class Stream; |
31 | class TcpSocket; | ||
32 | class ClientLinkFactory; | 31 | class ClientLinkFactory; |
33 | 32 | ||
34 | /** | 33 | /** |
@@ -36,15 +35,13 @@ namespace Bu | |||
36 | */ | 35 | */ |
37 | class Client : public Bu::Stream | 36 | class Client : public Bu::Stream |
38 | { | 37 | { |
38 | friend class Server; | ||
39 | public: | 39 | public: |
40 | Client( Bu::TcpSocket *pSocket, Bu::ClientLinkFactory *pfLink); | 40 | Client( Bu::ClientLinkFactory *pfLink ); |
41 | virtual ~Client(); | 41 | virtual ~Client(); |
42 | 42 | ||
43 | void processInput(); | 43 | void processInput(); |
44 | void processOutput(); | ||
45 | 44 | ||
46 | //Bu::String &getInput(); | ||
47 | //Bu::String &getOutput(); | ||
48 | Bu::size write( const Bu::String &sData ); | 45 | Bu::size write( const Bu::String &sData ); |
49 | Bu::size write( const void *pData, Bu::size nBytes ); | 46 | Bu::size write( const void *pData, Bu::size nBytes ); |
50 | Bu::size write( int8_t nData ); | 47 | Bu::size write( int8_t nData ); |
@@ -57,7 +54,7 @@ namespace Bu | |||
57 | Bu::size write( uint64_t nData ); | 54 | Bu::size write( uint64_t nData ); |
58 | Bu::size read( void *pData, Bu::size nBytes ); | 55 | Bu::size read( void *pData, Bu::size nBytes ); |
59 | Bu::size peek( void *pData, int nBytes, int nOffset=0 ); | 56 | Bu::size peek( void *pData, int nBytes, int nOffset=0 ); |
60 | // void seek( int nBytes ); | 57 | void seek( int nBytes ); |
61 | Bu::size getInputSize(); | 58 | Bu::size getInputSize(); |
62 | Bu::size getOutputSize(); | 59 | Bu::size getOutputSize(); |
63 | 60 | ||
@@ -69,8 +66,6 @@ namespace Bu | |||
69 | void close(); | 66 | void close(); |
70 | void tick(); | 67 | void tick(); |
71 | 68 | ||
72 | const Bu::TcpSocket *getSocket() const; | ||
73 | |||
74 | void disconnect(); | 69 | void disconnect(); |
75 | bool wantsDisconnect(); | 70 | bool wantsDisconnect(); |
76 | 71 | ||
@@ -78,31 +73,22 @@ namespace Bu | |||
78 | 73 | ||
79 | void onMessage( const Bu::String &sMsg ); | 74 | void onMessage( const Bu::String &sMsg ); |
80 | 75 | ||
81 | bool hasOutput() { return qbWrite.getSize() > 0; } | 76 | bool hasOutput() { return cbBuffer.server().getSize() > 0; } |
82 | bool hasInput() { return qbRead.getSize() > 0; } | 77 | bool hasInput() { return cbBuffer.client().getSize() > 0; } |
83 | 78 | ||
84 | template<typename filter> | 79 | template<typename filter> |
85 | void pushFilter() | 80 | void pushFilter() |
86 | { | 81 | { |
87 | filter *pFlt = new filter( *pTopStream ); | ||
88 | pTopStream = pFlt; | ||
89 | lFilts.prepend( pFlt ); | ||
90 | } | 82 | } |
91 | 83 | ||
92 | template<typename filter, typename p1t> | 84 | template<typename filter, typename p1t> |
93 | void pushFilter( p1t p1 ) | 85 | void pushFilter( p1t p1 ) |
94 | { | 86 | { |
95 | filter *pFlt = new filter( *pTopStream, p1 ); | ||
96 | pTopStream = pFlt; | ||
97 | lFilts.prepend( pFlt ); | ||
98 | } | 87 | } |
99 | 88 | ||
100 | template<typename filter, typename p1t, typename p2t> | 89 | template<typename filter, typename p1t, typename p2t> |
101 | void pushFilter( p1t p1, p2t p2 ) | 90 | void pushFilter( p1t p1, p2t p2 ) |
102 | { | 91 | { |
103 | filter *pFlt = new filter( *pTopStream, p1, p2 ); | ||
104 | pTopStream = pFlt; | ||
105 | lFilts.prepend( pFlt ); | ||
106 | } | 92 | } |
107 | 93 | ||
108 | /* | 94 | /* |
@@ -128,18 +114,12 @@ namespace Bu | |||
128 | virtual Bu::String getLocation() const; | 114 | virtual Bu::String getLocation() const; |
129 | 115 | ||
130 | private: | 116 | private: |
131 | typedef Bu::List<Bu::Stream *> FilterList; | ||
132 | FilterList lFilts; | ||
133 | Bu::Stream *pTopStream; | ||
134 | Bu::TcpSocket *pSocket; | ||
135 | Bu::Protocol *pProto; | 117 | Bu::Protocol *pProto; |
136 | Bu::QueueBuf qbRead; | 118 | Bu::ClientBuf cbBuffer; |
137 | Bu::QueueBuf qbWrite; | ||
138 | bool bWantsDisconnect; | 119 | bool bWantsDisconnect; |
139 | class Bu::ClientLinkFactory *pfLink; | 120 | class Bu::ClientLinkFactory *pfLink; |
140 | Bu::Mutex mRead; | 121 | mutable Bu::Mutex mProto; |
141 | Bu::Mutex mWrite; | 122 | mutable Bu::Mutex mDisconnect; |
142 | mutable Bu::ReadWriteMutex mGlobal; | ||
143 | }; | 123 | }; |
144 | } | 124 | } |
145 | 125 | ||