From 6d91d5f8a11f44febb4fd4f0400acec77006e227 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 2 Dec 2014 08:42:47 +0800 Subject: [PATCH] test ping correct type for fprintf Reported-by: Michael Habeler Signed-off-by: Andy Green --- test-server/test-echo.c | 47 +++++++++++++++++++++++++++-------------------- test-server/test-ping.c | 5 +++-- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/test-server/test-echo.c b/test-server/test-echo.c index f1e7b4e..6cbb109 100644 --- a/test-server/test-echo.c +++ b/test-server/test-echo.c @@ -42,7 +42,7 @@ #include "../lib/libwebsockets.h" static volatile int force_exit = 0; -static int versa; +static int versa, state; #define MAX_ECHO_PAYLOAD 1400 #define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server" @@ -95,9 +95,16 @@ do_rx: #ifndef LWS_NO_CLIENT /* when the callback is used for client operations --> */ + case LWS_CALLBACK_CLOSED: + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_info("closed\n"); + state = 0; + break; + case LWS_CALLBACK_CLIENT_ESTABLISHED: lwsl_notice("Client has connected\n"); pss->index = 0; + state = 2; break; case LWS_CALLBACK_CLIENT_RECEIVE: @@ -220,7 +227,7 @@ int main(int argc, char **argv) #endif while (n >= 0) { - n = getopt_long(argc, argv, "i:hsp:d:DC:k:P:v" + n = getopt_long(argc, argv, "i:hsp:d:DC:k:P:vu:" #ifndef LWS_NO_CLIENT "c:r:" #endif @@ -377,24 +384,7 @@ int main(int argc, char **argv) return -1; } -#ifndef LWS_NO_CLIENT - if (client) { - lwsl_notice("Client connecting to %s:%u....\n", address, port); - /* we are in client mode */ - - address[sizeof(address) - 1] = '\0'; - sprintf(ads_port, "%s:%u\n", address, port & 65535); - - wsi = libwebsocket_client_connect(context, address, - port, use_ssl, uri, ads_port, - "origin", NULL, -1); - if (!wsi) { - lwsl_err("Client failed to connect to %s:%u\n", address, port); - goto bail; - } - lwsl_notice("Client connected to %s:%u\n", address, port); - } -#endif + signal(SIGINT, sighandler); n = 0; @@ -402,6 +392,23 @@ int main(int argc, char **argv) #ifndef LWS_NO_CLIENT struct timeval tv; + if (client && !state) { + state = 1; + lwsl_notice("Client connecting to %s:%u....\n", address, port); + /* we are in client mode */ + + address[sizeof(address) - 1] = '\0'; + sprintf(ads_port, "%s:%u\n", address, port & 65535); + + wsi = libwebsocket_client_connect(context, address, + port, use_ssl, uri, ads_port, + "origin", NULL, -1); + if (!wsi) { + lwsl_err("Client failed to connect to %s:%u\n", address, port); + goto bail; + } + } + if (client && !versa) { gettimeofday(&tv, NULL); diff --git a/test-server/test-ping.c b/test-server/test-ping.c index c04f286..504af80 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -190,7 +190,8 @@ callback_lws_mirror(struct libwebsocket_context * this, if (!flood) fprintf(stderr, "%d bytes from %s: req=%ld " - "time=(unknown)\n", (int)len, address, l); + "time=(unknown)\n", (int)len, address, + (long)l); else fprintf(stderr, "\b \b"); @@ -211,7 +212,7 @@ callback_lws_mirror(struct libwebsocket_context * this, if (!flood) fprintf(stderr, "%d bytes from %s: req=%ld " - "time=%lu.%lums\n", (int)len, address, l, + "time=%lu.%lums\n", (int)len, address, (long)l, (iv - psd->ringbuffer[n].issue_timestamp) / 1000, ((iv - psd->ringbuffer[n].issue_timestamp) / 100) % 10); else -- 2.7.4