diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-10-14 22:27:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-10-14 22:27:51 +0000 |
commit | e72d6077b475bc6142afc3b5967db113922c76f5 (patch) | |
tree | 45bdb7b69ec4c1dbcfadc1fa568b1d6b341a6f0f /src/tests | |
parent | 44eac9521632f8da42f73085db945bdba45f8311 (diff) | |
download | libbu++-e72d6077b475bc6142afc3b5967db113922c76f5.tar.gz libbu++-e72d6077b475bc6142afc3b5967db113922c76f5.tar.bz2 libbu++-e72d6077b475bc6142afc3b5967db113922c76f5.tar.xz libbu++-e72d6077b475bc6142afc3b5967db113922c76f5.zip |
Fixed an interesting ideosyncacy in Bu::Hash in a safe way, I should try to do
this with the Bu::Archive next. Basically, there's one generic template
function that will convert anything that can safely cast to a uint32_t and that
supports direct comparisson, and doesn't have it's own override already to be
a Hash key, such as char, uint8_t, uint64_t, etc.
The Telnet protocol handler does everything I need it too for now, next up for
it is escape sequence handling, it would be nice to make this general too, by
using the termcap database or something, but there is an ANSI/ISO standard now,
I may just go ahead and use that. Also, it looks like it'd be pretty easy to
make the canonical mode editing functions be pluggable to facilitate different
types of editing, but that can be done down the road as well.
Diffstat (limited to '')
-rw-r--r-- | src/tests/telnetsrv.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/tests/telnetsrv.cpp b/src/tests/telnetsrv.cpp new file mode 100644 index 0000000..39e3217 --- /dev/null +++ b/src/tests/telnetsrv.cpp | |||
@@ -0,0 +1,85 @@ | |||
1 | #include "bu/server.h" | ||
2 | #include "bu/protocoltelnet.h" | ||
3 | #include "bu/client.h" | ||
4 | |||
5 | class MyTelnet : public Bu::ProtocolTelnet | ||
6 | { | ||
7 | public: | ||
8 | MyTelnet() | ||
9 | { | ||
10 | } | ||
11 | |||
12 | virtual ~MyTelnet() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | virtual void onNewConnection( Bu::Client *pClient ) | ||
17 | { | ||
18 | Bu::ProtocolTelnet::onNewConnection( pClient ); | ||
19 | |||
20 | //oNAWS.remoteSet(); | ||
21 | oEcho.localSet(); | ||
22 | oSuppressGA.remoteSet( true ); | ||
23 | oSuppressGA.localSet( true ); | ||
24 | setCanonical(); | ||
25 | } | ||
26 | |||
27 | virtual void onSubNAWS( uint16_t iWidth, uint16_t iHeight ) | ||
28 | { | ||
29 | printf("New dim = (%dx%d)\n", iWidth, iHeight ); | ||
30 | } | ||
31 | |||
32 | virtual void gotLine( Bu::FString &sLine ) | ||
33 | { | ||
34 | printf("Line: \"%s\"\n", sLine.getStr() ); | ||
35 | write("\n\r", 2 ); | ||
36 | } | ||
37 | |||
38 | private: | ||
39 | |||
40 | }; | ||
41 | |||
42 | class TelServer : public Bu::Server | ||
43 | { | ||
44 | public: | ||
45 | TelServer() | ||
46 | { | ||
47 | } | ||
48 | |||
49 | virtual ~TelServer() | ||
50 | { | ||
51 | } | ||
52 | |||
53 | virtual void onNewConnection( Bu::Client *pClient, int iPort ) | ||
54 | { | ||
55 | printf("New connection.\n"); | ||
56 | |||
57 | pClient->setProtocol( new MyTelnet() ); | ||
58 | } | ||
59 | |||
60 | virtual void onClosedConnection( Bu::Client *pClient ) | ||
61 | { | ||
62 | printf("Lost connection.\n"); | ||
63 | |||
64 | delete pClient->getProtocol(); | ||
65 | } | ||
66 | |||
67 | private: | ||
68 | |||
69 | }; | ||
70 | |||
71 | int main( int argc, char *argv[] ) | ||
72 | { | ||
73 | TelServer ts; | ||
74 | |||
75 | ts.addPort( 4000 ); | ||
76 | ts.setTimeout( 0, 5000 ); | ||
77 | |||
78 | printf("Initializing server on port: 4000\n"); | ||
79 | |||
80 | for(;;) | ||
81 | { | ||
82 | ts.scan(); | ||
83 | } | ||
84 | } | ||
85 | |||