- case I_RESOLVING:
- log(DEBUG,"State = I_RESOLVING, calling DoResolve()");
- return this->DoResolve();
- break;
- case I_CONNECTING:
- log(DEBUG,"State = I_CONNECTED");
- this->SetState(I_CONNECTED);
- /* Our socket was in write-state, so delete it and re-add it
- * in read-state.
- */
- ServerInstance->SE->DelFd(this->fd);
- ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
- return this->OnConnected();
- break;
- case I_LISTENING:
- length = sizeof (client);
- incoming = accept (this->fd, (sockaddr*)&client,&length);
- this->SetQueues(incoming);
- this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr));
- return true;
- break;
- case I_CONNECTED:
- n = this->OnDataReady();
- /* Flush any pending, but not till after theyre done with the event
- * so there are less write calls involved. */
- this->FlushWriteBuffer();
- return n;
- break;
- default:
- break;
+ Config->ConfValue(Config->config_data, "bind", "port", count, configToken, MAXBUF);
+ Config->ConfValue(Config->config_data, "bind", "address", count, Addr, MAXBUF);
+ Config->ConfValue(Config->config_data, "bind", "type", count, Type, MAXBUF);
+
+ if ((!*Type) || (!strcmp(Type,"clients")))
+ {
+ irc::portparser portrange(configToken, false);
+ long portno = -1;
+ while ((portno = portrange.GetToken()))
+ {
+ if (!HasPort(portno, Addr))
+ {
+ ports_found++;
+ Config->ports[clientportcount+InitialPortCount] = portno;
+ if (*Addr == '*')
+ *Addr = 0;
+
+ strlcpy(Config->addrs[clientportcount+InitialPortCount],Addr,256);
+ clientportcount++;
+ this->Log(DEBUG,"NEW binding %s:%d [%s] from config",Addr, portno, Type);
+ }
+ }
+ }
+
+ if (!bail)
+ {
+ int PortCount = clientportcount;
+ if (PortCount)
+ {
+ BoundPortCount = stats->BoundPortCount;
+ for (int count = InitialPortCount; count < InitialPortCount + PortCount; count++)
+ {
+ int fd = OpenTCPSocket();
+ if (fd == ERROR)
+ {
+ this->Log(DEBUG,"Bad fd %d binding port [%s:%d]",fd,Config->addrs[count],Config->ports[count]);
+ failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
+ }
+ else
+ {
+ Config->openSockfd[BoundPortCount] = new ListenSocket(this,fd,client,server,Config->ports[count],Config->addrs[count]);
+ if (Config->openSockfd[BoundPortCount]->GetFd() > -1)
+ {
+ if (!SE->AddFd(Config->openSockfd[BoundPortCount]))
+ {
+ this->Log(DEFAULT,"ERK! Failed to add listening port to socket engine!");
+ shutdown(Config->openSockfd[BoundPortCount]->GetFd(),2);
+ close(Config->openSockfd[BoundPortCount]->GetFd());
+ delete Config->openSockfd[BoundPortCount];
+ failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
+ }
+ else
+ BoundPortCount++;
+ }
+ }
+ }
+ return InitialPortCount + BoundPortCount;
+ }
+ else
+ {
+ this->Log(DEBUG,"There is nothing new to bind!");
+ }
+ return InitialPortCount;
+ }