]> git.tdb.fi Git - libs/net.git/commitdiff
Use nullptr instead of 0 for pointers
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 22:14:38 +0000 (00:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 22:14:38 +0000 (00:14 +0200)
12 files changed:
source/http/client.cpp
source/http/client.h
source/http/server.cpp
source/http/server.h
source/net/clientsocket.cpp
source/net/clientsocket.h
source/net/communicator.h
source/net/resolve.cpp
source/net/resolve.h
source/net/socket.cpp
source/net/socket.h
source/net/streamsocket.cpp

index 073656d184440aa225ca2774f5f98e2dafd8374b..30c336e3e1bf627867d7e4a75ffd3d7a763f352a 100644 (file)
@@ -32,7 +32,7 @@ void Client::use_resolver(Net::Resolver *r)
        if(resolver)
        {
                delete resolve_listener;
-               resolve_listener = 0;
+               resolve_listener = nullptr;
        }
 
        resolver = r;
@@ -46,14 +46,14 @@ void Client::start_request(const Request &r)
                throw invalid_state("already processing a request");
 
        delete sock;
-       sock = 0;
+       sock = nullptr;
 
        request = new Request(r);
        if(!user_agent.empty())
                request->set_header("User-Agent", user_agent);
 
        delete response;
-       response = 0;
+       response = nullptr;
        in_buf.clear();
 
        string host = r.get_header("Host");
@@ -88,9 +88,9 @@ void Client::tick()
                signal_response_complete.emit(*response);
 
                delete sock;
-               sock = 0;
+               sock = nullptr;
                delete request;
-               request = 0;
+               request = nullptr;
        }
 }
 
@@ -103,9 +103,9 @@ void Client::wait_response()
 void Client::abort()
 {
        delete sock;
-       sock = 0;
+       sock = nullptr;
        delete request;
-       request = 0;
+       request = nullptr;
 }
 
 void Client::address_resolved(unsigned tag, const Net::SockAddr &addr)
@@ -132,7 +132,7 @@ void Client::resolve_failed(unsigned tag, const exception &err)
        resolve_tag = 0;
 
        delete request;
-       request = 0;
+       request = nullptr;
 
        if(signal_socket_error.empty())
                throw err;
@@ -144,7 +144,7 @@ void Client::connect_finished(const exception *err)
        if(err)
        {
                delete request;
-               request = 0;
+               request = nullptr;
 
                if(signal_socket_error.empty())
                        throw *err;
@@ -206,7 +206,7 @@ void Client::data_available()
                signal_response_complete.emit(*response);
 
                delete request;
-               request = 0;
+               request = nullptr;
        }
 }
 
index c88ce32df2cd62b55f4c41a66db66e6295470d4b..2012498e67c79d5b6d86772993c3af48a64f169a 100644 (file)
@@ -30,14 +30,14 @@ private:
                void resolve_failed(unsigned, const std::exception &);
        };
 
-       Net::StreamSocket *sock = 0;
-       IO::EventDispatcher *event_disp = 0;
-       Net::Resolver *resolver = 0;
-       ResolveListener *resolve_listener = 0;
+       Net::StreamSocket *sock = nullptr;
+       IO::EventDispatcher *event_disp = nullptr;
+       Net::Resolver *resolver = nullptr;
+       ResolveListener *resolve_listener = nullptr;
        unsigned resolve_tag = 0;
        std::string user_agent = "libmspnet/1.0";
-       Request *request = 0;
-       Response *response = 0;
+       Request *request = nullptr;
+       Response *response = nullptr;
        std::string in_buf;
 
        Client(const Client &);
index 223f6c923e60f423b37c67fedb8cba1e6e38b877..a7435d330350b41e60416dbc3eb632d840b742ab 100644 (file)
@@ -192,7 +192,7 @@ void Server::client_data_available(Client &cl)
                        else
                        {
                                responses.erase(cl.response);
-                               cl.response = 0;
+                               cl.response = nullptr;
                                if(response->get_status()==NONE)
                                {
                                        response = new Response(NOT_FOUND);
@@ -203,7 +203,7 @@ void Server::client_data_available(Client &cl)
                catch(const exception &e)
                {
                        responses.erase(cl.response);
-                       cl.response = 0;
+                       cl.response = nullptr;
                        response = new Response(INTERNAL_ERROR);
                        response->add_content(format("An error occurred while processing the request:\ntype: %s\nwhat: %s",
                                Debug::demangle(typeid(e).name()), e.what()));
@@ -233,9 +233,9 @@ void Server::send_response(Client &cl, Response &resp)
        if(cl.keepalive)
        {
                delete cl.request;
-               cl.request = 0;
+               cl.request = nullptr;
                delete cl.response;
-               cl.response = 0;
+               cl.response = nullptr;
        }
        else
        {
index d55b774d961392af735f2381444ba4193de57d05..e6de22781d17077a8e26a66925231780de4c518d 100644 (file)
@@ -22,8 +22,8 @@ private:
        {
                RefPtr<Net::StreamSocket> sock;
                std::string in_buf;
-               Request *request = 0;
-               Response *response = 0;
+               Request *request = nullptr;
+               Response *response = nullptr;
                bool keepalive = false;
                bool async = false;
                bool stale = false;
@@ -35,7 +35,7 @@ private:
        Net::StreamServerSocket sock;
        std::list<Client> clients;
        std::map<Response *, Client *> responses;
-       IO::EventDispatcher *event_disp = 0;
+       IO::EventDispatcher *event_disp = nullptr;
 
 public:
        Server();
index c400f80e9848946a4c6bff0d8b980c86b156ad3a..89e2d082a65bddee2cdfd1f32334f2fb0f3a57bf 100644 (file)
@@ -51,7 +51,7 @@ void ClientSocket::shutdown(IO::Mode m)
 
 const SockAddr &ClientSocket::get_peer_address() const
 {
-       if(peer_addr==0)
+       if(!peer_addr)
                throw bad_socket_state("not connected");
        return *peer_addr;
 }
index 04065400ece8f9783be98a0def1016ec90a90e07..2359fd3c4500634ebd859feee2a20203af280c08 100644 (file)
@@ -18,7 +18,7 @@ public:
 protected:
        bool connecting = false;
        bool connected = false;
-       SockAddr *peer_addr = 0;
+       SockAddr *peer_addr = nullptr;
 
        ClientSocket(const Private &, const SockAddr &);
        ClientSocket(Family, int, int);
index 322d095a8ec3d1c1df5b258c25f65b3c88a713fa..822b16ef998dbd706d1ea1617950175d488496ca 100644 (file)
@@ -35,10 +35,10 @@ private:
        ReceiverBase &receiver;
        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;
+       char *in_buf = nullptr;
+       char *in_begin = nullptr;
+       char *in_end = nullptr;
+       char *out_buf = nullptr;
        bool good = true;
 
 public:
index fd59cbb37ddf1cea8f1377527645262300bd42be..e06bce77775e49fdd18569d12d79fec1f9739c0b 100644 (file)
@@ -40,16 +40,16 @@ namespace Net {
 
 SockAddr *resolve(const string &host, const string &serv, Family family)
 {
-       const char *chost = (host.empty() ? 0 : host.c_str());
-       const char *cserv = (serv.empty() ? 0 : serv.c_str());
+       const char *chost = (host.empty() ? nullptr : host.c_str());
+       const char *cserv = (serv.empty() ? nullptr : serv.c_str());
        int flags = 0;
        if(host=="*")
        {
                flags = AI_PASSIVE;
-               chost = 0;
+               chost = nullptr;
        }
 
-       addrinfo hints = { flags, family_to_sys(family), 0, 0, 0, 0, 0, 0 };
+       addrinfo hints = { flags, family_to_sys(family), 0, 0, 0, nullptr, nullptr, nullptr };
        addrinfo *res;
 
        int err = getaddrinfo(chost, cserv, &hints, &res);
@@ -134,7 +134,7 @@ void Resolver::task_done()
                        if(signal_resolve_failed.empty())
                        {
                                RefPtr<runtime_error> err = task->error;
-                               task->error = 0;
+                               task->error = nullptr;
                                thread.pop_complete_task();
                                throw *err;
                        }
@@ -174,7 +174,7 @@ Resolver::Task *Resolver::WorkerThread::get_complete_task()
        if(!queue.empty() && queue.front().is_complete())
                return &queue.front();
        else
-               return 0;
+               return nullptr;
 }
 
 void Resolver::WorkerThread::pop_complete_task()
@@ -197,7 +197,7 @@ void Resolver::WorkerThread::main()
                        sem.wait();
                wait = false;
 
-               Task *task = 0;
+               Task *task = nullptr;
                {
                        MutexLock lock(queue_mutex);
                        for(auto i=queue.begin(); (!task && i!=queue.end()); ++i)
index 6a0479e6aa363f2b22a49b5e1b999860a7666417..65d1db89977425ff6fc7079b83aef60ba74d680b 100644 (file)
@@ -40,8 +40,8 @@ private:
                std::string host;
                std::string serv;
                Family family = UNSPEC;
-               SockAddr *addr = 0;
-               std::runtime_error *error = 0;
+               SockAddr *addr = nullptr;
+               std::runtime_error *error = nullptr;
 
                bool is_complete() const { return addr || error; }
        };
@@ -74,7 +74,7 @@ public:
        sigc::signal<void, unsigned, const std::exception &> signal_resolve_failed;
 
 private:
-       IO::EventDispatcher *event_disp = 0;
+       IO::EventDispatcher *event_disp = nullptr;
        WorkerThread thread;
        unsigned next_tag = 1;
 
index a983a2ec2a6e115c11a5e731b885645cfcbbfcff..67bd38137dbe58eba6d76c51df553d90b4f0d3e3 100644 (file)
@@ -80,7 +80,7 @@ void Socket::bind(const SockAddr &addr)
 
 const SockAddr &Socket::get_local_address() const
 {
-       if(local_addr==0)
+       if(!local_addr)
                throw bad_socket_state("not bound");
        return *local_addr;
 }
index 6e0a497a08d855db1fcb506dc9c91ebfb2eb9a50..c675ab5801766635e93fbb8a6bbead4497820635 100644 (file)
@@ -30,8 +30,8 @@ protected:
 
        struct Private;
 
-       Private *priv = 0;
-       SockAddr *local_addr = 0;
+       Private *priv = nullptr;
+       SockAddr *local_addr = nullptr;
 
        Socket(const Private &);
        Socket(Family, int, int);
index 11887d398c4b09a894c088fb4b3656cd49bf8c45..c8eb1c488ac365d6471469ca59ffc2b034c78b45 100644 (file)
@@ -101,7 +101,7 @@ void StreamSocket::on_event(IO::PollEvent ev)
                if(err!=0)
                {
                        delete peer_addr;
-                       peer_addr = 0;
+                       peer_addr = nullptr;
                }
 
                set_socket_events((err==0) ? S_INPUT : S_NONE);