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
pull/1/head
Tatsuhiro Tsujikawa 2008-06-16 14:01:45 +00:00
parent 8989ffb6c5
commit 953d1683a3
8 changed files with 45 additions and 23 deletions

View File

@ -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> 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 Applied Ross's aria2-0.13.2+1-mingw-4.patch. With this change, all

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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