-
- /* Create a socket on a random port. Let the tcp stack allocate us an available port */
-#ifdef IPV6
- Notifier(InspIRCd* SI) : BufferedSocket(SI, "::1", 0, true, 3000)
-#else
- Notifier(InspIRCd* SI) : BufferedSocket(SI, "127.0.0.1", 0, true, 3000)
-#endif
- {
- uslen = sizeof(sock_us);
- if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
- {
- throw ModuleException("Could not create random listening port on localhost");
- }
- }
-
- 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 int OnIncomingConnection(int newsock, char* ip)
- {
- Notifier* n = new Notifier(this->Instance, newsock, ip);
- n = n; /* Stop bitching at me, GCC */
- return true;
- }
-
- virtual bool OnDataReady()
- {
- char data = 0;
- /* NOTE: Only a single character is read so we know we
- * cant get a partial read. (We've been told that theres
- * data waiting, so we wont ever get EAGAIN)
- * The function GetCharId translates a single character
- * back into an iterator.
- */
- if (Instance->SE->Recv(this, &data, 1, 0) > 0)
- {
- ConnMap::iterator iter = GetCharId(data);
- if (iter != Connections.end())
- {
- /* Lock the mutex, send back the data */
- pthread_mutex_lock(&results_mutex);
- ResultQueue::iterator n = iter->second->rq.begin();
- (*n)->Send();
- iter->second->rq.pop_front();
- pthread_mutex_unlock(&results_mutex);
- return true;
- }
- /* No error, but unknown id */
- return true;
- }
-
- /* Erk, error on descriptor! */
- return false;
- }