*
* Copyright (C) 2016 Adam <Adam@anope.org>
* Copyright (C) 2015 Daniel Vassdal <shutter@canternet.org>
- * Copyright (C) 2013, 2016-2019 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2013, 2016-2020 Sadie Powell <sadie@witchery.services>
* Copyright (C) 2012-2015 Attila Molnar <attilamolnar@hush.com>
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
* Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
* Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
* Copyright (C) 2007, 2009-2010 Craig Edwards <brain@inspircd.org>
+ * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
* Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
- * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
* Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
, qinprog(NULL, "")
{
if (!DoConnect())
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "WARNING: Could not connect to database " + tag->getString("id"));
DelayReconnect();
- }
}
CullResult cull() CXX11_OVERRIDE
return conninfo.str();
}
+ bool HandleConnectError(const char* reason)
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Could not connect to the \"%s\" database: %s",
+ GetId().c_str(), reason);
+ return false;
+ }
+
bool DoConnect()
{
sql = PQconnectStart(GetDSN().c_str());
if (!sql)
- return false;
+ return HandleConnectError("PQconnectStart returned NULL");
if(PQstatus(sql) == CONNECTION_BAD)
- return false;
+ return HandleConnectError("connection status is bad");
if(PQsetnonblocking(sql, 1) == -1)
- return false;
+ return HandleConnectError("unable to mark fd as non-blocking");
/* OK, we've initialised the connection, now to get it hooked into the socket engine
* and then start polling it.
*/
- this->fd = PQsocket(sql);
-
- if(this->fd <= -1)
- return false;
+ SetFd(PQsocket(sql));
+ if(!HasFd())
+ return HandleConnectError("PQsocket returned an invalid fd");
if (!SocketEngine::AddFd(this, FD_WANT_NO_WRITE | FD_WANT_NO_READ))
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "BUG: Couldn't add pgsql socket to socket engine");
- return false;
- }
+ return HandleConnectError("could not add the pgsql socket to the socket engine");
/* Socket all hooked into the engine, now to tell PgSQL to start connecting */
- return DoPoll();
+ if (!DoPoll())
+ return HandleConnectError("could not poll the connection state");
+
+ return true;
}
bool DoPoll()