diff --git a/ChangeLog b/ChangeLog index 17bea89d..314a0a1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-06-16 Tatsuhiro Tsujikawa + + 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 Applied Ross's aria2-0.13.2+1-mingw-4.patch. With this change, all diff --git a/src/AsyncNameResolver.cc b/src/AsyncNameResolver.cc index d20619b1..0ef27b13 100644 --- a/src/AsyncNameResolver.cc +++ b/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); } diff --git a/src/AsyncNameResolver.h b/src/AsyncNameResolver.h index b48472ed..acbe178c 100644 --- a/src/AsyncNameResolver.h +++ b/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); diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 1b1fdf29..648ff02b 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -116,7 +116,7 @@ void CommandEvent::processEvents(int events) ADNSEvent::ADNSEvent(const SharedHandle& 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 >::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& 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& rs #endif // HAVE_EPOLL && ENABLE_ASYNC_DNS diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index 251d5b69..b020974c 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -89,11 +89,11 @@ class ADNSEvent { private: SharedHandle _resolver; Command* _command; - int _socket; + sock_t _socket; int _events; public: ADNSEvent(const SharedHandle& 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 _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& 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& rs = SharedHandle() #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& rs = SharedHandle() diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 4383b324..232c0368 100644 --- a/src/SocketCore.cc +++ b/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(&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; } diff --git a/src/SocketCore.h b/src/SocketCore.h index 7ee56b93..d63e5679 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -65,7 +65,7 @@ private: // socket type defined in 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; } diff --git a/src/a2netcompat.h b/src/a2netcompat.h index f7915436..31a2757f 100644 --- a/src/a2netcompat.h +++ b/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_