*/
#include "socket.h"
-#include "configreader.h"
#include "inspstring.h"
#include "socketengine.h"
#include "inspircd.h"
{
if (!ip.empty() || ((IP != "*") && (IP != "127.0.0.1") && (!IP.empty()) && (IP != "::1")))
{
+ /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
sockaddr* s = new sockaddr[2];
#ifdef IPV6
if (v6)
in6_addr n;
if (inet_pton(AF_INET6, IP.c_str(), &n) > 0)
{
- memcpy(&((sockaddr_in6*)s)->sin6_addr, &n, sizeof(n));
+ memcpy(&((sockaddr_in6*)s)->sin6_addr, &n, sizeof(sockaddr_in6));
((sockaddr_in6*)s)->sin6_port = 0;
((sockaddr_in6*)s)->sin6_family = AF_INET6;
size = sizeof(sockaddr_in6);
}
}
- if (bind(this->fd, s, size) < 0)
+ if (Instance->SE->Bind(this->fd, s, size) < 0)
{
this->state = I_ERROR;
this->OnError(I_ERR_BIND);
bool InspSocket::DoConnect()
{
+ /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
sockaddr* addr = new sockaddr[2];
socklen_t size = sizeof(sockaddr_in);
#ifdef IPV6
((sockaddr_in*)addr)->sin_port = htons(this->port);
}
}
-#ifndef WIN32
- int flags = fcntl(this->fd, F_GETFL, 0);
- fcntl(this->fd, F_SETFL, flags | O_NONBLOCK);
-#else
- unsigned long flags = 0;
- ioctlsocket(this->fd, FIONBIO, &flags);
+
+ Instance->SE->NonBlocking(this->fd);
+
+#ifdef WIN32
+ /* UGH for the LOVE OF ZOMBIE JESUS SOMEONE FIX THIS!!!!!!!!!!! */
+ Instance->SE->Blocking(this->fd);
#endif
- if (connect(this->fd, (sockaddr*)addr, size) == -1)
+
+ if (Instance->SE->Connect(this, (sockaddr*)addr, size) == -1)
{
if (errno != EINPROGRESS)
{
this->Instance->Timers->AddTimer(this->Timeout);
}
#ifdef WIN32
- /* Set nonblocking mode after the connect() call */
- flags = 0;
- ioctlsocket(this->fd, FIONBIO, &flags);
+ /* CRAQ SMOKING STUFF TO BE FIXED */
+ Instance->SE->NonBlocking(this->fd);
#endif
this->state = I_CONNECTING;
if (this->fd > -1)
Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
- shutdown(this->fd,2);
- if (close(this->fd) != -1)
+ Instance->SE->Shutdown(this, 2);
+ if (Instance->SE->Close(this) != -1)
this->OnClose();
if (Instance->SocketCull.find(this) == Instance->SocketCull.end())
while (outbuffer.size() && (errno != EAGAIN))
{
/* Send a line */
-#ifndef WIN32
- int result = write(this->fd,outbuffer[0].c_str(),outbuffer[0].length());
-#else
- int result = send(this->fd,outbuffer[0].c_str(),outbuffer[0].length(), 0);
-#endif
+ int result = Instance->SE->Send(this, outbuffer[0].c_str(), outbuffer[0].length(), 0);
+
if (result > 0)
{
if ((unsigned int)result >= outbuffer[0].length())
errno = EAGAIN;
}
}
+ else if (result == 0)
+ {
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ return true;
+ }
else if ((result == -1) && (errno != EAGAIN))
{
this->OnError(I_ERR_WRITE);
break;
case I_LISTENING:
{
+ /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
sockaddr* client = new sockaddr[2];
length = sizeof (sockaddr_in);
std::string recvip;
if ((!*this->host) || strchr(this->host, ':'))
length = sizeof(sockaddr_in6);
#endif
- incoming = _accept (this->fd, client, &length);
+ incoming = Instance->SE->Accept(this, client, &length);
#ifdef IPV6
if ((!*this->host) || strchr(this->host, ':'))
{
}
else
#endif
+ Instance->SE->NonBlocking(incoming);
+
recvip = inet_ntoa(((sockaddr_in*)client)->sin_addr);
this->OnIncomingConnection(incoming, (char*)recvip.c_str());