mirror of https://github.com/aria2/aria2
Fixed MinGW non-blocking bug.
* src/SocketCore.cc * src/HttpRequestCommand.cc Added src/timegm,{h,c}pull/1/head
parent
657a40935e
commit
834625364f
|
@ -62,6 +62,10 @@
|
||||||
* src/Util.cc:
|
* src/Util.cc:
|
||||||
* src/strptime.c: Added support for %Z option.
|
* src/strptime.c: Added support for %Z option.
|
||||||
|
|
||||||
|
Fixed MinGW non-blocking bug.
|
||||||
|
* src/SocketCore.cc
|
||||||
|
* src/HttpRequestCommand.cc
|
||||||
|
|
||||||
Miscellenous build fixes/enhancements.
|
Miscellenous build fixes/enhancements.
|
||||||
* configure.ac: Added summary report.
|
* configure.ac: Added summary report.
|
||||||
* src/Platform.h: Tweaked #include's.
|
* src/Platform.h: Tweaked #include's.
|
||||||
|
|
|
@ -52,10 +52,6 @@ HttpRequestCommand::~HttpRequestCommand() {}
|
||||||
bool HttpRequestCommand::executeInternal() {
|
bool HttpRequestCommand::executeInternal() {
|
||||||
socket->setBlockingMode();
|
socket->setBlockingMode();
|
||||||
if(req->getProtocol() == "https") {
|
if(req->getProtocol() == "https") {
|
||||||
#ifdef __MINGW32__
|
|
||||||
// it only works in non-blocking mode
|
|
||||||
socket->setNonBlockingMode();
|
|
||||||
#endif // __MINGW32__
|
|
||||||
socket->initiateSecureConnection();
|
socket->initiateSecureConnection();
|
||||||
}
|
}
|
||||||
if(!e->option->getAsBool(PREF_HTTP_KEEP_ALIVE)) {
|
if(!e->option->getAsBool(PREF_HTTP_KEEP_ALIVE)) {
|
||||||
|
|
|
@ -188,16 +188,21 @@ void SocketCore::establishConnection(const string& host, int32_t port) {
|
||||||
}
|
}
|
||||||
// make socket non-blocking mode
|
// make socket non-blocking mode
|
||||||
setNonBlockingMode();
|
setNonBlockingMode();
|
||||||
if(connect(sockfd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr)) == -1 && SOCKET_ERRNO != EINPROGRESS) {
|
if(connect(sockfd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr)) == -1 && SOCKET_ERRNO !=
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
EINPROGRESS
|
||||||
|
#else
|
||||||
|
WSAEWOULDBLOCK
|
||||||
|
#endif // __MINGW32__
|
||||||
|
) {
|
||||||
throw new DlAbortEx(EX_SOCKET_CONNECT, host.c_str(), errorMsg());
|
throw new DlAbortEx(EX_SOCKET_CONNECT, host.c_str(), errorMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCore::setNonBlockingMode() {
|
void SocketCore::setNonBlockingMode() {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
u_long flag = 0;
|
static u_long flag = 1;
|
||||||
::ioctlsocket(sockfd, FIONBIO, &flag);
|
if (::ioctlsocket(sockfd, FIONBIO, &flag) == -1) {
|
||||||
if (WSAGetLastError()) {
|
|
||||||
throw new DlAbortEx(EX_SOCKET_NONBLOCKING, errorMsg());
|
throw new DlAbortEx(EX_SOCKET_NONBLOCKING, errorMsg());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -210,8 +215,10 @@ void SocketCore::setNonBlockingMode() {
|
||||||
|
|
||||||
void SocketCore::setBlockingMode() {
|
void SocketCore::setBlockingMode() {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
u_long flag = 1;
|
static u_long flag = 0;
|
||||||
::ioctlsocket(sockfd, FIONBIO, &flag);
|
if (::ioctlsocket(sockfd, FIONBIO, &flag) == -1) {
|
||||||
|
throw new DlAbortEx(EX_SOCKET_BLOCKING, errorMsg());
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
int32_t flags = fcntl(sockfd, F_GETFL, 0);
|
int32_t flags = fcntl(sockfd, F_GETFL, 0);
|
||||||
// TODO add error handling
|
// TODO add error handling
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/* timegm.c - libc replacement function
|
||||||
|
* Copyright (C) 2004 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* This file is part of GnuPG.
|
||||||
|
*
|
||||||
|
* GnuPG is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GnuPG is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
timegm() is a GNU function that might not be available everywhere.
|
||||||
|
It's basically the inverse of gmtime() - you give it a struct tm,
|
||||||
|
and get back a time_t. It differs from mktime() in that it handles
|
||||||
|
the case where the struct tm is UTC and the local environment isn't.
|
||||||
|
|
||||||
|
Some BSDs don't handle the putenv("foo") case properly, so we use
|
||||||
|
unsetenv if the platform has it to remove environment variables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
time_t
|
||||||
|
timegm(struct tm *tm)
|
||||||
|
{
|
||||||
|
time_t answer;
|
||||||
|
char *zone;
|
||||||
|
|
||||||
|
zone=getenv("TZ");
|
||||||
|
putenv("TZ=UTC");
|
||||||
|
tzset();
|
||||||
|
answer=mktime(tm);
|
||||||
|
if(zone)
|
||||||
|
{
|
||||||
|
char *old_zone;
|
||||||
|
|
||||||
|
old_zone=malloc(3+strlen(zone)+1);
|
||||||
|
if(old_zone)
|
||||||
|
{
|
||||||
|
strcpy(old_zone,"TZ=");
|
||||||
|
strcat(old_zone,zone);
|
||||||
|
putenv(old_zone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#ifdef HAVE_UNSETENV
|
||||||
|
unsetenv("TZ");
|
||||||
|
#else
|
||||||
|
putenv("TZ=");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tzset();
|
||||||
|
return answer;
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* aria2 - The high speed download utility
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give
|
||||||
|
* permission to link the code of portions of this program with the
|
||||||
|
* OpenSSL library under certain conditions as described in each
|
||||||
|
* individual source file, and distribute linked combinations
|
||||||
|
* including the two.
|
||||||
|
* You must obey the GNU General Public License in all respects
|
||||||
|
* for all of the code used other than OpenSSL. If you modify
|
||||||
|
* file(s) with this exception, you may extend this exception to your
|
||||||
|
* version of the file(s), but you are not obligated to do so. If you
|
||||||
|
* do not wish to do so, delete this exception statement from your
|
||||||
|
* version. If you delete this exception statement from all source
|
||||||
|
* files in the program, then also delete it here.
|
||||||
|
*/
|
||||||
|
/* copyright --> */
|
||||||
|
#ifndef _D_TIMEGM_H_
|
||||||
|
#define _D_TIMEGM_H_
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_TIMEGM
|
||||||
|
|
||||||
|
time_t timegm(struct tm *tm);
|
||||||
|
|
||||||
|
#endif // HAVE_TIMEGM
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif // _D_TIMEGM_H_
|
Loading…
Reference in New Issue