Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
return NULL;
}
+ /**
+ * Used to judge whether this connection is ready to send. Usually, the
+ * implementation need to build a own shakehand or sesson then it can be
+ * ready to send.
+ *
+ * @return true if ready to send, or false otherwise
+ */
virtual bool is_connected() = 0;
Messenger *get_messenger() {
pipe = p->get();
}
-bool PipeConnection::is_connected() {
- Mutex::Locker l(lock);
- if (pipe)
- return pipe->is_connected();
- return false;
+bool PipeConnection::is_connected()
+{
+ return static_cast<SimpleMessenger*>(msgr)->is_connected(this);
}
int PipeConnection::send_message(Message *m)
lock.Unlock();
}
-
+bool SimpleMessenger::is_connected(Connection *con)
+{
+ bool r = false;
+ if (con) {
+ Pipe *p = static_cast<Pipe *>(static_cast<PipeConnection*>(con)->get_pipe());
+ if (p) {
+ assert(p->msgr == this);
+ r = p->is_connected();
+ p->put();
+ }
+ }
+ return r;
+}
int SimpleMessenger::bind(const entity_addr_t &bind_addr)
{
* ready to be torn down.
*/
void queue_reap(Pipe *pipe);
+
+ /**
+ * Used to get whether this connection ready to send
+ */
+ bool is_connected(Connection *con);
/**
* @} // SimpleMessenger Internals
*/