Last active
August 29, 2015 14:09
-
-
Save jmorrill/b6be35c2c540a088c914 to your computer and use it in GitHub Desktop.
some networking in my libuv c++ wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
OUTPUT | |
initial thread id - 15684 | |
thread id - 15684 | |
got ip address - 74.125.224.165 | |
connected ! | |
*/ | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
cout << "initial thread id - " << this_thread::get_id() << endl; | |
auto dns = make_shared<net::dns>(); | |
auto socket = make_shared<net::stream_socket>(); | |
dns->resolve_host("google.com").then([socket](std::string& ipaddress) | |
{ | |
cout << "thread id - " << this_thread::get_id() << endl; | |
cout << "got ip address - " << ipaddress << endl; | |
return socket->connect_async(ipaddress, 80); | |
}, task_continuation_context::use_current()).then([]() | |
{ | |
cout << "connected !" << endl; | |
}, task_continuation_context::use_current()); | |
event_dispatcher::run(); | |
cout << "exiting..." << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment