From 5da560b79af3c807bc8cc9a950933e109e0e131c Mon Sep 17 00:00:00 2001 From: john30 Date: Fri, 20 Mar 2015 23:01:06 +0100 Subject: [PATCH] less compiler warnings --- src/ebusd/main.cpp | 2 +- src/ebusd/main.h | 3 ++- src/ebusd/network.cpp | 2 +- src/ebusd/network.h | 2 +- src/lib/ebus/device.cpp | 2 +- src/lib/utils/tcpsocket.cpp | 2 +- src/lib/utils/tcpsocket.h | 11 ++++++----- src/tools/ebusctl.cpp | 10 ++++++---- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index e60f4d43..c6515a12 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -257,7 +257,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) opt->foreground = true; break; case 'p': // --port=8888 - opt->port = parseInt(arg, 10, 1, 65535, result); + opt->port = (uint16_t)parseInt(arg, 10, 1, 65535, result); if (result != RESULT_OK) { argp_error(state, "invalid port"); return EINVAL; diff --git a/src/ebusd/main.h b/src/ebusd/main.h index 1bd5a7f5..098ee90d 100644 --- a/src/ebusd/main.h +++ b/src/ebusd/main.h @@ -23,6 +23,7 @@ #include "result.h" #include "data.h" #include "message.h" +#include /** \file main.h */ @@ -46,7 +47,7 @@ struct options bool generateSyn; //!< enable AUTO-SYN symbol generation bool foreground; //!< run in foreground - int port; //!< port to listen for client connections [8888] + uint16_t port; //!< port to listen for client connections [8888] bool localOnly; //!< listen on 127.0.0.1 interface only const char* logFile; //!< log file name [/var/log/ebusd.log] diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index 1c119730..ed285828 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -151,7 +151,7 @@ void Connection::run() } -Network::Network(const bool local, const int port, WQueue* netQueue) +Network::Network(const bool local, const uint16_t port, WQueue* netQueue) : m_netQueue(netQueue), m_listening(false) { if (local) diff --git a/src/ebusd/network.h b/src/ebusd/network.h index 875e3c42..50916b95 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -220,7 +220,7 @@ public: * @param port the tcp port to listening. * @param netQueue the remote queue for network messages. */ - Network(const bool local, const int port, WQueue* netQueue); + Network(const bool local, const uint16_t port, WQueue* netQueue); /** * destructor. diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index 37fd0fed..4f3ccd9f 100644 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -67,7 +67,7 @@ Device* Device::create(const char* name, const bool checkDevice, } free(host); address.sin_family = AF_INET; - address.sin_port = htons(port); + address.sin_port = htons((uint16_t)port); return new NetworkDevice(name, address, logRawFunc); } } diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index 06eadeaf..11a79750 100644 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -43,7 +43,7 @@ bool TCPSocket::isValid() } -TCPSocket* TCPClient::connect(const string& server, const int& port) +TCPSocket* TCPClient::connect(const string& server, const uint16_t& port) { struct sockaddr_in address; int ret; diff --git a/src/lib/utils/tcpsocket.h b/src/lib/utils/tcpsocket.h index 4d5ea42a..961fe199 100644 --- a/src/lib/utils/tcpsocket.h +++ b/src/lib/utils/tcpsocket.h @@ -24,6 +24,7 @@ #include #include #include +#include /** \file tcpsocket.h */ @@ -67,7 +68,7 @@ public: * returns the tcp port. * @return the tcp port. */ - int getPort() const { return m_port; } + uint16_t getPort() const { return m_port; } /** * returns the ip address. @@ -92,7 +93,7 @@ private: int m_sfd; /** port of tcp socket */ - int m_port; + uint16_t m_port; /** ip address of tcp socket */ string m_ip; @@ -119,7 +120,7 @@ public: * @param port the tcp port. * @return pointer to an opened tcp socket. */ - TCPSocket* connect(const string& server, const int& port); + TCPSocket* connect(const string& server, const uint16_t& port); }; @@ -135,7 +136,7 @@ public: * @param port the tcp port. * @param address the ip address. */ - TCPServer(const int port, const string address) + TCPServer(const uint16_t port, const string address) : m_lfd(0), m_port(port), m_address(address), m_listening(false) {} /** @@ -166,7 +167,7 @@ private: int m_lfd; /** listening tcp port */ - int m_port; + uint16_t m_port; /** listening tcp socket ip address */ string m_address; diff --git a/src/tools/ebusctl.cpp b/src/tools/ebusctl.cpp index 94ee51b8..750ec50c 100644 --- a/src/tools/ebusctl.cpp +++ b/src/tools/ebusctl.cpp @@ -40,7 +40,7 @@ using namespace std; struct options { const char* server; //!< ebusd server host (name or ip) [localhost] - unsigned int port; //!< ebusd server port [8888] + uint16_t port; //!< ebusd server port [8888] char* const *args; //!< arguments to pass to ebusd unsigned int argCount; //!< number of arguments to pass to ebusd @@ -90,6 +90,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) { struct options *opt = (struct options*)state->input; char* strEnd = NULL; + unsigned int port; switch (key) { // Device settings: case 's': // --server=localhost @@ -100,11 +101,12 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) opt->server = arg; break; case 'p': // --port=8888 - opt->port = (unsigned int)strtoul(arg, &strEnd, 10); - if (strEnd == NULL || *strEnd != 0 || opt->port < 1 || opt->port > 65535) { + port = strtoul(arg, &strEnd, 10); + if (strEnd == NULL || *strEnd != 0 || port < 1 || port > 65535) { argp_error(state, "invalid port"); return EINVAL; } + opt->port = (uint16_t)port; break; case ARGP_KEY_ARGS: opt->args = state->argv + state->next; @@ -230,7 +232,7 @@ string fetchData(TCPSocket* socket, bool& listening) return ss.str(); } -void connect(const char* host, int port, char* const *args, int argCount) +void connect(const char* host, uint16_t port, char* const *args, int argCount) { TCPClient* client = new TCPClient();