瀏覽代碼

2008-06-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Applied Ross's aria2-0.13.2+1-mingw-5.patch, which changes the 
type of
	socket from int to sock_t as sockets are unsigned in Windows.
	For AsyncNameResolver, DownloadEngine, I did additional 
modification
	for the portion of the code changed according to epoll support.
	I defined sock_t in a2netcompat.h to use sock_t without 
including
	SocketCore.h.
	* src/AsyncNameResolver.cc
	* src/AsyncNameResolver.h
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/SocketCore.cc
	* src/SocketCore.h
	* src/a2netcompat.h
Tatsuhiro Tsujikawa 17 年之前
父節點
當前提交
953d1683a3
共有 8 個文件被更改,包括 45 次插入23 次删除
  1. 16 0
      ChangeLog
  2. 1 1
      src/AsyncNameResolver.cc
  3. 1 1
      src/AsyncNameResolver.h
  4. 6 6
      src/DownloadEngine.cc
  5. 8 8
      src/DownloadEngine.h
  6. 4 4
      src/SocketCore.cc
  7. 3 3
      src/SocketCore.h
  8. 6 0
      src/a2netcompat.h

+ 16 - 0
ChangeLog

@@ -1,3 +1,19 @@
+2008-06-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Applied Ross's aria2-0.13.2+1-mingw-5.patch, which changes the type of
+	socket from int to sock_t as sockets are unsigned in Windows.
+	For AsyncNameResolver, DownloadEngine, I did additional modification
+	for the portion of the code changed according to epoll support.
+	I defined sock_t in a2netcompat.h to use sock_t without including
+	SocketCore.h.
+	* src/AsyncNameResolver.cc
+	* src/AsyncNameResolver.h
+	* src/DownloadEngine.cc
+	* src/DownloadEngine.h
+	* src/SocketCore.cc
+	* src/SocketCore.h
+	* src/a2netcompat.h
+
 2008-06-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Applied Ross's aria2-0.13.2+1-mingw-4.patch. With this change, all

+ 1 - 1
src/AsyncNameResolver.cc

@@ -117,7 +117,7 @@ void AsyncNameResolver::process(fd_set* rfdsPtr, fd_set* wfdsPtr)
 
 #ifdef HAVE_LIBCARES
 
-int AsyncNameResolver::getsock(int* sockets) const
+int AsyncNameResolver::getsock(sock_t* sockets) const
 {
   return ares_getsock(channel, sockets, ARES_GETSOCK_MAXNUM);
 }

+ 1 - 1
src/AsyncNameResolver.h

@@ -91,7 +91,7 @@ public:
 
 #ifdef HAVE_LIBCARES
 
-  int getsock(int* sockets) const;
+  int getsock(sock_t* sockets) const;
 
   void process(ares_socket_t readfd, ares_socket_t writefd);
 

+ 6 - 6
src/DownloadEngine.cc

@@ -116,7 +116,7 @@ void CommandEvent::processEvents(int events)
 
 ADNSEvent::ADNSEvent(const SharedHandle<AsyncNameResolver>& resolver,
 		     Command* command,
-		     int socket, int events):
+		     sock_t socket, int events):
   _resolver(resolver), _command(command), _socket(socket), _events(events) {}
 
 bool ADNSEvent::operator==(const ADNSEvent& event) const
@@ -149,7 +149,7 @@ void ADNSEvent::processEvents(int events)
 
 #endif // HAVE_EPOLL && ENABLE_ASYNC_DNS
 
-SocketEntry::SocketEntry(int socket):_socket(socket)
+SocketEntry::SocketEntry(sock_t socket):_socket(socket)
 {
 #ifdef HAVE_EPOLL
   memset(&_epEvent, 0, sizeof(struct epoll_event));
@@ -241,7 +241,7 @@ void SocketEntry::processEvents(int events)
 
 }
 
-int SocketEntry::getSocket() const
+sock_t SocketEntry::getSocket() const
 {
   return _socket;
 }
