Merge pull request #110 from tesselode/fixes
[wdl/wdl-ol.git] / WDL / shm_connection.h
blobbc3f676233521b8a097fa58e04e4ea0caf76d7b7
1 #ifndef _WDL_SHM_CONNECTION_H_
2 #define _WDL_SHM_CONNECTION_H_
4 #ifdef _WIN32
5 #include <windows.h>
6 #else
7 #include "swell/swell.h"
8 #include "swell/swell-internal.h"
9 #endif
11 #include <time.h>
13 #include "wdlstring.h"
14 #include "wdltypes.h"
15 #include "queue.h"
17 class WDL_SHM_Connection
19 public:
20 WDL_SHM_Connection(bool whichChan, // a true con connects to a false con -- note on SHM false should be created FIRST.
21 const char *uniquestring, // identify
22 int shmsize=262144, // bytes, whoever opens first decides
23 int timeout_sec=0,
24 int extra_flags=0 // on posix, set 1 for the master to create a .lock file as well
27 ~WDL_SHM_Connection();
29 int Run(); // call as often as possible, returns <0 error, >0 if did something
31 bool WantSendKeepAlive(); // called when it needs a keepalive to be sent (may be never, or whatever interval it decides)
33 // wait for this if you want to see when data comes in
34 HANDLE GetWaitEvent()
36 #ifdef _WIN32
37 return m_events[m_whichChan];
38 #else
39 return m_waitevt;
40 #endif
43 // receiving and sending data
44 WDL_Queue recv_queue;
45 WDL_Queue send_queue;
48 private:
51 int m_timeout_sec;
52 time_t m_last_recvt;
53 int m_timeout_cnt;
55 WDL_String m_tempfn;
57 int m_whichChan; // which channel we read from
59 #ifdef _WIN32
61 HANDLE m_file, m_filemap;
62 HANDLE m_events[2]; // [m_whichChan] set when the other side did something useful
63 HANDLE m_lockmutex;
65 unsigned char *m_mem;
66 #else
67 time_t m_next_keepalive;
69 int m_sockbufsize;
71 int m_rdbufsize;
72 char *m_rdbuf; // m_rdbufsize
74 int m_listen_socket;
75 int m_socket;
77 HANDLE m_waitevt;
78 void *m_sockaddr;
80 void acquireListener();
81 WDL_String m_lockfn;
82 int m_lockhandle;
83 #endif
87 #endif