diff options
Diffstat (limited to 'fnet/src/examples')
-rw-r--r-- | fnet/src/examples/ping/pingclient.cpp | 9 | ||||
-rw-r--r-- | fnet/src/examples/timeout/timeout.cpp | 12 |
2 files changed, 13 insertions, 8 deletions
diff --git a/fnet/src/examples/ping/pingclient.cpp b/fnet/src/examples/ping/pingclient.cpp index 6a7bd21e715..afd2475bfa0 100644 --- a/fnet/src/examples/ping/pingclient.cpp +++ b/fnet/src/examples/ping/pingclient.cpp @@ -22,7 +22,7 @@ int PingClient::Main() { if (_argc < 2) { - printf("usage : pingclient <connectspec>\n"); + printf("usage : pingclient <connectspec> <timeout>\n"); printf("example: pingclient 'tcp/localhost:8000'\n"); return 1; } @@ -33,7 +33,12 @@ PingClient::Main() FNET_SimplePacketStreamer streamer(&factory); FNET_Transport transport; FNET_Connection *conn = transport.Connect(_argv[1], &streamer); + uint32_t timeout_ms=5000; FNET_Channel *channels[10]; + + if (_argc == 3) { + timeout_ms = atof(_argv[2]) * 1000; + } transport.Start(&pool); uint32_t channelCnt = 0; @@ -52,7 +57,7 @@ PingClient::Main() FNET_Packet *packet; FNET_Context context; while (channelCnt > 0) { - packet = queue.DequeuePacket(5000, &context); + packet = queue.DequeuePacket(timeout_ms, &context); if (packet == nullptr) { fprintf(stderr, "Timeout\n"); for(int c = 0; c < 10; c++) { diff --git a/fnet/src/examples/timeout/timeout.cpp b/fnet/src/examples/timeout/timeout.cpp index 9f363ccd864..b2f6c3a8e3c 100644 --- a/fnet/src/examples/timeout/timeout.cpp +++ b/fnet/src/examples/timeout/timeout.cpp @@ -60,16 +60,16 @@ MyApp::Main() transport.Start(&pool); // stable-state operation - std::this_thread::sleep_for(500ms); + std::this_thread::sleep_for(100ms); FNET_Packet *packet; FNET_Context context; - fprintf(stderr, "scheduling timeout in 2 seconds...\n"); + fprintf(stderr, "scheduling timeout in 1 seconds...\n"); t = clock::now(); - timeout.Schedule(2.0); // timeout in 2 seconds + timeout.Schedule(1.0); // timeout in 1 seconds - std::this_thread::sleep_for(1s); + std::this_thread::sleep_for(100ms); timeout.Unschedule(); // cancel timeout ms = (clock::now() - t); @@ -78,9 +78,9 @@ MyApp::Main() fprintf(stderr, "timeout canceled; no timeout packet delivered\n"); fprintf(stderr, "time since timeout was scheduled: %f ms\n", ms.count()); - fprintf(stderr, "scheduling timeout in 2 seconds...\n"); + fprintf(stderr, "scheduling timeout in 1 seconds...\n"); t = clock::now(); - timeout.Schedule(2.0); // timeout in 2 seconds + timeout.Schedule(1.0); // timeout in 1 seconds packet = queue.DequeuePacket(&context); // wait for timeout ms = (clock::now() - t); |