+ResultNotifier* resultnotify = NULL;
+ResultNotifier* resultdispatch = NULL;
+int QueueFD = -1;
+
+class ResultNotifier : public BufferedSocket
+{
+ Module* mod;
+ insp_sockaddr sock_us;
+ socklen_t uslen;
+
+ public:
+ /* Create a socket on a random port. Let the tcp stack allocate us an available port */
+#ifdef IPV6
+ ResultNotifier(InspIRCd* SI, Module* m) : BufferedSocket(SI, "::1", 0, true, 3000), mod(m)
+#else
+ ResultNotifier(InspIRCd* SI, Module* m) : BufferedSocket(SI, "127.0.0.1", 0, true, 3000), mod(m)
+#endif
+ {
+ uslen = sizeof(sock_us);
+ if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
+ {
+ throw ModuleException("Could not create random listening port on localhost");
+ }
+ }
+
+ ResultNotifier(InspIRCd* SI, Module* m, int newfd, char* ip) : BufferedSocket(SI, newfd, ip), mod(m)
+ {
+ }
+
+ /* 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 int OnIncomingConnection(int newsock, char* ip)
+ {
+ resultdispatch = new ResultNotifier(Instance, mod, newsock, ip);
+ return true;
+ }
+
+ virtual bool OnDataReady()
+ {
+ char data = 0;
+ if (Instance->SE->Recv(this, &data, 1, 0) > 0)
+ {
+ Dispatch();
+ return true;
+ }
+ return false;
+ }
+
+ void Dispatch();
+};
+
+