+int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen)
+{
+ int nbSent = sendto(fd->GetFd(), (const char*)buf, len, flags, to, tolen);
+ if (nbSent > 0)
+ stats.Update(0, nbSent);
+ return nbSent;
+}
+
+int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen)
+{
+ int ret = connect(fd->GetFd(), serv_addr, addrlen);
+#ifdef _WIN32
+ if ((ret == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK))
+ errno = EINPROGRESS;
+#endif
+ return ret;
+}
+
+int SocketEngine::Shutdown(EventHandler* fd, int how)
+{
+ return shutdown(fd->GetFd(), how);
+}
+
+int SocketEngine::Bind(int fd, const irc::sockets::sockaddrs& addr)
+{
+ return bind(fd, &addr.sa, addr.sa_size());
+}
+
+int SocketEngine::Listen(int sockfd, int backlog)
+{
+ return listen(sockfd, backlog);
+}
+
+int SocketEngine::Shutdown(int fd, int how)
+{
+ return shutdown(fd, how);
+}
+
+void SocketEngine::Statistics::Update(size_t len_in, size_t len_out)
+{
+ CheckFlush();
+ indata += len_in;
+ outdata += len_out;
+}
+
+void SocketEngine::Statistics::CheckFlush() const
+{
+ // Reset the in/out byte counters if it has been more than a second
+ time_t now = ServerInstance->Time();
+ if (lastempty != now)
+ {
+ lastempty = now;
+ indata = outdata = 0;
+ }
+}
+
+void SocketEngine::Statistics::GetBandwidth(float& kbitpersec_in, float& kbitpersec_out, float& kbitpersec_total) const
+{
+ CheckFlush();
+ float in_kbit = indata * 8;
+ float out_kbit = outdata * 8;
+ kbitpersec_total = ((in_kbit + out_kbit) / 1024);
+ kbitpersec_in = in_kbit / 1024;
+ kbitpersec_out = out_kbit / 1024;
+}
+
+std::string SocketEngine::LastError()
+{
+#ifndef _WIN32
+ return strerror(errno);