class SQLConnection;
-class Notifier;
+class MySQLListener;
typedef std::map<std::string, SQLConnection*> ConnMap;
virtual void Run();
};
-/** Spawn HTTP sockets from a listener
- */
-class MySQLListener : public ListenSocketBase
-{
- FileReader* index;
-
- public:
- HttpListener(InspIRCd* Instance, int port, char* addr) : ListenSocketBase(Instance, port, addr)
- {
- this->index = idx;
- }
-
- virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip)
- {
- new Notifier(this->ServerInstance, nfd, (char)ipconnectedto.c_str()); // XXX unsafe casts suck
- }
-};
-
/** Used by m_mysql to notify one thread when the other has a result
*/
class Notifier : public BufferedSocket
{
- insp_sockaddr sock_us;
- socklen_t uslen;
ModuleSQL* Parent;
public:
Notifier(InspIRCd* SI, int newfd, char* ip) : BufferedSocket(SI, newfd, ip) { }
- /* Using getsockname and ntohs, we can determine which port number we were allocated */
- int GetPort()
- {
-#ifdef IPV6
- return ntohs(sock_us.sin6_port);
-#else
- return ntohs(sock_us.sin_port);
-#endif
- }
-
virtual bool OnDataReady()
{
char data = 0;
}
};
+/** Spawn sockets from a listener
+ */
+class MySQLListener : public ListenSocketBase
+{
+ insp_sockaddr sock_us;
+ socklen_t uslen;
+ FileReader* index;
+
+ public:
+ MySQLListener(InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr)
+ {
+ uslen = sizeof(sock_us);
+ if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
+ {
+ throw ModuleException("Could not getsockname() to find out port number for ITC port");
+ }
+ }
+
+ virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip)
+ {
+ new Notifier(this->ServerInstance, nfd, (char *)ipconnectedto.c_str()); // XXX unsafe casts suck
+ }
+
+ /* Using getsockname and ntohs, we can determine which port number we were allocated */
+ int GetPort()
+ {
+#ifdef IPV6
+ return ntohs(sock_us.sin6_port);
+#else
+ return ntohs(sock_us.sin_port);
+#endif
+ }
+};
ModuleSQL::ModuleSQL(InspIRCd* Me) : Module(Me), rehashing(false)
{
PublicServerInstance = ServerInstance;
currid = 0;
- MessagePipe = new Notifier(ServerInstance, this);
-
/* Create a socket on a random port. Let the tcp stack allocate us an available port */
#ifdef IPV6
- MessagePipe = new MySQLListener(SI, 0, "::1");
+ MessagePipe = new MySQLListener(ServerInstance, 0, "::1");
#else
- MessagePipe = new MySQLListener(SI, 0, "127.0.0.1");
+ MessagePipe = new MySQLListener(ServerInstance, 0, "127.0.0.1");
#endif
- if (MessagePipe->GetFd())
+ if (MessagePipe->GetFd() == -1)
throw ModuleException("m_mysql: unable to create ITC pipe");
+ else
+ ServerInstance->Logs->Log("m_mysql", DEBUG, "MySQL: Interthread comms port is %d", MessagePipe->GetPort());
Dispatcher = new DispatcherThread(ServerInstance, this);
ServerInstance->Threads->Create(Dispatcher);