summaryrefslogtreecommitdiff
path: root/src/cprlisten.cc
diff options
context:
space:
mode:
authordeva <deva>2006-01-10 10:03:41 +0000
committerdeva <deva>2006-01-10 10:03:41 +0000
commit495330ce3cfb6b168d2fb9b56aa125bbc7ff6e7d (patch)
tree45cb7dc618e05a21657790e17b617a664652dae1 /src/cprlisten.cc
parentcaa558e59c248521d1d4ad483fe669828277664e (diff)
*** empty log message ***
Diffstat (limited to 'src/cprlisten.cc')
-rw-r--r--src/cprlisten.cc50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/cprlisten.cc b/src/cprlisten.cc
index 9a816d2..9ecac86 100644
--- a/src/cprlisten.cc
+++ b/src/cprlisten.cc
@@ -26,36 +26,68 @@
*/
#include "cprlisten.h"
-#include "socket.h"
+#include "aa_socket.h"
#include <iostream>
#include <string>
using namespace std;
+#define MAGIC_STOP_STRING "SHUTTHEFUCKUP"
+
CPRListen::CPRListen(unsigned short port)
{
this->port = port;
cpr = "N/A";
+ cprchanged = false;
+ running = true;
}
CPRListen::~CPRListen()
{
}
+void CPRListen::stop()
+{
+ running = false;
+ try {
+ AASocket socket;
+ socket.connect("localhost", port);
+ socket.send_string(MAGIC_STOP_STRING);
+ } catch(Network_error &e) {
+ cerr << "In stop(): " << e.error << endl;
+ }
+}
+
void CPRListen::thread_main()
{
- while(1) {
+ while(running) {
try {
- Socket socket;
+ string newcpr;
+ AASocket socket;
socket.listen(port);
- mutex.lock();
- cpr = socket.receive_string();
- mutex.unlock();
- cerr << "Got CPR: " << cpr << endl;
+ newcpr = socket.receive_string();
+
+ if(newcpr == MAGIC_STOP_STRING) {
+ running = false;
+ } else {
+ mutex.lock();
+ cprchanged = true;
+ cpr = newcpr;
+ mutex.unlock();
+ // cerr << "Got CPR: " << cpr << endl;
+ }
+
} catch(Network_error &e) {
- cerr << e.error << endl;
+ cerr << "In thread_main(): " << e.error << endl;
+ running = false;
}
}
+ // cout << "fisk!" << endl;
+}
+
+bool CPRListen::cprChanged()
+{
+ return cprchanged;
}
string CPRListen::getCpr()
@@ -66,5 +98,7 @@ string CPRListen::getCpr()
cpr_copy = cpr;
mutex.unlock();
+ cprchanged = false;
+
return cpr_copy;
}