Subversion Repositories HomeAutomation

Rev

Rev 969 | Rev 981 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 969 Rev 974
Line 37... Line 37...
37
#include <string.h>
37
#include <string.h>
38
#include <errno.h>
38
#include <errno.h>
39
#include <fcntl.h>
39
#include <fcntl.h>
40
#include <sys/ioctl.h>
40
#include <sys/ioctl.h>
41
#include <signal.h>
41
#include <signal.h>
-
 
42
#include <netinet/tcp.h>
-
 
43
 
42
 
44
 
43
#include "../Threads/thread.h"
45
#include "../Threads/thread.h"
44
#include "../Threads/semaphore.h"
46
#include "../Threads/semaphore.h"
45
#include "../Threads/threadsafequeue.h"
47
#include "../Threads/threadsafequeue.h"
46
#include "../Tools/tools.h"
48
#include "../Tools/tools.h"
47
#include "../SyslogStream/syslogstream.h"
49
#include "../SyslogStream/syslogstream.h"
48
 
50
 
49
#include "socketexception.h"
51
#include "socketexception.h"
50
 
52
 
51
#define ASYNCSOCKET_EVENT_NONE 0
53
#define ASYNCSOCKET_EVENT_NONE 0
52
#define ASYNCSOCKET_EVENT_DATA 1
54
#define ASYNCSOCKET_EVENT_DATA 1
53
#define ASYNCSOCKET_EVENT_CLOSED 2
55
#define ASYNCSOCKET_EVENT_CLOSED 2
54
#define ASYNCSOCKET_EVENT_DIED 2
56
#define ASYNCSOCKET_EVENT_DIED 3
-
 
57
#define ASYNCSOCKET_EVENT_INACTIVITY 4
55
 
58
 
56
const int MAXBUFFER = 1024;
59
const int MAXBUFFER = 1024;
57
 
60
 
58
class AsyncSocket : public Thread<AsyncSocket>
61
class AsyncSocket : public Thread<AsyncSocket>
59
{
62
{
60
public:
63
public:
Line 68... Line 71...
68
 
71
 
69
    void startEvent();
72
    void startEvent();
70
    int getEvent();
73
    int getEvent();
71
    void waitForEvent();
74
    void waitForEvent();
72
    void stopEvent();
75
    void stopEvent();
73
 
76
 
74
    bool availableData();
77
    bool availableData();
75
    string getData();
78
    string getData();
76
    bool sendData(string data);
79
    bool sendData(string data);
-
 
80
    void forceReconnect();
77
 
81
 
78
    static void signalHandler(int signum);
82
    static void signalHandler(int signum);
79
   
83
   
80
protected:
84
protected:
81
    void reconnectLoop();
85
    void reconnectLoop();
82
    void connect();
86
    void connect();
83
    void close();
87
    void close();
84
    void setEvent(int event);
88
    void setEvent(int event);
85
 
89
 
86
    static Semaphore mySemaphore;
90
    static Semaphore mySemaphore;
87
 
91
 
88
private:
92
private:
89
    Semaphore myEventSemaphore;
93
    Semaphore myEventSemaphore;
90
    int myEvent;
94
    int myEvent;
-
 
95
 
-
 
96
    bool myForceReconnect;
91
   
97
   
92
    ThreadSafeQueue<string> myInQueue;
98
    ThreadSafeQueue<string> myInQueue;
93
    ThreadSafeQueue<string> myOutQueue;
99
    ThreadSafeQueue<string> myOutQueue;
94
 
100
 
95
    int mySocket;
101
    int mySocket;