Subversion Repositories HomeAutomation

Rev

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

Rev 981 Rev 983
Line 51... Line 51...
51
 
51
 
52
#include "socketexception.h"
52
#include "socketexception.h"
53
 
53
 
54
#define ASYNCSOCKET_EVENT_NONE 0
54
#define ASYNCSOCKET_EVENT_NONE 0
55
#define ASYNCSOCKET_EVENT_DATA 1
55
#define ASYNCSOCKET_EVENT_DATA 1
-
 
56
#define ASYNCSOCKET_EVENT_CONNECTED 2
-
 
57
#define ASYNCSOCKET_EVENT_CONNECT_FAILED 3
-
 
58
#define ASYNCSOCKET_EVENT_WAITING_TO_RECONNECT 4
56
#define ASYNCSOCKET_EVENT_CLOSED 2
59
#define ASYNCSOCKET_EVENT_CLOSED 5
-
 
60
#define ASYNCSOCKET_EVENT_RESET 6
57
#define ASYNCSOCKET_EVENT_DIED 3
61
#define ASYNCSOCKET_EVENT_DIED 7
58
#define ASYNCSOCKET_EVENT_INACTIVITY 4
62
#define ASYNCSOCKET_EVENT_INACTIVITY 8
59
 
63
 
60
const int MAXBUFFER = 1024;
64
const int MAXBUFFER = 1024;
61
const int MAXCONNECTIONS = 10;
65
const int MAXCONNECTIONS = 10;
62
 
66
 
63
class AsyncSocket : public Thread<AsyncSocket>
67
class AsyncSocket : public Thread<AsyncSocket>
Line 72... Line 76...
72
    void setAddress(string address, int port);
76
    void setAddress(string address, int port);
73
    void setPort(int port);
77
    void setPort(int port);
74
    void setSocket(int socket);
78
    void setSocket(int socket);
75
    int getSocket();
79
    int getSocket();
76
 
80
 
-
 
81
    bool availableEvent();
77
    void startEvent();
82
    void startEvent();
78
    int getEvent();
83
    int getEvent();
79
    void waitForEvent();
84
    void waitForEvent();
80
    void stopEvent();
85
    void stopEvent();
81
 
86
 
Line 86... Line 91...
86
    void forceReconnect();
91
    void forceReconnect();
87
    void startListen();
92
    void startListen();
88
    bool accept(AsyncSocket* newSocket);
93
    bool accept(AsyncSocket* newSocket);
89
    bool isConnected();
94
    bool isConnected();
90
 
95
 
91
    static void signalHandler(int signum);
96
    //static void signalHandler(int signum);
92
    string getId() { return myId; };
97
    string getId() { return myId; };
93
 
98
 
94
    static Mutex mySocketsMutex;
99
    //static Mutex mySocketsMutex;
95
    static map<string, AsyncSocket*> mySockets;
100
    //static map<string, AsyncSocket*> mySockets;
96
    Semaphore mySemaphore;
101
    //static Semaphore mySemaphore;
97
 
102
 
98
protected:
103
protected:
99
    void reconnectLoop();
104
    void reconnectLoop();
100
    void connect();
105
    void connect();
101
    void create();
106
    void create();
Line 105... Line 110...
105
 
110
 
106
 
111
 
107
private:
112
private:
108
    string myId;
113
    string myId;
109
    Semaphore myEventSemaphore;
114
    Semaphore myEventSemaphore;
110
    int myEvent;
115
    ThreadSafeQueue<int> myEventQueue;
111
 
116
 
112
    bool myForceReconnect;
117
    bool myForceReconnect;
113
   
118
   
114
    ThreadSafeQueue<string> myInQueue;
119
    ThreadSafeQueue<string> myInQueue;
115
    ThreadSafeQueue<string> myOutQueue;
120
    //ThreadSafeQueue<string> myOutQueue;
116
 
121
 
117
    int mySocket;
122
    int mySocket;
118
    sockaddr_in myAddressStruct;
123
    sockaddr_in myAddressStruct;
119
    string myAddress;
124
    string myAddress;
120
    int myPort;
125
    int myPort;