From: Mikko Rasa Date: Sat, 10 Dec 2022 22:14:38 +0000 (+0200) Subject: Use nullptr instead of 0 for pointers X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3ab65d35cfd696002e09768a38f98e6a2e1ade81;p=libs%2Fnet.git Use nullptr instead of 0 for pointers --- diff --git a/source/http/client.cpp b/source/http/client.cpp index 073656d..30c336e 100644 --- a/source/http/client.cpp +++ b/source/http/client.cpp @@ -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; } } diff --git a/source/http/client.h b/source/http/client.h index c88ce32..2012498 100644 --- a/source/http/client.h +++ b/source/http/client.h @@ -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 &); diff --git a/source/http/server.cpp b/source/http/server.cpp index 223f6c9..a7435d3 100644 --- a/source/http/server.cpp +++ b/source/http/server.cpp @@ -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 { diff --git a/source/http/server.h b/source/http/server.h index d55b774..e6de227 100644 --- a/source/http/server.h +++ b/source/http/server.h @@ -22,8 +22,8 @@ private: { RefPtr 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 clients; std::map responses; - IO::EventDispatcher *event_disp = 0; + IO::EventDispatcher *event_disp = nullptr; public: Server(); diff --git a/source/net/clientsocket.cpp b/source/net/clientsocket.cpp index c400f80..89e2d08 100644 --- a/source/net/clientsocket.cpp +++ b/source/net/clientsocket.cpp @@ -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; } diff --git a/source/net/clientsocket.h b/source/net/clientsocket.h index 0406540..2359fd3 100644 --- a/source/net/clientsocket.h +++ b/source/net/clientsocket.h @@ -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); diff --git a/source/net/communicator.h b/source/net/communicator.h index 322d095..822b16e 100644 --- a/source/net/communicator.h +++ b/source/net/communicator.h @@ -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: diff --git a/source/net/resolve.cpp b/source/net/resolve.cpp index fd59cbb..e06bce7 100644 --- a/source/net/resolve.cpp +++ b/source/net/resolve.cpp @@ -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 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) diff --git a/source/net/resolve.h b/source/net/resolve.h index 6a0479e..65d1db8 100644 --- a/source/net/resolve.h +++ b/source/net/resolve.h @@ -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 signal_resolve_failed; private: - IO::EventDispatcher *event_disp = 0; + IO::EventDispatcher *event_disp = nullptr; WorkerThread thread; unsigned next_tag = 1; diff --git a/source/net/socket.cpp b/source/net/socket.cpp index a983a2e..67bd381 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -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; } diff --git a/source/net/socket.h b/source/net/socket.h index 6e0a497..c675ab5 100644 --- a/source/net/socket.h +++ b/source/net/socket.h @@ -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); diff --git a/source/net/streamsocket.cpp b/source/net/streamsocket.cpp index 11887d3..c8eb1c4 100644 --- a/source/net/streamsocket.cpp +++ b/source/net/streamsocket.cpp @@ -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);