]> git.tdb.fi Git - libs/net.git/commitdiff
Use default member initializers where possible
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 00:15:40 +0000 (02:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 00:52:48 +0000 (02:52 +0200)
28 files changed:
source/http/client.cpp
source/http/client.h
source/http/message.cpp
source/http/message.h
source/http/server.cpp
source/http/server.h
source/net/clientsocket.cpp
source/net/clientsocket.h
source/net/communicator.cpp
source/net/communicator.h
source/net/inet.cpp
source/net/inet.h
source/net/inet6.cpp
source/net/inet6.h
source/net/protocol.cpp
source/net/protocol.h
source/net/resolve.cpp
source/net/resolve.h
source/net/sockaddr.cpp
source/net/sockaddr_private.h
source/net/socket.cpp
source/net/socket.h
source/net/streamserversocket.cpp
source/net/streamserversocket.h
source/net/unix.cpp
source/net/unix.h
source/net/unix/unix.cpp
source/net/windows/unix.cpp

index 705f4cb7bbd0a7e09dcdbcde3dc979e9bf0cae86..073656d184440aa225ca2774f5f98e2dafd8374b 100644 (file)
@@ -11,17 +11,6 @@ using namespace std;
 namespace Msp {
 namespace Http {
 
-Client::Client():
-       sock(0),
-       event_disp(0),
-       resolver(0),
-       resolve_listener(0),
-       resolve_tag(0),
-       user_agent("libmsphttp/0.1"),
-       request(0),
-       response(0)
-{ }
-
 Client::~Client()
 {
        delete sock;
index e0b9b64f097b62c563480e0f879b2985cb5523c2..c88ce32df2cd62b55f4c41a66db66e6295470d4b 100644 (file)
@@ -30,20 +30,19 @@ private:
                void resolve_failed(unsigned, const std::exception &);
        };
 
-       Net::StreamSocket *sock;
-       IO::EventDispatcher *event_disp;
-       Net::Resolver *resolver;
-       ResolveListener *resolve_listener;
-       unsigned resolve_tag;
-       std::string user_agent;
-       Request *request;
-       Response *response;
+       Net::StreamSocket *sock = 0;
+       IO::EventDispatcher *event_disp = 0;
+       Net::Resolver *resolver = 0;
+       ResolveListener *resolve_listener = 0;
+       unsigned resolve_tag = 0;
+       std::string user_agent = "libmspnet/1.0";
+       Request *request = 0;
+       Response *response = 0;
        std::string in_buf;
 
        Client(const Client &);
        Client &operator=(const Client &);
 public:
-       Client();
        ~Client();
 
        void use_event_dispatcher(IO::EventDispatcher *);
index 99d149725c80db88f5c534547369da8ddac90401..4f17017823df937f152f2f2e56780fa420c0ad98 100644 (file)
@@ -9,12 +9,6 @@ using namespace std;
 namespace Msp {
 namespace Http {
 
-Message::Message():
-       http_version(0x11),
-       chunk_length(0),
-       complete(false)
-{ }
-
 void Message::set_header(const string &hdr, const string &val)
 {
        headers[normalize_header_name(hdr)] = val;
index 7acce90d146dffa356adb885ba0449c13e4c6b9e..7984372328fab20af5cb78b9327947a69235aadb 100644 (file)
@@ -14,14 +14,14 @@ class Message
 protected:
        typedef std::map<std::string, std::string> HeaderMap;
 
-       Version http_version;
+       Version http_version = 0x11;
        HeaderMap headers;
        std::string content;
-       std::string::size_type chunk_length;
-       bool complete;
+       std::string::size_type chunk_length = 0;
+       bool complete = false;
        Variant user_data;
 
-       Message();
+       Message() = default;
 public:
        virtual ~Message() = default;
 
index c52bec4e7e89a2b3a703a657eecc88b102407788..223f6c923e60f423b37c67fedb8cba1e6e38b877 100644 (file)
@@ -18,13 +18,11 @@ namespace Msp {
 namespace Http {
 
 Server::Server():
-       sock(Net::INET6),
-       event_disp(0)
+       sock(Net::INET6)
 { }
 
 Server::Server(unsigned port):
-       sock(Net::INET6),
-       event_disp(0)
+       sock(Net::INET6)
 {
        listen(port);
 }
@@ -258,12 +256,7 @@ Server::Client &Server::get_client_by_response(Response &resp)
 
 
 Server::Client::Client(RefPtr<Net::StreamSocket> s):
-       sock(s),
-       request(0),
-       response(0),
-       keepalive(false),
-       async(false),
-       stale(false)
+       sock(s)
 { }
 
 Server::Client::~Client()
index 4835de039c87b46781499a52e54cb901782b5188..d55b774d961392af735f2381444ba4193de57d05 100644 (file)
@@ -22,11 +22,11 @@ private:
        {
                RefPtr<Net::StreamSocket> sock;
                std::string in_buf;
-               Request *request;
-               Response *response;
-               bool keepalive;
-               bool async;
-               bool stale;
+               Request *request = 0;
+               Response *response = 0;
+               bool keepalive = false;
+               bool async = false;
+               bool stale = false;
 
                Client(RefPtr<Net::StreamSocket>);
                ~Client();
@@ -35,7 +35,7 @@ private:
        Net::StreamServerSocket sock;
        std::list<Client> clients;
        std::map<Response *, Client *> responses;
-       IO::EventDispatcher *event_disp;
+       IO::EventDispatcher *event_disp = 0;
 
 public:
        Server();
index 9cabeef9c7714b7f743bf350b37c067d739714a2..c400f80e9848946a4c6bff0d8b980c86b156ad3a 100644 (file)
@@ -7,15 +7,11 @@ namespace Msp {
 namespace Net {
 
 ClientSocket::ClientSocket(Family af, int type, int proto):
-       Socket(af, type, proto),
-       connecting(false),
-       connected(false),
-       peer_addr(0)
+       Socket(af, type, proto)
 { }
 
 ClientSocket::ClientSocket(const Private &p, const SockAddr &paddr):
        Socket(p),
-       connecting(false),
        connected(true),
        peer_addr(paddr.copy())
 { }
index 672c32bc98fca3f570d7b3b31948debcb2f434f4..04065400ece8f9783be98a0def1016ec90a90e07 100644 (file)
@@ -16,9 +16,9 @@ public:
        sigc::signal<void, const std::exception *> signal_connect_finished;
 
 protected:
-       bool connecting;
-       bool connected;
-       SockAddr *peer_addr;
+       bool connecting = false;
+       bool connected = false;
+       SockAddr *peer_addr = 0;
 
        ClientSocket(const Private &, const SockAddr &);
        ClientSocket(Family, int, int);
index 05ef0ea86e0f4e9a6f6710864537a800e61ff663..f77ada2159d427788a74a414285aaa67a3ad1ee4 100644 (file)
@@ -30,18 +30,13 @@ HandshakeProtocol::HandshakeProtocol():
 class HandshakeReceiver: public PacketReceiver<Handshake>
 {
 private:
-       uint64_t hash;
+       uint64_t hash = 0;
 
 public:
-       HandshakeReceiver();
        uint64_t get_hash() const { return hash; }
        void receive(const Handshake &) override;
 };
 
-HandshakeReceiver::HandshakeReceiver():
-       hash(0)
-{ }
-
 void HandshakeReceiver::receive(const Handshake &shake)
 {
        hash = shake.hash;
@@ -57,13 +52,10 @@ Communicator::Communicator(StreamSocket &s, const Protocol &p, ReceiverBase &r):
        socket(s),
        protocol(p),
        receiver(r),
-       handshake_status(0),
-       buf_size(65536),
        in_buf(new char[buf_size]),
        in_begin(in_buf),
        in_end(in_buf),
-       out_buf(new char[buf_size]),
-       good(true)
+       out_buf(new char[buf_size])
 {
        socket.signal_data_available.connect(sigc::mem_fun(this, &Communicator::data_available));
 }
index 575ec84e6c3a0f2be7ea77039041a52b919c069d..322d095a8ec3d1c1df5b258c25f65b3c88a713fa 100644 (file)
@@ -33,13 +33,13 @@ private:
        StreamSocket &socket;
        const Protocol &protocol;
        ReceiverBase &receiver;
-       int handshake_status;
-       std::size_t buf_size;
-       char *in_buf;
-       char *in_begin;
-       char *in_end;
-       char *out_buf;
-       bool good;
+       int handshake_status = 0;
+       std::size_t buf_size = 65536;
+       char *in_buf = 0;
+       char *in_begin = 0;
+       char *in_end = 0;
+       char *out_buf = 0;
+       bool good = true;
 
 public:
        Communicator(StreamSocket &, const Protocol &, ReceiverBase &);
index 8e75cd89dfb1eb930b3e55a0217a93e42ab03e15..dbbd12d7e5e7e65cb5292a1c5b04592b29cf4c4f 100644 (file)
@@ -8,12 +8,6 @@ using namespace std;
 namespace Msp {
 namespace Net {
 
-InetAddr::InetAddr():
-       port(0)
-{
-       fill(addr, addr+4, 0);
-}
-
 InetAddr::InetAddr(const SysAddr &sa)
 {
        const sockaddr_in &sai = reinterpret_cast<const sockaddr_in &>(sa.addr);
index 67bb6100b66005191d923d3a4210a9ea82d4cd79..517b111b42a71e386ca1c692293f1632733006f8 100644 (file)
@@ -12,11 +12,11 @@ Address class for IPv4 sockets.
 class InetAddr: public SockAddr
 {
 private:
-       unsigned char addr[4];
-       unsigned port;
+       unsigned char addr[4] = { };
+       unsigned port = 0;
 
 public:
-       InetAddr();
+       InetAddr() = default;
        InetAddr(const SysAddr &);
 
        InetAddr *copy() const override { return new InetAddr(*this); }
index 77d757082379f70e713d7587bbf0d61df675ff75..8ddf1d5cb52248e771dc3e602f75c45f6de16700 100644 (file)
@@ -8,12 +8,6 @@ using namespace std;
 namespace Msp {
 namespace Net {
 
-Inet6Addr::Inet6Addr():
-       port(0)
-{
-       fill(addr, addr+16, 0);
-}
-
 Inet6Addr::Inet6Addr(const SysAddr &sa)
 {
        const sockaddr_in6 &sai6 = reinterpret_cast<const sockaddr_in6 &>(sa.addr);
index fb07eec52e2d2ff14dcaa551fff7eef38468a840..3b48a63fe089dc6733b722cd2c04f33f01adb325 100644 (file)
@@ -9,11 +9,11 @@ namespace Net {
 class Inet6Addr: public SockAddr
 {
 private:
-       unsigned char addr[16];
-       unsigned port;
+       unsigned char addr[16] = { };
+       unsigned port = 0;
 
 public:
-       Inet6Addr();
+       Inet6Addr() = default;
        Inet6Addr(const SysAddr &);
 
        Inet6Addr *copy() const override { return new Inet6Addr(*this); }
index 81e9d142a56f93615152a9bfb7b5040ffe05b8ab..bcad032b4cb4fcc86a9de9702312806bf640b3b3 100644 (file)
@@ -166,11 +166,6 @@ Protocol::PacketDefBase::PacketDefBase(unsigned i):
 { }
 
 
-Protocol::PacketHeader::PacketHeader():
-       type(0),
-       length(0)
-{ }
-
 Protocol::PacketHeader::PacketHeader(uint16_t t, uint16_t l):
        type(t),
        length(l)
index e867c0a167af9e6c58441788eea3961a0d8b7679..6d15a330295a0592b3e921d7737cde6cf515507d 100644 (file)
@@ -213,10 +213,10 @@ private:
 
        struct PacketHeader
        {
-               std::uint16_t type;
-               std::uint16_t length;
+               std::uint16_t type = 0;
+               std::uint16_t length = 0;
 
-               PacketHeader();
+               PacketHeader() = default;
                PacketHeader(std::uint16_t, std::uint16_t);
        };
 
index c30d62a7bd9f471f1d621477d5f3536fc39e4adf..fd59cbb37ddf1cea8f1377527645262300bd42be 100644 (file)
@@ -81,9 +81,7 @@ SockAddr *resolve(const string &str, Family family)
 }
 
 
-Resolver::Resolver():
-       event_disp(0),
-       next_tag(1)
+Resolver::Resolver()
 {
        thread.get_notify_pipe().signal_data_available.connect(sigc::mem_fun(this, &Resolver::task_done));
 }
@@ -147,18 +145,9 @@ void Resolver::task_done()
 }
 
 
-Resolver::Task::Task():
-       tag(0),
-       family(UNSPEC),
-       addr(0),
-       error(0)
-{ }
-
-
 Resolver::WorkerThread::WorkerThread():
        Thread("Resolver"),
-       sem(1),
-       done(false)
+       sem(1)
 {
        launch();
 }
index b006aff9986b7c5cf51ea5638fdcca6b53693e27..6a0479e6aa363f2b22a49b5e1b999860a7666417 100644 (file)
@@ -36,14 +36,12 @@ class Resolver
 private:
        struct Task
        {
-               unsigned tag;
+               unsigned tag = 0;
                std::string host;
                std::string serv;
-               Family family;
-               SockAddr *addr;
-               std::runtime_error *error;
-
-               Task();
+               Family family = UNSPEC;
+               SockAddr *addr = 0;
+               std::runtime_error *error = 0;
 
                bool is_complete() const { return addr || error; }
        };
@@ -55,7 +53,7 @@ private:
                Mutex queue_mutex;
                Semaphore sem;
                IO::Pipe notify_pipe;
-               bool done;
+               bool done = false;
 
        public:
                WorkerThread();
@@ -76,9 +74,9 @@ public:
        sigc::signal<void, unsigned, const std::exception &> signal_resolve_failed;
 
 private:
-       IO::EventDispatcher *event_disp;
+       IO::EventDispatcher *event_disp = 0;
        WorkerThread thread;
-       unsigned next_tag;
+       unsigned next_tag = 1;
 
 public:
        Resolver();
index db436fe17227218e193e71f7ad28b18cfac4cab0..36e9c6882542eebc92f0e8edb3dc8e37255e8338 100644 (file)
@@ -25,8 +25,7 @@ SockAddr *SockAddr::new_from_sys(const SysAddr &sa)
        }
 }
 
-SockAddr::SysAddr::SysAddr():
-       size(sizeof(sockaddr_storage))
+SockAddr::SysAddr::SysAddr()
 {
        addr.ss_family = AF_UNSPEC;
 }
index 909ef9255853e6a65f9669a8d688c1b75dba45de..5fca4102188c8fe89d547cbdc417bcf85f0dafe6 100644 (file)
@@ -14,7 +14,7 @@ namespace Net {
 struct SockAddr::SysAddr
 {
        struct sockaddr_storage addr;
-       socklen_t size;
+       socklen_t size = sizeof(sockaddr_storage);
 
        SysAddr();
 };
index 9fd468ef84111175c620dc216932c1c387bbac26..a983a2ec2a6e115c11a5e731b885645cfcbbfcff 100644 (file)
@@ -11,8 +11,7 @@ namespace Msp {
 namespace Net {
 
 Socket::Socket(const Private &p):
-       priv(new Private),
-       local_addr(0)
+       priv(new Private)
 {
        mode = IO::M_RDWR;
 
@@ -26,8 +25,7 @@ Socket::Socket(const Private &p):
 }
 
 Socket::Socket(Family af, int type, int proto):
-       priv(new Private),
-       local_addr(0)
+       priv(new Private)
 {
        mode = IO::M_RDWR;
 
index d917bd8e37e9d1b9a7d81adbfbc98053d6738406..6e0a497a08d855db1fcb506dc9c91ebfb2eb9a50 100644 (file)
@@ -30,8 +30,8 @@ protected:
 
        struct Private;
 
-       Private *priv;
-       SockAddr *local_addr;
+       Private *priv = 0;
+       SockAddr *local_addr = 0;
 
        Socket(const Private &);
        Socket(Family, int, int);
index 9b583a141da552d420908826357528eb5b5b7cce..b91491dcdd542e034ef6c35e3e00379abe019f7c 100644 (file)
@@ -14,8 +14,7 @@ namespace Msp {
 namespace Net {
 
 StreamServerSocket::StreamServerSocket(Family af, int proto):
-       ServerSocket(af, SOCK_STREAM, proto),
-       listening(false)
+       ServerSocket(af, SOCK_STREAM, proto)
 { }
 
 void StreamServerSocket::listen(const SockAddr &addr, unsigned backlog)
index d38c2eb9c06851f3c48c9819ed70579742b5e477..bd2487de430e3bca5820497c5238b65d38db2a8b 100644 (file)
@@ -10,7 +10,7 @@ namespace Net {
 class StreamServerSocket: public ServerSocket
 {
 private:
-       bool listening;
+       bool listening = false;
 
 public:
        StreamServerSocket(Family, int = 0);
index fe00020988bf92c1b915b7e6a7ef399ad7e9c4af..1da822b2da03be2a7dc8ad976ec2e82816d13a5a 100644 (file)
@@ -5,11 +5,6 @@ using namespace std;
 namespace Msp {
 namespace Net {
 
-UnixAddr::UnixAddr():
-       abstract(false)
-{
-}
-
 string UnixAddr::str() const
 {
        string result = "unix:";
index ec65164fbd0372ca62a8ea4bd28a25729403a099..a7431a9c17f99a03bbc14b5f482b671b40d491b4 100644 (file)
@@ -10,10 +10,10 @@ class UnixAddr: public SockAddr
 {
 private:
        std::string path;
-       bool abstract;
+       bool abstract = false;
 
 public:
-       UnixAddr();
+       UnixAddr() = default;
        UnixAddr(const SysAddr &);
        UnixAddr(const std::string &, bool = false);
 
index 0e88c2c2d0bc6cf1afe1f19af7f84f3ef6587690..eba7fb6425fa36acf825126bd73310586f6db373 100644 (file)
@@ -9,8 +9,7 @@ using namespace std;
 namespace Msp {
 namespace Net {
 
-UnixAddr::UnixAddr(const SysAddr &sa):
-       abstract(false)
+UnixAddr::UnixAddr(const SysAddr &sa)
 {
        const sockaddr_un &sau = reinterpret_cast<const sockaddr_un &>(sa.addr);
        if(static_cast<size_t>(sa.size)>sizeof(sa_family_t))
index 052710e8363eaa932962c82ab7ee22269aeebbb0..6a56ee0b8357a68b4a5851ac40107d9172672a4a 100644 (file)
@@ -8,8 +8,7 @@ using namespace std;
 namespace Msp {
 namespace Net {
 
-UnixAddr::UnixAddr(const SysAddr &):
-       abstract(false)
+UnixAddr::UnixAddr(const SysAddr &)
 {
        throw unsupported("AF_UNIX");
 }