- int result = 0;
-#ifdef USE_SELECT
- FD_ZERO(&wfdset);
- FD_ZERO(&rfdset);
- timeval tval;
- int sresult;
- for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
- {
- if (ref[a->second] & X_READBIT)
- {
- FD_SET (a->second, &rfdset);
- }
- else
- {
- FD_SET (a->second, &wfdset);
- }
-
- }
- tval.tv_sec = 0;
- tval.tv_usec = 100L;
- sresult = select(FD_SETSIZE, &rfdset, &wfdset, NULL, &tval);
- if (sresult > 0)
+ int on = 1;
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on));
+}
+
+int SocketEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen)
+{
+ int nbRecvd = recvfrom(fd->GetFd(), (char*)buf, len, flags, from, fromlen);
+ if (nbRecvd > 0)
+ stats.Update(nbRecvd, 0);
+ return nbRecvd;
+}
+
+int SocketEngine::Send(EventHandler* fd, const void *buf, size_t len, int flags)
+{
+ int nbSent = send(fd->GetFd(), (const char*)buf, len, flags);
+ if (nbSent > 0)
+ stats.Update(0, nbSent);
+ return nbSent;
+}
+
+int SocketEngine::Recv(EventHandler* fd, void *buf, size_t len, int flags)
+{
+ int nbRecvd = recv(fd->GetFd(), (char*)buf, len, flags);
+ if (nbRecvd > 0)
+ stats.Update(nbRecvd, 0);
+ return nbRecvd;
+}
+
+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::WriteV(EventHandler* fd, const IOVector* iovec, int count)
+{
+ int sent = writev(fd->GetFd(), iovec, count);
+ if (sent > 0)
+ stats.Update(0, sent);
+ return sent;
+}
+
+#ifdef _WIN32
+int SocketEngine::WriteV(EventHandler* fd, const iovec* iovec, int count)
+{
+ // On Windows the fields in iovec are not in the order required by the Winsock API; IOVector has
+ // the fields in the correct order.
+ // Create temporary IOVectors from the iovecs and pass them to the WriteV() method that accepts the
+ // platform's native struct.
+ IOVector wiovec[128];
+ count = std::min(count, static_cast<int>(sizeof(wiovec) / sizeof(IOVector)));
+
+ for (int i = 0; i < count; i++)