- if ((this->fd = OpenTCPSocket()) == ERROR)
- {
- this->fd = -1;
- this->state = I_ERROR;
- this->OnError(I_ERR_SOCKET);
- this->Instance->Log(DEBUG,"OpenTCPSocket() error");
- return;
- }
- else
- {
- if (!SI->BindSocket(this->fd,this->client,this->server,aport,(char*)ipaddr.c_str()))
- {
- this->Instance->Log(DEBUG,"BindSocket() error %s",strerror(errno));
- this->Close();
- this->fd = -1;
- this->state = I_ERROR;
- this->OnError(I_ERR_BIND);
- this->ClosePending = true;
- return;
- }
- else
- {
- this->state = I_LISTENING;
- if (this->fd > -1)
- {
- if (!this->Instance->SE->AddFd(this))
- {
- this->Close();
- this->state = I_ERROR;
- this->OnError(I_ERR_NOMOREFDS);
- }
- }
- this->Instance->Log(DEBUG,"New socket now in I_LISTENING state");
- return;
- }
- }
- }
- else
- {
- strlcpy(this->host,ipaddr.c_str(),MAXBUF);
- this->port = aport;
-
- if (insp_aton(host,&addy) < 1)
- {
- this->Instance->Log(DEBUG,"You cannot pass hostnames to InspSocket, resolve them first with Resolver!");
- this->Close();
- this->fd = -1;
- this->state = I_ERROR;
- this->OnError(I_ERR_RESOLVE);
- return;
- }
- else
- {
- this->Instance->Log(DEBUG,"No need to resolve %s",this->host);
- strlcpy(this->IP,host,MAXBUF);
- timeout_end = time(NULL) + maxtime;
- this->DoConnect();
- }