aboutsummaryrefslogtreecommitdiff
path: root/src/old/tests/srvstress.cpp
blob: d9a9a1cd3a8f4bef865eda23a7e6309dfc1b38e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "connectionmanager.h"
#include "programlink.h"
#include "linkedlist.h"
#include "protocol.h"

class StressProtocol : public Protocol
{
public:
	bool onNewData()
	{
		switch( getConnection()->getInput()[0] )
		{
			case 'd':
				throw "Hello";
				break;

			case 'w':
				getConnection()->appendOutput("Hello");
				break;
		};

		return true;
	}

	bool onNewConnection()
	{
		return true;
	}
};

class StressMonitor : public ConnectionMonitor, public ProgramLink
{
public:
	bool init()
	{
		return true;
	}

	bool deInit()
	{
		return true;
	}

	bool timeSlice()
	{
		return true;
	}

	bool onNewConnection( Connection *pCon, int nPort )
	{
		StressProtocol *sp = new StressProtocol();
		pCon->setProtocol( sp );

		printf("    sys: New connection: socket(%d), port(%d)\n",
				pCon->getSocket(), nPort );

		return true;
	}

	bool onClosedConnection( Connection *pCon )
	{
		printf("    sys: Closed connection: socket(%d)\n",
				pCon->getSocket() );

		return true;
	}

	LinkMessage *processIRM( LinkMessage *pMsg )
	{
		return NULL;
	}
};

int main()
{
	printf("Starting server...\n");

	ConnectionManager srv;
	StressMonitor telnet;

	srv.setConnectionMonitor( &telnet );

	srv.startServer( 4001 );

	for(;;)
	{
		srv.scanConnections( 5000, false );
	}
	
	return 0;
}