- if(connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1)
- {
- if (errno != EINPROGRESS)
- {
- this->Close();
- this->OnError(I_ERR_CONNECT);
- this->state = I_ERROR;
- return;
- }
- }
- this->state = I_CONNECTING;
- ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE);
- socket_ref[this->fd] = this;
- return;
+ log(DEBUG,"Part 2 DoConnect() %s",this->IP.c_str());
+ inet_aton(this->IP.c_str(),&addy);
+ addr.sin_family = AF_INET;
+ addr.sin_addr = addy;
+ addr.sin_port = htons(this->port);
+
+ int flags;
+ flags = fcntl(this->fd, F_GETFL, 0);
+ fcntl(this->fd, F_SETFL, flags | O_NONBLOCK);
+
+ if (connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1)
+ {
+ if (errno != EINPROGRESS)
+ {
+ log(DEBUG,"Error connect() %d: %s",this->fd,strerror(errno));
+ this->OnError(I_ERR_CONNECT);
+ this->state = I_ERROR;
+ this->Close();
+ return false;
+ }