aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/clistress/main.cpp39
-rw-r--r--src/test/srvstress/main.cpp86
2 files changed, 125 insertions, 0 deletions
diff --git a/src/test/clistress/main.cpp b/src/test/clistress/main.cpp
new file mode 100644
index 0000000..3f5038b
--- /dev/null
+++ b/src/test/clistress/main.cpp
@@ -0,0 +1,39 @@
1#include "connection.h"
2
3void _waitForLength( Connection &con, int len)
4{
5 int rlen = con.getInputAmnt();
6
7 if (rlen >= len)
8 return;
9
10 int time_left = 5;
11 int mic_left = 0;
12
13 while (rlen < len)
14 {
15 if (time_left == 0 && mic_left == 0)
16 {
17 throw "Socket Timeout";
18 }
19 con.readInput(time_left, mic_left, &time_left, &mic_left);
20 rlen = con.getInputAmnt();
21 }
22}
23
24int main()
25{
26 Connection c;
27
28 c.open("localhost", 4001 );
29
30 c.appendOutput("d");
31 c.writeOutput();
32
33 _waitForLength( c, 40 );
34
35 c.close();
36
37 return 0;
38}
39
diff --git a/src/test/srvstress/main.cpp b/src/test/srvstress/main.cpp
new file mode 100644
index 0000000..c7795e4
--- /dev/null
+++ b/src/test/srvstress/main.cpp
@@ -0,0 +1,86 @@
1#include "connectionmanager.h"
2#include "programlink.h"
3#include "linkedlist.h"
4#include "protocol.h"
5
6class StressProtocol : public Protocol
7{
8public:
9 bool onNewData()
10 {
11 switch( getConnection()->getInput()[0] )
12 {
13 case 'd':
14 throw "Hello";
15 break;
16 };
17
18 return true;
19 }
20
21 bool onNewConnection()
22 {
23 return true;
24 }
25};
26
27class StressMonitor : public ConnectionMonitor, public ProgramLink
28{
29public:
30 bool init()
31 {
32 return true;
33 }
34
35 bool deInit()
36 {
37 return true;
38 }
39
40 bool timeSlice()
41 {
42 }
43
44 bool onNewConnection( Connection *pCon, int nPort )
45 {
46 StressProtocol *sp = new StressProtocol();
47 pCon->setProtocol( sp );
48
49 printf(" sys: New connection: socket(%d), port(%d)\n",
50 pCon->getSocket(), nPort );
51
52 return true;
53 }
54
55 bool onClosedConnection( Connection *pCon )
56 {
57 printf(" sys: Closed connection: socket(%d)\n",
58 pCon->getSocket() );
59
60 return true;
61 }
62
63 LinkMessage *processIRM( LinkMessage *pMsg )
64 {
65 return NULL;
66 }
67};
68
69int main()
70{
71 printf("Starting server...\n");
72
73 ConnectionManager srv;
74 StressMonitor telnet;
75
76 srv.setConnectionMonitor( &telnet );
77
78 srv.startServer( 4001 );
79
80 for(;;)
81 {
82 srv.scanConnections( 5000, false );
83 }
84
85 return 0;
86}