]> AND Private Git Repository - loba.git/blob - communicator.h
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Use a vector for sent_comm (smaller and faster than a list).
[loba.git] / communicator.h
1 // Asynchronous communicator
2
3 #ifndef COMMUNICATOR_H
4 #define COMMUNICATOR_H
5
6 #include <vector>
7 #include <msg/msg.h>
8 #include "hostdata.h"
9 #include "messages.h"
10 #include "msg_thread.h"
11
12 class communicator {
13 public:
14     communicator();
15     ~communicator();
16
17     // Send a message to the "dest" mailbox
18     void send(const char* dest, message* msg);
19
20     // Try to flush pending sending communications.
21     // If "wait" is true, blocks until success.
22     void flush(bool wait);
23
24     // Try to get a message.  Returns true on success.
25     // Parameter "timeout" may be 0 for non-blocking operation, -1 for
26     // infinite waiting, or any positive timeout.
27     bool recv(message*& msg, m_host_t& from, double timeout);
28
29 private:
30     // Myself
31     const hostdata* host;
32
33     // List of pending send communications
34     typedef std::vector<msg_comm_t> sent_comm_type;
35     sent_comm_type sent_comm;
36
37     // Queue of received messages
38     message_queue received;
39
40     // Handling of receiving thread
41     msg_thread* receiver_thread;
42     void receiver();
43
44     // Used to chek if a communication is successfull before destroying it
45     static void comm_check_n_destroy(msg_comm_t comm);
46     // If comm is over, call comm_check_n_destroy(comm), and return true
47     static bool comm_test_n_destroy(msg_comm_t comm);
48 };
49
50 #endif // !COMMUNICATOR_H
51
52 // Local variables:
53 // mode: c++
54 // End: