summaryrefslogtreecommitdiffstats
path: root/tests/Network/NameLookup.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-11 11:21:18 +0100
committerMattes D <github@xoft.cz>2015-01-22 20:12:45 +0100
commitfde44cba0815f626253c0d352cd0d782eec94328 (patch)
treea25648d28be80c624b3fea7240c8449991d08564 /tests/Network/NameLookup.cpp
parentExcluded PolarSSL tests from MCS tests. (diff)
downloadcuberite-fde44cba0815f626253c0d352cd0d782eec94328.tar
cuberite-fde44cba0815f626253c0d352cd0d782eec94328.tar.gz
cuberite-fde44cba0815f626253c0d352cd0d782eec94328.tar.bz2
cuberite-fde44cba0815f626253c0d352cd0d782eec94328.tar.lz
cuberite-fde44cba0815f626253c0d352cd0d782eec94328.tar.xz
cuberite-fde44cba0815f626253c0d352cd0d782eec94328.tar.zst
cuberite-fde44cba0815f626253c0d352cd0d782eec94328.zip
Diffstat (limited to 'tests/Network/NameLookup.cpp')
-rw-r--r--tests/Network/NameLookup.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/Network/NameLookup.cpp b/tests/Network/NameLookup.cpp
new file mode 100644
index 000000000..daa72a3cb
--- /dev/null
+++ b/tests/Network/NameLookup.cpp
@@ -0,0 +1,67 @@
+
+// NameLookup.cpp
+
+// Implements a DNS name lookup using the LibEvent-based cNetwork API
+
+#include "Globals.h"
+#include <thread>
+#include "OSSupport/Event.h"
+#include "OSSupport/Network.h"
+
+
+
+
+
+class cFinishLookupCallbacks:
+ public cNetwork::cResolveNameCallbacks
+{
+ cEvent & m_Event;
+
+ virtual void OnNameResolved(const AString & a_Name, const AString & a_IP) override
+ {
+ LOGD("%s resolves to IP %s", a_Name.c_str(), a_IP.c_str());
+ }
+
+ virtual void OnError(int a_ErrorCode) override
+ {
+ LOGD("Error %d while performing lookup!", a_ErrorCode);
+ abort();
+ }
+
+ virtual void OnFinished(void) override
+ {
+ LOGD("Resolving finished.");
+ m_Event.Set();
+ }
+
+public:
+ cFinishLookupCallbacks(cEvent & a_Event):
+ m_Event(a_Event)
+ {
+ }
+};
+
+
+
+
+
+int main()
+{
+ cEvent evtFinish;
+
+ LOGD("Network test: Looking up google.com");
+ if (!cNetwork::HostnameToIP("google.com", std::make_shared<cFinishLookupCallbacks>(evtFinish)))
+ {
+ LOGWARNING("Cannot resolve google.com");
+ abort();
+ }
+ LOGD("Name lookup has been successfully queued");
+
+ evtFinish.Wait();
+ LOGD("Network test finished");
+ return 0;
+}
+
+
+
+