/*
- * libwebsockets-test-ping - libwebsockets floodping
+ * libwebsockets-test-ping - libwebsockets test floodping
*
- * Copyright (C) 2011 Andy Green <andy@warmcat.com>
+ * Copyright (C) 2011-2016 Andy Green <andy@warmcat.com>
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation:
- * version 2.1 of the License.
+ * This file is made available under the Creative Commons CC0 1.0
+ * Universal Public Domain Dedication.
*
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
+ * The person who associated a work with this deed has dedicated
+ * the work to the public domain by waiving all of his or her rights
+ * to the work worldwide under copyright law, including all related
+ * and neighboring rights, to the extent allowed by law. You can copy,
+ * modify, distribute and perform the work, even for commercial purposes,
+ * all without asking permission.
*
- * 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
+ * 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
+ * Public Domain.
*/
#include <stdio.h>
#include "gettimeofday.h"
#endif
+#ifdef __ANDROID__
+#include <termiosh>
+#endif
+
+#ifdef __sun
+#include <sys/termios.h>
+#endif
+
/*
* this is specified in the 04 standard, control frames can only have small
* payload length styles
static unsigned int size = 64;
static int flood;
static const char *address;
-static unsigned char pingbuf[LWS_SEND_BUFFER_PRE_PADDING + MAX_MIRROR_PAYLOAD +
- LWS_SEND_BUFFER_POST_PADDING];
+static unsigned char pingbuf[LWS_PRE + MAX_MIRROR_PAYLOAD];
static char peer_name[128];
static unsigned long started;
static int screen_width = 80;
};
struct per_session_data__ping {
- uint64_t ping_index;
+ unsigned long long ping_index;
struct ping ringbuffer[PING_RINGBUFFER_SIZE];
int ringbuffer_head;
unsigned char *p;
unsigned long iv;
int match = 0;
- uint64_t l;
+ unsigned long long l;
int shift;
int n;
l = 0;
while (shift >= 0) {
- l |= ((uint64_t)*p++) << shift;
+ l |= ((lws_intptr_t)*p++) << shift;
shift -= 8;
}
case LWS_CALLBACK_CLIENT_WRITEABLE:
shift = 56;
- p = &pingbuf[LWS_SEND_BUFFER_PRE_PADDING];
+ p = &pingbuf[LWS_PRE];
/* 64-bit ping index in network byte order */
while (shift >= 0) {
- *p++ = psd->ping_index >> shift;
+ *p++ = (unsigned char)(psd->ping_index >> shift);
shift -= 8;
}
- while (p - &pingbuf[LWS_SEND_BUFFER_PRE_PADDING] < size)
+ while ((unsigned int)(p - &pingbuf[LWS_PRE]) < size)
*p++ = 0;
gettimeofday(&tv, NULL);
psd->ringbuffer[psd->ringbuffer_head].issue_timestamp =
(tv.tv_sec * 1000000) + tv.tv_usec;
- psd->ringbuffer[psd->ringbuffer_head].index = psd->ping_index++;
+ psd->ringbuffer[psd->ringbuffer_head].index = (unsigned long)psd->ping_index++;
psd->ringbuffer[psd->ringbuffer_head].seen = 0;
if (psd->ringbuffer_head == PING_RINGBUFFER_SIZE - 1)
if (use_mirror)
n = lws_write(wsi,
- &pingbuf[LWS_SEND_BUFFER_PRE_PADDING],
+ &pingbuf[LWS_PRE],
size, write_options | LWS_WRITE_BINARY);
else
n = lws_write(wsi,
- &pingbuf[LWS_SEND_BUFFER_PRE_PADDING],
+ &pingbuf[LWS_PRE],
size, write_options | LWS_WRITE_PING);
if (n < 0)
return -1;
- if (n < size) {
+ if (n < (int)size) {
lwsl_err("Partial write\n");
return -1;
}
}
};
+static const struct lws_extension exts[] = {
+ {
+ "permessage-deflate",
+ lws_extension_callback_pm_deflate,
+ "permessage-deflate; client_no_context_takeover; client_max_window_bits"
+ },
+ {
+ "deflate-frame",
+ lws_extension_callback_pm_deflate,
+ "deflate_frame"
+ },
+ { NULL, NULL, NULL /* terminator */ }
+};
+
static struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "debug", required_argument, NULL, 'd' },
int port = 7681;
int use_ssl = 0;
struct lws_context *context;
- char protocol_name[256];
+ char protocol_name[256], ads_port[300];
char ip[30];
#ifndef _WIN32
struct sigaction sa;
unsigned long l;
int ietf_version = -1;
struct lws_context_creation_info info;
+ struct lws_client_connect_info i;
memset(&info, 0, sizeof info);
if (argc < 2)
goto usage;
- address = argv[1];
- optind++;
-
while (n >= 0) {
n = getopt_long(argc, argv, "v:kr:hmfts:n:i:p:d:", options, NULL);
if (n < 0)
protocols[PROTOCOL_LWS_MIRROR].name = protocol_name;
break;
case 'i':
- interval_us = 1000000.0 * atof(optarg);
+ interval_us = (unsigned int)(1000000.0 * atof(optarg));
break;
case 's':
size = atoi(optarg);
case 'r':
clients = atoi(optarg);
if (clients > MAX_PING_CLIENTS || clients < 1) {
- fprintf(stderr, "Max clients supportd = %d\n",
+ fprintf(stderr, "Max clients supported = %d\n",
MAX_PING_CLIENTS);
return 1;
}
info.port = CONTEXT_PORT_NO_LISTEN;
info.protocols = protocols;
-#ifndef LWS_NO_EXTENSIONS
- info.extensions = lws_get_internal_extensions();
-#endif
+ info.extensions = exts;
+
info.gid = -1;
info.uid = -1;
+ if (use_ssl)
+ info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
+
context = lws_create_context(&info);
if (context == NULL) {
fprintf(stderr, "Creating libwebsocket context failed\n");
/* create client websockets using dumb increment protocol */
+ address = argv[optind];
+ lws_snprintf(ads_port, sizeof(ads_port), "%s:%u",
+ address, port & 65535);
+ lwsl_notice("Connecting to %s...\n", ads_port);
+ memset(&i, 0, sizeof(i));
+ i.context = context;
+ i.address = address;
+ i.port = port;
+ i.ssl_connection = use_ssl;
+ i.path = "/";
+ i.host = ads_port;
+ i.origin = ads_port;
+ i.protocol = protocols[PROTOCOL_LWS_MIRROR].name;
+ i.ietf_version_or_minus_one = ietf_version;
+
for (n = 0; n < clients; n++) {
- ping_wsi[n] = lws_client_connect(context, address,
- port, use_ssl, "/", address,
- "origin", protocols[PROTOCOL_LWS_MIRROR].name,
- ietf_version);
+ ping_wsi[n] = lws_client_connect_via_info(&i);
if (ping_wsi[n] == NULL) {
- fprintf(stderr, "client connection %d failed to "
- "connect\n", n);
+ lwsl_err("client %d failed to connect\n", n);
return 1;
}
}
lws_get_peer_addresses(ping_wsi[0], lws_get_socket_fd(ping_wsi[0]),
peer_name, sizeof peer_name, ip, sizeof ip);
+ lwsl_notice("libwebsockets test server ping - license LGPL2.1+SLE\n");
+ lwsl_notice("(C) Copyright 2010-2016 Andy Green <andy@warmcat.com>\n");
fprintf(stderr, "Websocket PING %s (%s) %d bytes of data.\n",
peer_name, ip, size);
/* stats */
- fprintf(stderr, "\n--- %s websocket ping statistics "
+ if (global_rx_count && global_tx_count)
+ fprintf(stderr, "\n--- %s websocket ping statistics "
"using %d connections ---\n"
"%lu packets transmitted, %lu received, "
"%lu%% packet loss, time %ldms\n"