summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-09-09 08:32:46 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-09-09 08:32:46 +0000
commitb6497f2715d1df8ccc1461caa52ec600490e44b3 (patch)
tree46346fe112aba373ec64021adcfeef589e551477
parent27fec307cf7581130563cc09389a2b2c79bc53b9 (diff)
not test compiled yet: sql modules werent working because someone chopped out the important code that determines what port the new socket is bound to when binding to port "0". The GetPort() method belongs in the listensocketbase derived socket not the bufferedsocket one, and the code for determining the getsockname() belongs in the ctor for the listen derived socket.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10482 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/extra/m_mysql.cpp35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index be7166f13..ae66e44bb 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -661,23 +661,11 @@ class DispatcherThread : public Thread
*/
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;
@@ -714,15 +702,34 @@ class Notifier : public BufferedSocket
*/
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) { }
+ 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)
@@ -742,6 +749,8 @@ ModuleSQL::ModuleSQL(InspIRCd* Me) : Module(Me), rehashing(false)
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);