Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
[2.4.4] add calls to WSAStartup and WSACleanup in examples (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Ninon committed Jul 2, 2017
1 parent e086db2 commit 4d4150a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <mutex>
#include <signal.h>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

std::condition_variable cv;

void
Expand All @@ -49,6 +53,17 @@ on_new_message(tacopie::tcp_client& client, const tacopie::tcp_client::read_resu

int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;

if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */

tacopie::tcp_client client;
client.connect("127.0.0.1", 3001);
client.async_read({1024, std::bind(&on_new_message, std::ref(client), std::placeholders::_1)});
Expand All @@ -59,5 +74,9 @@ main(void) {
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock);

#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */

return 0;
}
19 changes: 19 additions & 0 deletions examples/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <mutex>
#include <signal.h>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

std::condition_variable cv;

void
Expand All @@ -49,6 +53,17 @@ on_new_message(const std::shared_ptr<tacopie::tcp_client>& client, const tacopie

int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;

if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */

tacopie::tcp_server s;
s.start("127.0.0.1", 3001, [](const std::shared_ptr<tacopie::tcp_client>& client) -> bool {
std::cout << "New client" << std::endl;
Expand All @@ -62,5 +77,9 @@ main(void) {
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock);

#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */

return 0;
}

0 comments on commit 4d4150a

Please sign in to comment.