From 9c04a107c9b3b3d3b32041d4f0833f3dc46c81be Mon Sep 17 00:00:00 2001 From: Fredrik Skogman Date: Fri, 9 Sep 2016 06:50:41 +0800 Subject: [PATCH] Updated test programs to build on Solaris. Some whitespaces cleanup. --- test-server/fuzxy.c | 27 ++++++++++++++-------- test-server/test-echo.c | 37 +++++++++++++++++------------- test-server/test-ping.c | 6 ++++- test-server/test-server-pthreads.c | 21 ++++++++++------- test-server/test-server.c | 23 +++++++++++-------- 5 files changed, 71 insertions(+), 43 deletions(-) diff --git a/test-server/fuzxy.c b/test-server/fuzxy.c index 03024b72..0ab8e141 100644 --- a/test-server/fuzxy.c +++ b/test-server/fuzxy.c @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * MA 02110-1301 USA * * * fuzxy is designed to go on the client path @@ -66,6 +66,10 @@ #include #endif +#if defined(__sun) +#include /* bzero */ +#endif + #define MAX_FUZZ_BUF (1024 * 1024) enum types { @@ -394,11 +398,11 @@ static struct option options[] = { { "port", required_argument, NULL, 'p' }, { "ssl", no_argument, NULL, 's' }, { "allow-non-ssl", no_argument, NULL, 'a' }, - { "interface", required_argument, NULL, 'i' }, - { "closetest", no_argument, NULL, 'c' }, + { "interface", required_argument, NULL, 'i' }, + { "closetest", no_argument, NULL, 'c' }, { "libev", no_argument, NULL, 'e' }, #ifndef LWS_NO_DAEMONIZE - { "daemonize", no_argument, NULL, 'D' }, + { "daemonize", no_argument, NULL, 'D' }, #endif { "resource_path", required_argument, NULL, 'r' }, { NULL, 0, 0, 0 } @@ -486,7 +490,7 @@ fuzxy_listen(const char *interface_name, int port, int *sockfd) if (interface_name[0] && lws_interface_to_sa(0, interface_name, (struct sockaddr_in *) - (struct sockaddr *)&serv_addr4, + (struct sockaddr *)&serv_addr4, sizeof(serv_addr4)) < 0) { lwsl_err("Unable to find interface %s\n", interface_name); goto bail2; @@ -756,10 +760,15 @@ main(int argc, char **argv) int n = 0, m; #ifndef _WIN32 +/* LOG_PERROR is not POSIX standard, and may not be portable */ +#ifdef __sun + int syslog_options = LOG_PID; +#else int syslog_options = LOG_PID | LOG_PERROR; #endif +#endif #ifndef LWS_NO_DAEMONIZE - int daemonize = 0; + int daemonize = 0; #endif signal(SIGPIPE, sigpipe_handler); @@ -774,7 +783,7 @@ main(int argc, char **argv) #ifndef LWS_NO_DAEMONIZE case 'D': daemonize = 1; - #ifndef _WIN32 + #if !defined(_WIN32) && !defined(__sun) syslog_options &= ~LOG_PERROR; #endif break; @@ -913,8 +922,8 @@ main(int argc, char **argv) /* * draw down enough of the partner's * in ring to either exhaust it - * or fill an output buffer - */ + * or fill an output buffer + */ m = fuzz(n, out, sizeof(out)); if (m < 0) { lwsl_err("Error on fuzz\n"); diff --git a/test-server/test-echo.c b/test-server/test-echo.c index 75390f67..854f032a 100644 --- a/test-server/test-echo.c +++ b/test-server/test-echo.c @@ -14,7 +14,7 @@ * all without asking permission. * * The test apps are intended to be adapted for use in your code, which - * may be proprietary. So unlike the library itself, they are licensed + * may be proprietary. So unlike the library itself, they are licensed * Public Domain. */ @@ -216,7 +216,7 @@ static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, { "port", required_argument, NULL, 'p' }, - { "ssl-cert", required_argument, NULL, 'C' }, + { "ssl-cert", required_argument, NULL, 'C' }, { "ssl-key", required_argument, NULL, 'k' }, #ifndef LWS_NO_CLIENT { "client", required_argument, NULL, 'c' }, @@ -226,11 +226,11 @@ static struct option options[] = { { "versa", no_argument, NULL, 'v' }, { "uri", required_argument, NULL, 'u' }, { "passphrase", required_argument, NULL, 'P' }, - { "interface", required_argument, NULL, 'i' }, + { "interface", required_argument, NULL, 'i' }, { "times", required_argument, NULL, 'n' }, { "echogen", no_argument, NULL, 'e' }, #ifndef LWS_NO_DAEMONIZE - { "daemonize", no_argument, NULL, 'D' }, + { "daemonize", no_argument, NULL, 'D' }, #endif { NULL, 0, 0, 0 } }; @@ -247,7 +247,12 @@ int main(int argc, char **argv) char ssl_cert[256] = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem"; char ssl_key[256] = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem"; #ifndef _WIN32 +/* LOG_PERROR is not POSIX standard, and may not be portable */ +#ifdef __sun + int syslog_options = LOG_PID; +#else int syslog_options = LOG_PID | LOG_PERROR; +#endif #endif int client = 0; int listen_port = 80; @@ -310,7 +315,7 @@ int main(int argc, char **argv) #ifndef LWS_NO_DAEMONIZE case 'D': daemonize = 1; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__sun) syslog_options &= ~LOG_PERROR; #endif break; @@ -354,21 +359,21 @@ int main(int argc, char **argv) case '?': case 'h': fprintf(stderr, "Usage: libwebsockets-test-echo\n" - " --debug / -d \n" - " --port / -p \n" - " --ssl-cert / -C \n" - " --ssl-key / -k \n" + " --debug / -d \n" + " --port / -p \n" + " --ssl-cert / -C \n" + " --ssl-key / -k \n" #ifndef LWS_NO_CLIENT - " --client / -c \n" - " --ratems / -r \n" + " --client / -c \n" + " --ratems / -r \n" #endif - " --ssl / -s\n" + " --ssl / -s\n" " --passphrase / -P \n" - " --interface / -i \n" - " --uri / -u \n" - " --times / -n <-1 unlimited or times to echo>\n" + " --interface / -i \n" + " --uri / -u \n" + " --times / -n <-1 unlimited or times to echo>\n" #ifndef LWS_NO_DAEMONIZE - " --daemonize / -D\n" + " --daemonize / -D\n" #endif ); exit(1); diff --git a/test-server/test-ping.c b/test-server/test-ping.c index 3d073d81..d10e20da 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -14,7 +14,7 @@ * all without asking permission. * * The test apps are intended to be adapted for use in your code, which - * may be proprietary. So unlike the library itself, they are licensed + * may be proprietary. So unlike the library itself, they are licensed * Public Domain. */ @@ -42,6 +42,10 @@ #include #endif +#ifdef __sun +#include +#endif + /* * this is specified in the 04 standard, control frames can only have small * payload length styles diff --git a/test-server/test-server-pthreads.c b/test-server/test-server-pthreads.c index 7e386e00..963736e5 100644 --- a/test-server/test-server-pthreads.c +++ b/test-server/test-server-pthreads.c @@ -14,7 +14,7 @@ * all without asking permission. * * The test apps are intended to be adapted for use in your code, which - * may be proprietary. So unlike the library itself, they are licensed + * may be proprietary. So unlike the library itself, they are licensed * Public Domain. */ @@ -45,7 +45,7 @@ char crl_path[1024] = ""; /* * This mutex lock protects code that changes or relies on wsi list outside of - * the service thread. The service thread will acquire it when changing the + * the service thread. The service thread will acquire it when changing the * wsi list and other threads should acquire it while dereferencing wsis or * calling apis like lws_callback_on_writable_all_protocol() which * use the wsi list and wsis from a different thread context. @@ -176,12 +176,12 @@ static struct option options[] = { { "port", required_argument, NULL, 'p' }, { "ssl", no_argument, NULL, 's' }, { "allow-non-ssl", no_argument, NULL, 'a' }, - { "interface", required_argument, NULL, 'i' }, - { "closetest", no_argument, NULL, 'c' }, + { "interface", required_argument, NULL, 'i' }, + { "closetest", no_argument, NULL, 'c' }, { "libev", no_argument, NULL, 'e' }, { "threads", required_argument, NULL, 'j' }, #ifndef LWS_NO_DAEMONIZE - { "daemonize", no_argument, NULL, 'D' }, + { "daemonize", no_argument, NULL, 'D' }, #endif { "resource_path", required_argument, NULL, 'r' }, { NULL, 0, 0, 0 } @@ -195,16 +195,21 @@ int main(int argc, char **argv) pthread_t pthread_dumb, pthread_service[32]; char cert_path[1024]; char key_path[1024]; - int threads = 1; + int threads = 1; int use_ssl = 0; void *retval; int opts = 0; int n = 0; #ifndef _WIN32 +/* LOG_PERROR is not POSIX standard, and may not be portable */ +#ifdef __sun + int syslog_options = LOG_PID; +#else int syslog_options = LOG_PID | LOG_PERROR; #endif +#endif #ifndef LWS_NO_DAEMONIZE - int daemonize = 0; + int daemonize = 0; #endif /* @@ -235,7 +240,7 @@ int main(int argc, char **argv) #ifndef LWS_NO_DAEMONIZE case 'D': daemonize = 1; - #ifndef _WIN32 + #if !defined(_WIN32) && !defined(__sun) syslog_options &= ~LOG_PERROR; #endif break; diff --git a/test-server/test-server.c b/test-server/test-server.c index 85b9c1bb..466bf98e 100644 --- a/test-server/test-server.c +++ b/test-server/test-server.c @@ -14,7 +14,7 @@ * all without asking permission. * * The test apps are intended to be adapted for use in your code, which - * may be proprietary. So unlike the library itself, they are licensed + * may be proprietary. So unlike the library itself, they are licensed * Public Domain. */ @@ -122,7 +122,7 @@ static struct lws_protocols protocols[] = { }; -/* this shows how to override the lws file operations. You don't need +/* this shows how to override the lws file operations. You don't need * to do any of this unless you have a reason (eg, want to serve * compressed files without decompressing the whole archive) */ @@ -169,20 +169,20 @@ static struct option options[] = { { "port", required_argument, NULL, 'p' }, { "ssl", no_argument, NULL, 's' }, { "allow-non-ssl", no_argument, NULL, 'a' }, - { "interface", required_argument, NULL, 'i' }, - { "closetest", no_argument, NULL, 'c' }, + { "interface", required_argument, NULL, 'i' }, + { "closetest", no_argument, NULL, 'c' }, { "ssl-cert", required_argument, NULL, 'C' }, { "ssl-key", required_argument, NULL, 'K' }, { "ssl-ca", required_argument, NULL, 'A' }, #if defined(LWS_OPENSSL_SUPPORT) - { "ssl-verify-client", no_argument, NULL, 'v' }, + { "ssl-verify-client", no_argument, NULL, 'v' }, #if defined(LWS_HAVE_SSL_CTX_set1_param) { "ssl-crl", required_argument, NULL, 'R' }, #endif #endif { "libev", no_argument, NULL, 'e' }, #ifndef LWS_NO_DAEMONIZE - { "daemonize", no_argument, NULL, 'D' }, + { "daemonize", no_argument, NULL, 'D' }, #endif { "resource_path", required_argument, NULL, 'r' }, { NULL, 0, 0, 0 } @@ -202,10 +202,15 @@ int main(int argc, char **argv) int opts = 0; int n = 0; #ifndef _WIN32 +/* LOG_PERROR is not POSIX standard, and may not be portable */ +#ifdef __sun + int syslog_options = LOG_PID; +#else int syslog_options = LOG_PID | LOG_PERROR; #endif +#endif #ifndef LWS_NO_DAEMONIZE - int daemonize = 0; + int daemonize = 0; #endif /* @@ -226,7 +231,7 @@ int main(int argc, char **argv) #ifndef LWS_NO_DAEMONIZE case 'D': daemonize = 1; - #ifndef _WIN32 + #if !defined(_WIN32) && !defined(__sun) syslog_options &= ~LOG_PERROR; #endif break; @@ -396,7 +401,7 @@ int main(int argc, char **argv) return -1; } - /* this shows how to override the lws file operations. You don't need + /* this shows how to override the lws file operations. You don't need * to do any of this unless you have a reason (eg, want to serve * compressed files without decompressing the whole archive) */