- case I_RESOLVING:
- return this->DoResolve();
- break;
- case I_CONNECTING:
- 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->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr));
- return true;
- break;
- case I_CONNECTED:
- return this->OnDataReady();
- break;
- default:
- break;
+ int InitialPortCount = stats->BoundPortCount;
+ this->Log(DEBUG,"Initial port count: %d",InitialPortCount);
+
+ for (int count = 0; count < Config->ConfValueEnum(Config->config_data, "bind"); count++)
+ {
+ 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"))) && (!HasPort(atoi(configToken),Addr)))
+ {
+ // modules handle server bind types now
+ Config->ports[clientportcount+InitialPortCount] = atoi(configToken);
+ if (*Addr == '*')
+ *Addr = 0;
+
+ strlcpy(Config->addrs[clientportcount+InitialPortCount],Addr,256);
+ clientportcount++;
+ this->Log(DEBUG,"NEW binding %s:%s [%s] from config",Addr,configToken, Type);
+ }
+ }
+ 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]);
+ }
+ 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];
+ }
+ else
+ BoundPortCount++;
+ }
+ /*if (!BindSocket(Config->openSockfd[count],client,server,Config->ports[count],Config->addrs[count]))
+ {
+ this->Log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
+ }*/
+ }
+ }
+ return InitialPortCount + BoundPortCount;
+ }
+ else
+ {
+ this->Log(DEBUG,"There is nothing new to bind!");
+ }
+ return InitialPortCount;