@@ -574,7 +574,7 @@ void DownloadEngine::updateFdSet() {
   FD_ZERO(&wfdset);
   for(std::deque<SharedHandle<SocketEntry> >::iterator i =
 	socketEntries.begin(); i != socketEntries.end(); ++i) {
-    int fd = (*i)->getSocket();
+    sock_t fd = (*i)->getSocket();
     int events = (*i)->getEvents();
     if(events&SocketEntry::EVENT_READ) {
       FD_SET(fd, &rfdset);
@@ -590,7 +590,7 @@ void DownloadEngine::updateFdSet() {
 
 #endif // !HAVE_EPOLL
 
-bool DownloadEngine::addSocketEvents(int socket, Command* command, int events
+bool DownloadEngine::addSocketEvents(sock_t socket, Command* command, int events
 #if defined HAVE_EPOLL && defined ENABLE_ASYNC_DNS
 				     ,const SharedHandle<AsyncNameResolver>& rs
 #endif // HAVE_EPOLL && ENABLE_ASYNC_DNS
@@ -676,7 +676,7 @@ bool DownloadEngine::addSocketEvents(int socket, Command* command, int events
   }
 }
 
-bool DownloadEngine::deleteSocketEvents(int socket, Command* command, int events
+bool DownloadEngine::deleteSocketEvents(sock_t socket, Command* command, int events
 #if defined HAVE_EPOLL && defined ENABLE_ASYNC_DNS
 					,const SharedHandle<AsyncNameResolver>& rs
 #endif // HAVE_EPOLL && ENABLE_ASYNC_DNS

+ 8 - 8
src/DownloadEngine.h

@@ -89,11 +89,11 @@ class ADNSEvent {
 private:
   SharedHandle<AsyncNameResolver> _resolver;
   Command* _command;
-  int _socket;
+  sock_t _socket;
   int _events;
 public:
   ADNSEvent(const SharedHandle<AsyncNameResolver>& resolver, Command* command,
-	    int socket, int events);
+	    sock_t socket, int events);
 
   void processEvents(int events);
 
@@ -106,7 +106,7 @@ public:
 
 class SocketEntry {
 private:
-  int _socket;
+  sock_t _socket;
 
   std::deque<CommandEvent> _commandEvents;
 
@@ -144,7 +144,7 @@ public:
 
 #endif // !HAVE_EPOLL
 
-  SocketEntry(int socket);
+  SocketEntry(sock_t socket);
 
   bool operator==(const SocketEntry& entry) const;
 
@@ -174,7 +174,7 @@ public:
 
 #endif // !HAVE_EPOLL
 
-  int getSocket() const;
+  sock_t getSocket() const;
 
   bool eventEmpty() const;
 
@@ -197,7 +197,7 @@ private:
 
   size_t _socketsSize;
   
-  int _sockets[ARES_GETSOCK_MAXNUM];
+  sock_t _sockets[ARES_GETSOCK_MAXNUM];
 
 #endif // HAVE_EPOLL
 
@@ -321,14 +321,14 @@ public:
   bool deleteSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
 				 Command* command);
 
-  bool addSocketEvents(int socket, Command* command, int events
+  bool addSocketEvents(sock_t socket, Command* command, int events
 #if defined HAVE_EPOLL && defined ENABLE_ASYNC_DNS
 		       ,const SharedHandle<AsyncNameResolver>& rs =
 		       SharedHandle<AsyncNameResolver>()
 #endif // HAVE_EPOLL && ENABLE_ASYNC_DNS
 		       );
 
-  bool deleteSocketEvents(int socket, Command* command, int events
+  bool deleteSocketEvents(sock_t socket, Command* command, int events
 #if defined HAVE_EPOLL && defined ENABLE_ASYNC_DNS
 			  ,const SharedHandle<AsyncNameResolver>& rs =
 			  SharedHandle<AsyncNameResolver>()

+ 4 - 4
src/SocketCore.cc

@@ -66,7 +66,7 @@ SocketCore::SocketCore(int sockType):_sockType(sockType), sockfd(-1)  {
   init();
 }
 
-SocketCore::SocketCore(int sockfd, int sockType):_sockType(sockType), sockfd(sockfd) {
+SocketCore::SocketCore(sock_t sockfd, int sockType):_sockType(sockType), sockfd(sockfd) {
   init();
 }
 
@@ -145,7 +145,7 @@ void SocketCore::bind(uint16_t port)
   }
   struct addrinfo* rp;
   for(rp = res; rp; rp = rp->ai_next) {
-    int fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+    sock_t fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
     if(fd == -1) {
       continue;
     }
@@ -178,7 +178,7 @@ SocketCore* SocketCore::acceptConnection() const
 {
   struct sockaddr_storage sockaddr;
   socklen_t len = sizeof(sockaddr);
-  int fd;
+  sock_t fd;
   while((fd = accept(sockfd, reinterpret_cast<struct sockaddr*>(&sockaddr), &len)) == -1 && errno == EINTR);
   if(fd == -1) {
     throw DlAbortEx(StringFormat(EX_SOCKET_ACCEPT, errorMsg()).str());
@@ -227,7 +227,7 @@ void SocketCore::establishConnection(const std::string& host, uint16_t port)
   }
   struct addrinfo* rp;
   for(rp = res; rp; rp = rp->ai_next) {
-    int fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+    sock_t fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
     if(fd == -1) {
       continue;
     }

+ 3 - 3
src/SocketCore.h

@@ -65,7 +65,7 @@ private:
   // socket type defined in <sys/socket.h>
   int _sockType;
   // socket endpoint descriptor
-  int sockfd;
+  sock_t sockfd;
 
 #ifdef HAVE_EPOLL
 
@@ -104,7 +104,7 @@ private:
 
 #endif // HAVE_EPOLL
 
-  SocketCore(int sockfd, int sockType);
+  SocketCore(sock_t sockfd, int sockType);
   static int error();
   static const char *errorMsg();
   static const char *errorMsg(const int err);
@@ -112,7 +112,7 @@ public:
   SocketCore(int sockType = SOCK_STREAM);
   ~SocketCore();
 
-  int getSockfd() const { return sockfd; }
+  sock_t getSockfd() const { return sockfd; }
 
   bool isOpen() const { return sockfd != -1; }
 

+ 6 - 0
src/a2netcompat.h

@@ -91,4 +91,10 @@
 # include "gai_strerror.h"
 #endif // HAVE_GAI_STRERROR
 
+#ifdef HAVE_WINSOCK2_H
+# define sock_t SOCKET
+#else
+# define sock_t int
+#endif
+
 #endif // _D_A2NETCOMPAT_H_