diff options
-rw-r--r-- | orkaudio/OrkAudio.cpp | 2 | ||||
-rw-r--r-- | orkbasecxx/messages/PingMsg.cpp | 55 | ||||
-rw-r--r-- | orkbasecxx/messages/PingMsg.h | 14 |
3 files changed, 71 insertions, 0 deletions
diff --git a/orkaudio/OrkAudio.cpp b/orkaudio/OrkAudio.cpp index 3cfa931..689f771 100644 --- a/orkaudio/OrkAudio.cpp +++ b/orkaudio/OrkAudio.cpp @@ -185,6 +185,8 @@ void MainThread() ObjectFactory::GetSingleton()->RegisterObject(objRef); objRef.reset(new CaptureMsg); ObjectFactory::GetSingleton()->RegisterObject(objRef); + objRef.reset(new TcpPingMsg); + ObjectFactory::GetSingleton()->RegisterObject(objRef); //objRef.reset(new TestMsg); //ObjectFactory::GetSingleton()->RegisterObject(objRef); diff --git a/orkbasecxx/messages/PingMsg.cpp b/orkbasecxx/messages/PingMsg.cpp index 1f90bbe..e75beb8 100644 --- a/orkbasecxx/messages/PingMsg.cpp +++ b/orkbasecxx/messages/PingMsg.cpp @@ -11,6 +11,9 @@ * */ +#include "ace/INET_Addr.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_Stream.h" #include "PingMsg.h" #define PING_CLASS "ping" @@ -58,3 +61,55 @@ ObjectRef PingMsg::Process() return ref; } +//=============================== +#define TCP_PING_CLASS "tcpping" + +void TcpPingMsg::Define(Serializer* s) +{ + CStdString tcpPingClass(TCP_PING_CLASS); + s->StringValue(OBJECT_TYPE_TAG, tcpPingClass, true); + s->StringValue("hostname", m_hostname, true); + s->IntValue("port", (int&)m_port, true); +} + + +CStdString TcpPingMsg::GetClassName() +{ + return CStdString(TCP_PING_CLASS); +} + +ObjectRef TcpPingMsg::NewInstance() +{ + return ObjectRef(new TcpPingMsg); +} + +ObjectRef TcpPingMsg::Process() +{ + bool success = true; + CStdString logMsg; + ACE_SOCK_Connector connector; + ACE_SOCK_Stream peer; + ACE_INET_Addr peer_addr; + ACE_Time_Value aceTimeout (5); + + if (peer_addr.set (m_port, (PCSTR)m_hostname) == -1) + { + logMsg.Format("peer_addr.set() errno=%d", errno); + success = false; + } + else if (connector.connect (peer, peer_addr, &aceTimeout) == -1) + { + if (errno == ETIME) + { + } + logMsg.Format("connector.connect() errno=%d", errno); + success = false; + } + + SimpleResponseMsg* msg = new SimpleResponseMsg; + ObjectRef ref(msg); + msg->m_success = success; + msg->m_comment = logMsg; + return ref; +} + diff --git a/orkbasecxx/messages/PingMsg.h b/orkbasecxx/messages/PingMsg.h index 52a46c4..71ab240 100644 --- a/orkbasecxx/messages/PingMsg.h +++ b/orkbasecxx/messages/PingMsg.h @@ -42,5 +42,19 @@ public: ObjectRef Process(); }; +class DLL_IMPORT_EXPORT_ORKBASE TcpPingMsg : public SyncMessage +{ +public: + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + ObjectRef Process(); + + CStdString m_hostname; + int m_port; +}; + #endif |