if(resolver)
{
delete resolve_listener;
- resolve_listener = 0;
+ resolve_listener = nullptr;
}
resolver = 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");
signal_response_complete.emit(*response);
delete sock;
- sock = 0;
+ sock = nullptr;
delete request;
- request = 0;
+ request = nullptr;
}
}
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)
resolve_tag = 0;
delete request;
- request = 0;
+ request = nullptr;
if(signal_socket_error.empty())
throw err;
if(err)
{
delete request;
- request = 0;
+ request = nullptr;
if(signal_socket_error.empty())
throw *err;
signal_response_complete.emit(*response);
delete request;
- request = 0;
+ request = nullptr;
}
}
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 &);
else
{
responses.erase(cl.response);
- cl.response = 0;
+ cl.response = nullptr;
if(response->get_status()==NONE)
{
response = new Response(NOT_FOUND);
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()));
if(cl.keepalive)
{
delete cl.request;
- cl.request = 0;
+ cl.request = nullptr;
delete cl.response;
- cl.response = 0;
+ cl.response = nullptr;
}
else
{
{
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;
Net::StreamServerSocket sock;
std::list<Client> clients;
std::map<Response *, Client *> responses;
- IO::EventDispatcher *event_disp = 0;
+ IO::EventDispatcher *event_disp = nullptr;
public:
Server();
const SockAddr &ClientSocket::get_peer_address() const
{
- if(peer_addr==0)
+ if(!peer_addr)
throw bad_socket_state("not connected");
return *peer_addr;
}
protected:
bool connecting = false;
bool connected = false;
- SockAddr *peer_addr = 0;
+ SockAddr *peer_addr = nullptr;
ClientSocket(const Private &, const SockAddr &);
ClientSocket(Family, int, int);
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:
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);
if(signal_resolve_failed.empty())
{
RefPtr<runtime_error> err = task->error;
- task->error = 0;
+ task->error = nullptr;
thread.pop_complete_task();
throw *err;
}
if(!queue.empty() && queue.front().is_complete())
return &queue.front();
else
- return 0;
+ return nullptr;
}
void Resolver::WorkerThread::pop_complete_task()
sem.wait();
wait = false;
- Task *task = 0;
+ Task *task = nullptr;
{
MutexLock lock(queue_mutex);
for(auto i=queue.begin(); (!task && i!=queue.end()); ++i)
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; }
};
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;
const SockAddr &Socket::get_local_address() const
{
- if(local_addr==0)
+ if(!local_addr)
throw bad_socket_state("not bound");
return *local_addr;
}
struct Private;
- Private *priv = 0;
- SockAddr *local_addr = 0;
+ Private *priv = nullptr;
+ SockAddr *local_addr = nullptr;
Socket(const Private &);
Socket(Family, int, int);
if(err!=0)
{
delete peer_addr;
- peer_addr = 0;
+ peer_addr = nullptr;
}
set_socket_events((err==0) ? S_INPUT : S_NONE);