- /* All instances of ListenSocket share these, so reference count it */
- ServerInstance->Logs->Log("SOCKET", DEBUG,"Allocate sockaddr structures");
- sock_us = new sockaddr[2];
- client = new sockaddr[2];
- raddr = new sockaddr[2];
+ irc::sockets::satoap(&bind_to, bind_addr, port);
+ bind_desc = irc::sockets::satouser(&bind_to);
+
+ this->fd = irc::sockets::OpenTCPSocket(bind_addr);
+ }
+
+ if (this->fd > -1)
+ {
+ int rv = ServerInstance->SE->Bind(this->fd, &bind_to.sa, sizeof(bind_to));
+ if (rv >= 0)
+ rv = ServerInstance->SE->Listen(this->fd, ServerInstance->Config->MaxConn);
+
+ if (rv < 0)
+ {
+ ServerInstance->SE->Shutdown(this, 2);
+ ServerInstance->SE->Close(this);
+ this->fd = -1;
+ }
+ else
+ {
+ ServerInstance->SE->NonBlocking(this->fd);
+ ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE);
+ }