Skip to content

Commit

Permalink
update demos to not use deprecated functions (nanomsg#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
urkle authored and JaylinYu committed Nov 29, 2021
1 parent 297f7bf commit bd9355e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
7 changes: 5 additions & 2 deletions demo/async/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# file was obtained (LICENSE.txt). A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.

cmake_minimum_required (VERSION 2.8.7)
cmake_minimum_required (VERSION 2.8.12)

project(nng-asyncdemo)

Expand All @@ -16,9 +16,12 @@ set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)")
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)

find_package(Threads)

add_executable(server server.c)
target_link_libraries(server nng::nng)
target_compile_definitions(server PRIVATE -DPARALLEL=${PARALLEL})
target_compile_definitions(server PRIVATE NNG_ELIDE_DEPRECATED PARALLEL=${PARALLEL})

add_executable(client client.c)
target_link_libraries(client nng::nng)
target_compile_definitions(client PRIVATE NNG_ELIDE_DEPRECATED)
5 changes: 4 additions & 1 deletion demo/http_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
# file was obtained (LICENSE.txt). A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.

cmake_minimum_required (VERSION 2.8.7)
cmake_minimum_required (VERSION 2.8.12)

project(http_client)

# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)

find_package(Threads)

add_executable(http_client http_client.c)
target_link_libraries(http_client nng::nng)
target_compile_definitions(http_client PRIVATE NNG_ELIDE_DEPRECATED)
6 changes: 4 additions & 2 deletions demo/raw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
# file was obtained (LICENSE.txt). A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.

cmake_minimum_required (VERSION 2.8.7)
cmake_minimum_required (VERSION 2.8.12)

project(raw)

set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)")

find_package(nng CONFIG REQUIRED)

find_package(Threads)

add_executable(raw raw.c)
target_link_libraries(raw nng::nng)
target_compile_definitions(raw PRIVATE -DPARALLEL=${PARALLEL})
target_compile_definitions(raw PRIVATE NNG_ELIDE_DEPRECATED PARALLEL=${PARALLEL})
3 changes: 2 additions & 1 deletion demo/reqrep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# file was obtained (LICENSE.txt). A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.

cmake_minimum_required (VERSION 2.8.7)
cmake_minimum_required (VERSION 2.8.12)

project(reqrep)

Expand All @@ -20,3 +20,4 @@ find_package(Threads)

add_executable(reqrep reqrep.c)
target_link_libraries(reqrep nng::nng)
target_compile_definitions(reqrep PRIVATE NNG_ELIDE_DEPRECATED)
32 changes: 16 additions & 16 deletions demo/reqrep/reqrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ server(const char *url)
if (strncmp(url, "zt://", 5) == 0) {
printf("ZeroTier transport will store its keys in current working directory.\n");
printf("The server and client instances must run in separate directories.\n");
nng_listener_setopt_string(listener, NNG_OPT_ZT_HOME, ".");
nng_listener_setopt_ms(listener, NNG_OPT_RECONNMINT, 1);
nng_listener_setopt_ms(listener, NNG_OPT_RECONNMAXT, 1000);
nng_setopt_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
nng_setopt_ms(sock, NNG_OPT_RECVMAXSZ, 0);
nng_listener_setopt_ms(listener, NNG_OPT_ZT_PING_TIME, 10000);
nng_listener_setopt_ms(listener, NNG_OPT_ZT_CONN_TIME, 1000);
nng_listener_set_string(listener, NNG_OPT_ZT_HOME, ".");
nng_listener_set_ms(listener, NNG_OPT_RECONNMINT, 1);
nng_listener_set_ms(listener, NNG_OPT_RECONNMAXT, 1000);
nng_socket_set_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
nng_socket_set_ms(sock, NNG_OPT_RECVMAXSZ, 0);
nng_listener_set_ms(listener, NNG_OPT_ZT_PING_TIME, 10000);
nng_listener_set_ms(listener, NNG_OPT_ZT_CONN_TIME, 1000);
} else {
nng_setopt_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
nng_socket_set_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
}
nng_listener_start(listener, 0);

Expand Down Expand Up @@ -158,15 +158,15 @@ client(const char *url)
if (strncmp(url, "zt://", 5) == 0) {
printf("ZeroTier transport will store its keys in current working directory\n");
printf("The server and client instances must run in separate directories.\n");
nng_dialer_setopt_string(dialer, NNG_OPT_ZT_HOME, ".");
nng_dialer_setopt_ms(dialer, NNG_OPT_RECONNMINT, 1);
nng_dialer_setopt_ms(dialer, NNG_OPT_RECONNMAXT, 1000);
nng_setopt_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
nng_setopt_ms(sock, NNG_OPT_RECVMAXSZ, 0);
nng_dialer_setopt_ms(dialer, NNG_OPT_ZT_PING_TIME, 10000);
nng_dialer_setopt_ms(dialer, NNG_OPT_ZT_CONN_TIME, 1000);
nng_dialer_set_string(dialer, NNG_OPT_ZT_HOME, ".");
nng_dialer_set_ms(dialer, NNG_OPT_RECONNMINT, 1);
nng_dialer_set_ms(dialer, NNG_OPT_RECONNMAXT, 1000);
nng_socket_set_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
nng_socket_set_ms(sock, NNG_OPT_RECVMAXSZ, 0);
nng_dialer_set_ms(dialer, NNG_OPT_ZT_PING_TIME, 10000);
nng_dialer_set_ms(dialer, NNG_OPT_ZT_CONN_TIME, 1000);
} else {
nng_setopt_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
nng_socket_set_ms(sock, NNG_OPT_REQ_RESENDTIME, 2000);
}

nng_dialer_start(dialer, NNG_FLAG_NONBLOCK);
Expand Down
5 changes: 4 additions & 1 deletion demo/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
# file was obtained (LICENSE.txt). A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.

cmake_minimum_required (VERSION 2.8.7)
cmake_minimum_required (VERSION 2.8.12)

project(rest)

find_package(nng CONFIG REQUIRED)

find_package(Threads)

add_executable(rest-server server.c)
target_link_libraries(rest-server nng::nng)
target_compile_definitions(rest-server PRIVATE NNG_ELIDE_DEPRECATED)

0 comments on commit bd9355e

Please sign in to comment.