From 2cd30747460bdf48eb72571efb3d7f751ab59d2e Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 2 Nov 2015 13:10:33 +0800 Subject: [PATCH] mbed3 warning cleaning Signed-off-by: Andy Green --- lib/base64-decode.c | 4 ++-- lib/context.c | 2 +- lib/header.c | 6 ++++++ lib/libwebsockets.c | 2 ++ lib/libwebsockets.h | 32 +++++++++++++++++++++++++------- lib/output.c | 9 ++++++--- lib/parsers.c | 4 ++-- lib/pollfd.c | 2 +- lib/private-libwebsockets.h | 21 ++++++++++++++------- lib/server.c | 10 ++++++---- lib/service.c | 4 ++-- 11 files changed, 67 insertions(+), 29 deletions(-) diff --git a/lib/base64-decode.c b/lib/base64-decode.c index baaccbb..bb074fc 100644 --- a/lib/base64-decode.c +++ b/lib/base64-decode.c @@ -151,8 +151,8 @@ int lws_b64_selftest(void) { char buf[64]; - int n; - int test; + unsigned int n; + unsigned int test; static const char * const plaintext[] = { "sanity check base 64" }; diff --git a/lib/context.c b/lib/context.c index 98c9ea2..3159b1f 100644 --- a/lib/context.c +++ b/lib/context.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2014 Andy Green + * Copyright (C) 2010-2015 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/lib/header.c b/lib/header.c index 8d83f5c..56c8fc0 100644 --- a/lib/header.c +++ b/lib/header.c @@ -40,6 +40,9 @@ int lws_add_http_header_by_name(struct libwebsocket_context *context, #ifdef LWS_USE_HTTP2 if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING) return lws_add_http2_header_by_name(context, wsi, name, value, length, p, end); +#else + (void)wsi; + (void)context; #endif if (name) { while (*p < end && *name) @@ -63,9 +66,12 @@ int lws_finalize_http_header(struct libwebsocket_context *context, unsigned char **p, unsigned char *end) { + (void)context; #ifdef LWS_USE_HTTP2 if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING) return 0; +#else + (void)wsi; #endif if ((long)(end - *p) < 3) return 1; diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 792d148..28f2c61 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -845,6 +845,7 @@ lws_is_ssl(struct libwebsocket *wsi) #ifdef LWS_OPENSSL_SUPPORT return wsi->use_ssl; #else + (void)wsi; return 0; #endif } @@ -898,6 +899,7 @@ lws_get_peer_write_allowance(struct libwebsocket *wsi) return wsi->u.http2.tx_credit; #else + (void)wsi; return -1; #endif } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 3e1db93..dfa40c7 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -25,6 +25,16 @@ #ifdef __cplusplus #include #include +#ifdef MBED_OPERATORS +#include "mbed-drivers/mbed.h" +#include "sal-iface-eth/EthernetInterface.h" +#include "sockets/TCPListener.h" +#include "sal-stack-lwip/lwipv4_init.h" +#define LWS_POSIX 0 +#else +#define LWS_POSIX 1 +#endif + extern "C" { #else #include @@ -155,13 +165,13 @@ LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); #else /* no debug */ -#define lwsl_info(...) -#define lwsl_debug(...) -#define lwsl_parser(...) -#define lwsl_header(...) -#define lwsl_ext(...) -#define lwsl_client(...) -#define lwsl_latency(...) +#define lwsl_info(...) {} +#define lwsl_debug(...) {} +#define lwsl_parser(...) {} +#define lwsl_header(...) {} +#define lwsl_ext(...) {} +#define lwsl_client(...) {} +#define lwsl_latency(...) {} #define lwsl_hexdump(a, b) #endif @@ -1262,6 +1272,14 @@ libwebsocket_set_timeout(struct libwebsocket *wsi, // they recommend that structures larger than 16 bytes be aligned to 16-byte // boundaries. // + +#if !defined(LWS_SIZEOFPTR) +#define LWS_SIZEOFPTR (sizeof (void *)) +#endif +#if !defined(u_int64_t) +#define u_int64_t unsigned long long +#endif + #if __x86_64__ #define _LWS_PAD_SIZE 16 // Intel recommended for best performance. #else diff --git a/lib/output.c b/lib/output.c index 81d1d5c..059fbaa 100644 --- a/lib/output.c +++ b/lib/output.c @@ -128,7 +128,7 @@ int lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len) */ lws_latency_pre(context, wsi); n = lws_ssl_capable_write(wsi, buf, len); - lws_latency(context, wsi, "send lws_issue_raw", n, n == len); + lws_latency(context, wsi, "send lws_issue_raw", n, (unsigned int)n == len); switch (n) { case LWS_SSL_CAPABLE_ERROR: @@ -167,7 +167,7 @@ handle_truncated_send: return n; } - if (n == real_len) + if ((unsigned int)n == real_len) /* what we just sent went out cleanly */ return n; @@ -498,7 +498,7 @@ send_raw: if (n <= 0) return n; - if (n == len + pre + post) { + if (n == (int)len + pre + post) { /* everything in the buffer was handled (or rebuffered...) */ wsi->u.ws.inside_frame = 0; return orig_len; @@ -583,6 +583,8 @@ lws_ssl_capable_read_no_ssl(struct libwebsocket_context *context, { int n; + (void)context; + n = recv(wsi->sock, (char *)buf, len, 0); if (n >= 0) return n; @@ -620,5 +622,6 @@ lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int l LWS_VISIBLE int lws_ssl_pending_no_ssl(struct libwebsocket *wsi) { + (void)wsi; return 0; } diff --git a/lib/parsers.c b/lib/parsers.c index b660b38..2330a2a 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -210,7 +210,7 @@ int libwebsocket_parse( WSI_TOKEN_PATCH_URI, WSI_TOKEN_DELETE_URI, }; - int n, m; + unsigned int n, m; switch (wsi->u.hdr.parser_state) { default: @@ -387,7 +387,7 @@ check_eol: } n = issue_char(wsi, c); - if (n < 0) + if ((int)n < 0) return -1; if (n > 0) wsi->u.hdr.parser_state = WSI_TOKEN_SKIPPING; diff --git a/lib/pollfd.c b/lib/pollfd.c index 04e2e4d..80cb2ea 100644 --- a/lib/pollfd.c +++ b/lib/pollfd.c @@ -32,7 +32,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context, return 1; } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(MBED_OPERATORS) if (wsi->sock >= context->max_fds) { lwsl_err("Socket fd %d is too high (%d)\n", wsi->sock, context->max_fds); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index ece8380..57578f2 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -149,9 +149,15 @@ #define compatible_file_read(amount, fd, buf, len) \ amount = read(fd, buf, len); #define lws_set_blocking_send(wsi) + +#ifdef MBED_OPERATORS +#define lws_socket_is_valid(x) ((x) != NULL) +#define LWS_SOCK_INVALID (NULL) +#else #define lws_socket_is_valid(x) (x >= 0) #define LWS_SOCK_INVALID (-1) #endif +#endif #ifndef LWS_HAVE_BZERO #ifndef bzero @@ -619,8 +625,8 @@ struct _lws_http_mode_related { enum http_version request_version; enum http_connection_type connection_type; - int content_length; - int content_remain; + unsigned int content_length; + unsigned int content_remain; }; @@ -790,7 +796,7 @@ struct _lws_header_related { struct _lws_websocket_related { char *rx_user_buffer; - int rx_user_buffer_head; + unsigned int rx_user_buffer_head; unsigned char frame_masking_nonce_04[4]; unsigned char frame_mask_index; size_t rx_packet_length; @@ -901,9 +907,9 @@ lws_rxflow_cache(struct libwebsocket *wsi, unsigned char *buf, int n, int len); #ifndef LWS_LATENCY static inline void lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi, const char *action, - int ret, int completion) { do { } while (0); } + int ret, int completion) { do { (void)context; (void)wsi; (void)action; (void)ret; (void)completion; } while (0); } static inline void lws_latency_pre(struct libwebsocket_context *context, - struct libwebsocket *wsi) { do { } while (0); } + struct libwebsocket *wsi) { do { (void)context; (void)wsi; } while (0); } #else #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0) extern void @@ -928,7 +934,7 @@ lws_http_action(struct libwebsocket_context *context, struct libwebsocket *wsi); LWS_EXTERN int lws_b64_selftest(void); -#ifdef _WIN32 +#if defined(_WIN32) || defined(MBED_OPERATORS) LWS_EXTERN struct libwebsocket * wsi_from_fd(struct libwebsocket_context *context, lws_sockfd_type fd); @@ -1111,9 +1117,10 @@ LWS_EXTERN int get_daemonize_pid(); #define get_daemonize_pid() (0) #endif +#if !defined(MBED_OPERATORS) LWS_EXTERN int interface_to_sa(struct libwebsocket_context *context, const char *ifname, struct sockaddr_in *addr, size_t addrlen); - +#endif LWS_EXTERN void lwsl_emit_stderr(int level, const char *line); #ifdef _WIN32 diff --git a/lib/server.c b/lib/server.c index 14acf2e..38e1925 100644 --- a/lib/server.c +++ b/lib/server.c @@ -27,15 +27,17 @@ int lws_context_init_server(struct lws_context_creation_info *info, { int n; lws_sockfd_type sockfd; +#if LWS_POSIX struct sockaddr_in sin; socklen_t len = sizeof(sin); - int opt = 1; - struct libwebsocket *wsi; #ifdef LWS_USE_IPV6 struct sockaddr_in6 serv_addr6; #endif struct sockaddr_in serv_addr4; struct sockaddr *v; +#endif + int opt = 1; + struct libwebsocket *wsi; /* set up our external listening socket we serve on */ @@ -182,7 +184,7 @@ int lws_http_action(struct libwebsocket_context *context, char content_length_str[32]; char http_version_str[10]; char http_conn_str[20]; - int n, count = 0; + unsigned int n, count = 0; static const unsigned char methods[] = { WSI_TOKEN_GET_URI, WSI_TOKEN_POST_URI, @@ -457,7 +459,7 @@ upgrade_ws: hit = 0; while (*p && !hit) { - n = 0; + unsigned int n = 0; while (n < sizeof(protocol_name) - 1 && *p && *p !=',') protocol_name[n++] = *p++; protocol_name[n] = '\0'; diff --git a/lib/service.c b/lib/service.c index 32e0902..120d6c5 100644 --- a/lib/service.c +++ b/lib/service.c @@ -297,7 +297,7 @@ libwebsocket_service_timeout_check(struct libwebsocket_context *context, * if we went beyond the allowed time, kill the * connection */ - if (sec > wsi->pending_timeout_limit) { + if ((time_t)sec > wsi->pending_timeout_limit) { lwsl_info("TIMEDOUT WAITING on %d\n", wsi->pending_timeout); /* * Since he failed a timeout, he already had a chance to do @@ -371,7 +371,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context, char draining_flow = 0; int more; struct lws_tokens eff_buf; - int pending = 0; + unsigned int pending = 0; if (context->listen_service_fd) listen_socket_fds_index = wsi_from_fd(context,context->listen_service_fd)->position_in_fds_table; -- 2.7.4