|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #include <windows.h>
- #include <iostream>
- #include <string>
- #include "snfmultidll.h"
- #include "../CodeDweller/timing.hpp"
- #include "../CodeDweller/threading.hpp"
-
-
- class Pounder : private Thread {
- private:
- string MessageToTest;
- bool TimeToStop;
- volatile int ScansAccomplished;
- volatile int HighestHandleSeen;
- void myTask();
-
- public:
- Pounder(string Message);
- ~Pounder();
- int NumberOfScans();
- int HighestHandle();
- void stop();
- };
-
- Pounder::Pounder(string Message) :
- MessageToTest(Message),
- TimeToStop(false),
- ScansAccomplished(0),
- HighestHandleSeen(0) {
- run();
- }
-
- Pounder::~Pounder() {
- stop();
- }
-
- int Pounder::NumberOfScans() {
- return ScansAccomplished;
- }
-
- int Pounder::HighestHandle() {
- return HighestHandleSeen;
- }
-
- void Pounder::stop() {
- if(!TimeToStop) {
- TimeToStop = true;
- join();
- }
- }
-
- void Pounder::myTask() {
- while(!TimeToStop) {
-
- int ScanHandle =
- scanBuffer(
- (unsigned char*)MessageToTest.c_str(),
- MessageToTest.length(),
- (char *) "nobigdeal",
- 0
- );
-
- if(1 > ScanHandle) {
- TimeToStop = true;
- break;
- }
-
- if(ScanHandle > HighestHandleSeen) {
- HighestHandleSeen = ScanHandle;
- }
-
- char* HeadersString = 0;
- int HeadersStringLength = 0;
- int ScanResult =
- getScanXHeaders(ScanHandle, &HeadersString, &HeadersStringLength);
-
- string XHeaders = HeadersString;
- closeScan(ScanHandle);
-
- if(0 > ScanResult) { TimeToStop = true; break; }
- if(0 == HeadersStringLength) { TimeToStop = true; break; }
- if(HeadersStringLength != XHeaders.length()) {
- TimeToStop = true; break;
- }
-
- ++ScansAccomplished;
-
- }
- }
-
- string BigGiantUglyMessage =
- "Received: from [213.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "Received: from [13.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "Received: from [23.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "Received: from [33.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "Received: from [43.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "Received: from [53.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "Received: from [63.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "From: \"somebody\" <somebody@someplace.com>\r\n"
- "Subject: Nothing to see here\r\n"
- "\r\n"
- "So, this is a message eh?\r\n"
- "Don't you have something special to say?\r\n"
- "I suppose you could say something else too.\r\n"
- "This is just more filler text. No. Really.\r\n"
- "Nothing to see here. Move along. Move along.\r\n"
- "If ever a whiz of a whiz there was the wizard of oz is one because,\r\n"
- "because, because, because, because, because..... \r\n"
- "Because of the wonderful things he does.\r\n"
- "\r\n"
- "I repeat myself when under stress. I repeat myself when under stress.\r\n"
- "I repeat myself when under stress. I repeat myself when under stress.\r\n"
- "I repeat myself when under stress. I repeat myself when under stress.\r\n"
- "I repeat myself when under stress. I repeat...\r\n"
- "\r\n"
- "I think that's enough craziness for now.\r\n"
- ".\r\n";
-
- int main()
- {
- std::cout << "Hello world!" << std::endl;
-
- int LastResult;
-
- std::cout << "Throttling not set" << endl;
-
-
- std::cout << "startupSNF(): ";
- LastResult = startupSNF((char *) "prescale.xml");
- std::cout << LastResult << std::endl;
-
- std::cout << "Scanning ugly text: ";
- string UglyText1 =
- "Received: from [213.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "From: \"somebody\" <somebody@someplace.com>\r\n"
- "Subject: Nothing to see here\r\n"
- "\r\n"
- "So, this is a message eh?\r\n"
- ".\r\n";
-
- string UglyText2 =
- "Received: from [11.93.213.84] (HELO uw-4b58d8528225.arnhem.chello.nl)\r\n"
- " by inbound.appriver.com (CommuniGate Pro SMTP 5.0.6)\r\n"
- "From: \"somebody\" <somebody@someplace.com>\r\n"
- "Subject: Nothing to see here\r\n"
- "\r\n"
- "So, this is a message eh?\r\n"
- ".\r\n";
-
- int HandleOne = scanBuffer((unsigned char*)UglyText1.c_str(), UglyText1.length(), (char *) "", 0);
- char* Result1; int Result1Length;
- LastResult = getScanXHeaders(HandleOne, &Result1, &Result1Length);
- std::cout << HandleOne << ", " << LastResult << endl;
- std::cout << Result1;
- LastResult = closeScan(HandleOne);
- std::cout << "Closed handle one: " << LastResult << endl;
-
-
-
-
-
-
- HandleOne = scanBuffer((unsigned char*)UglyText1.c_str(), UglyText1.length(), (char *) "", 0);
- LastResult = getScanXHeaders(HandleOne, &Result1, &Result1Length);
- std::cout << HandleOne << ", " << LastResult << endl;
- std::cout << Result1;
-
- int HandleTwo = scanBuffer((unsigned char*)UglyText1.c_str(), UglyText1.length(), (char *) "", 0);
- char* Result2; int Result2Length;
- LastResult = getScanXHeaders(HandleTwo, &Result2, &Result2Length);
- std::cout << HandleTwo << ", " << LastResult << endl;
- std::cout << Result2;
-
- std::cout << "Closing Scanners: ";
- LastResult = closeScan(HandleOne);
- std::cout << LastResult << ", ";
- LastResult = closeScan(HandleTwo);
- std::cout << LastResult << endl;
-
- std::cout << "Scanners Closed" << endl;
-
-
-
- Sleeper WaitATic(1000);
- std::cout << "Starting Pounder 1" << endl;
- Pounder Pounder1(BigGiantUglyMessage);
- for(int a = 0; a < 10; a++) {
- WaitATic();
- std:cout
- << "Pounder 1: " << Pounder1.NumberOfScans()
- << ", " << Pounder1.HighestHandle() << endl;
- }
-
- std::cout << "Starting Pounder 2" << endl;
- Pounder Pounder2(BigGiantUglyMessage);
- for(int a = 0; a < 10; a++) {
- WaitATic();
- std::cout << "Pounder 1: " << Pounder1.NumberOfScans()
- << ", " << Pounder1.HighestHandle() << endl;
-
- std::cout << "Pounder 2: " << Pounder2.NumberOfScans()
- << ", " << Pounder2.HighestHandle() << endl;
-
- }
-
- std::cout << "Starting Pounder 3" << endl;
- Pounder Pounder3(BigGiantUglyMessage);
- for(int a = 0; a < 10; a++) {
- WaitATic();
- std::cout << "Pounder 1: " << Pounder1.NumberOfScans()
- << ", " << Pounder1.HighestHandle() << endl;
-
- std::cout << "Pounder 2: " << Pounder2.NumberOfScans()
- << ", " << Pounder2.HighestHandle() << endl;
-
- std::cout << "Pounder 3: " << Pounder3.NumberOfScans()
- << ", " << Pounder3.HighestHandle() << endl;
-
- }
-
- std::cout << "Starting Pounder 4" << endl;
- Pounder Pounder4(BigGiantUglyMessage);
- for(int a = 0; a < 10; a++) {
- WaitATic();
- std::cout << "Pounder 1: " << Pounder1.NumberOfScans()
- << ", " << Pounder1.HighestHandle() << endl;
-
- std::cout << "Pounder 2: " << Pounder2.NumberOfScans()
- << ", " << Pounder2.HighestHandle() << endl;
-
- std::cout << "Pounder 3: " << Pounder3.NumberOfScans()
- << ", " << Pounder3.HighestHandle() << endl;
-
- std::cout << "Pounder 4: " << Pounder4.NumberOfScans()
- << ", " << Pounder4.HighestHandle() << endl;
-
- }
-
- std::cout << "Starting Pounder 5" << endl;
- Pounder Pounder5(BigGiantUglyMessage);
- for(int a = 0; a < 10; a++) {
- WaitATic();
- std::cout << "Pounder 1: " << Pounder1.NumberOfScans()
- << ", " << Pounder1.HighestHandle() << endl;
-
- std::cout << "Pounder 2: " << Pounder2.NumberOfScans()
- << ", " << Pounder2.HighestHandle() << endl;
-
- std::cout << "Pounder 3: " << Pounder3.NumberOfScans()
- << ", " << Pounder3.HighestHandle() << endl;
-
- std::cout << "Pounder 4: " << Pounder4.NumberOfScans()
- << ", " << Pounder4.HighestHandle() << endl;
-
- std::cout << "Pounder 5: " << Pounder5.NumberOfScans()
- << ", " << Pounder5.HighestHandle() << endl;
-
- }
-
- std::cout << "Starting Pounder 6" << endl;
- Pounder Pounder6(BigGiantUglyMessage);
- for(int a = 0; a < 30; a++) {
- WaitATic();
- std::cout << "Pounder 1: " << Pounder1.NumberOfScans()
- << ", " << Pounder1.HighestHandle() << endl;
-
- std::cout << "Pounder 2: " << Pounder2.NumberOfScans()
- << ", " << Pounder2.HighestHandle() << endl;
-
- std::cout << "Pounder 3: " << Pounder3.NumberOfScans()
- << ", " << Pounder3.HighestHandle() << endl;
-
- std::cout << "Pounder 4: " << Pounder4.NumberOfScans()
- << ", " << Pounder4.HighestHandle() << endl;
-
- std::cout << "Pounder 5: " << Pounder5.NumberOfScans()
- << ", " << Pounder5.HighestHandle() << endl;
-
- std::cout << "Pounder 6: " << Pounder6.NumberOfScans()
- << ", " << Pounder6.HighestHandle() << endl;
-
- }
-
- std::cout << "Stopping All Pounders" << endl;
-
- Pounder1.stop(); std::cout << "1 stopped." << endl;
- Pounder2.stop(); std::cout << "2 stopped." << endl;
- Pounder3.stop(); std::cout << "3 stopped." << endl;
- Pounder4.stop(); std::cout << "4 stopped." << endl;
- Pounder5.stop(); std::cout << "5 stopped." << endl;
- Pounder6.stop(); std::cout << "6 stopped." << endl;
-
- std::cout << "shutdownSNF(): ";
- LastResult = shutdownSNF();
- std::cout << LastResult << std::endl;
-
- std::cout << "That's All Folks";
-
- return 0;
- }
|