| 23 |
Suite 330, Boston, MA 02111-1307 USA |
Suite 330, Boston, MA 02111-1307 USA |
| 24 |
*/ |
*/ |
| 25 |
|
|
| 26 |
|
#define _FILE_OFFSET_BITS 64 |
| 27 |
#include "axel.h" |
#include "axel.h" |
| 28 |
|
|
| 29 |
/* Axel */ |
/* Axel */ |
| 124 |
if( ( axel->size = axel->conn[0].size ) != INT_MAX ) |
if( ( axel->size = axel->conn[0].size ) != INT_MAX ) |
| 125 |
{ |
{ |
| 126 |
if( axel->conf->verbose > 0 ) |
if( axel->conf->verbose > 0 ) |
| 127 |
axel_message( axel, _("File size: %i bytes"), axel->size ); |
axel_message( axel, _("File size: %lld bytes"), axel->size ); |
| 128 |
} |
} |
| 129 |
|
|
| 130 |
/* Wildcards in URL --> Get complete filename */ |
/* Wildcards in URL --> Get complete filename */ |
| 138 |
int axel_open( axel_t *axel ) |
int axel_open( axel_t *axel ) |
| 139 |
{ |
{ |
| 140 |
int i, fd; |
int i, fd; |
| 141 |
|
long long int j; |
| 142 |
|
|
| 143 |
if( axel->conf->verbose > 0 ) |
if( axel->conf->verbose > 0 ) |
| 144 |
axel_message( axel, _("Opening output file %s"), axel->filename ); |
axel_message( axel, _("Opening output file %s"), axel->filename ); |
| 169 |
for( i = 0; i < axel->conf->num_connections; i ++ ) |
for( i = 0; i < axel->conf->num_connections; i ++ ) |
| 170 |
read( fd, &axel->conn[i].currentbyte, sizeof( axel->conn[i].currentbyte ) ); |
read( fd, &axel->conn[i].currentbyte, sizeof( axel->conn[i].currentbyte ) ); |
| 171 |
|
|
| 172 |
axel_message( axel, _("State file found: %i bytes downloaded, %i to go."), |
axel_message( axel, _("State file found: %lld bytes downloaded, %lld to go."), |
| 173 |
axel->bytes_done, axel->size - axel->bytes_done ); |
axel->bytes_done, axel->size - axel->bytes_done ); |
| 174 |
|
|
| 175 |
close( fd ); |
close( fd ); |
| 195 |
/* And check whether the filesystem can handle seeks to |
/* And check whether the filesystem can handle seeks to |
| 196 |
past-EOF areas.. Speeds things up. :) AFAIK this |
past-EOF areas.. Speeds things up. :) AFAIK this |
| 197 |
should just not happen: */ |
should just not happen: */ |
| 198 |
if( lseek( axel->outfd, axel->size, SEEK_SET ) == -1 && axel->conf->num_connections > 1 ) |
if( lseek64( axel->outfd, axel->size, SEEK_SET ) == -1 && axel->conf->num_connections > 1 ) |
| 199 |
{ |
{ |
| 200 |
/* But if the OS/fs does not allow to seek behind |
/* But if the OS/fs does not allow to seek behind |
| 201 |
EOF, we have to fill the file with zeroes before |
EOF, we have to fill the file with zeroes before |
| 203 |
axel_message( axel, _("Crappy filesystem/OS.. Working around. :-(") ); |
axel_message( axel, _("Crappy filesystem/OS.. Working around. :-(") ); |
| 204 |
lseek( axel->outfd, 0, SEEK_SET ); |
lseek( axel->outfd, 0, SEEK_SET ); |
| 205 |
memset( buffer, 0, axel->conf->buffer_size ); |
memset( buffer, 0, axel->conf->buffer_size ); |
| 206 |
i = axel->size; |
j = axel->size; |
| 207 |
while( i > 0 ) |
while( j > 0 ) |
| 208 |
{ |
{ |
| 209 |
write( axel->outfd, buffer, min( i, axel->conf->buffer_size ) ); |
write( axel->outfd, buffer, min( j, axel->conf->buffer_size ) ); |
| 210 |
i -= axel->conf->buffer_size; |
j -= axel->conf->buffer_size; |
| 211 |
} |
} |
| 212 |
} |
} |
| 213 |
} |
} |
| 262 |
void axel_do( axel_t *axel ) |
void axel_do( axel_t *axel ) |
| 263 |
{ |
{ |
| 264 |
fd_set fds[1]; |
fd_set fds[1]; |
| 265 |
int hifd, i, j, size; |
int hifd, i, j; |
| 266 |
|
long long int size; |
| 267 |
struct timeval timeval[1]; |
struct timeval timeval[1]; |
| 268 |
|
|
| 269 |
/* Create statefile if necessary */ |
/* Create statefile if necessary */ |
| 574 |
for( i = 1; i < axel->conf->num_connections; i ++ ) |
for( i = 1; i < axel->conf->num_connections; i ++ ) |
| 575 |
{ |
{ |
| 576 |
#ifdef DEBUG |
#ifdef DEBUG |
| 577 |
printf( "Downloading %i-%i using conn. %i\n", axel->conn[i-1].currentbyte, axel->conn[i-1].lastbyte, i - 1 ); |
printf( "Downloading %lld-%lld using conn. %i\n", axel->conn[i-1].currentbyte, axel->conn[i-1].lastbyte, i - 1 ); |
| 578 |
#endif |
#endif |
| 579 |
axel->conn[i].currentbyte = axel->conn[i-1].lastbyte + 1; |
axel->conn[i].currentbyte = axel->conn[i-1].lastbyte + 1; |
| 580 |
axel->conn[i].lastbyte = axel->conn[i].currentbyte + axel->size / axel->conf->num_connections; |
axel->conn[i].lastbyte = axel->conn[i].currentbyte + axel->size / axel->conf->num_connections; |
| 581 |
} |
} |
| 582 |
axel->conn[axel->conf->num_connections-1].lastbyte = axel->size - 1; |
axel->conn[axel->conf->num_connections-1].lastbyte = axel->size - 1; |
| 583 |
#ifdef DEBUG |
#ifdef DEBUG |
| 584 |
printf( "Downloading %i-%i using conn. %i\n", axel->conn[i-1].currentbyte, axel->conn[i-1].lastbyte, i - 1 ); |
printf( "Downloading %lld-%lld using conn. %i\n", axel->conn[i-1].currentbyte, axel->conn[i-1].lastbyte, i - 1 ); |
| 585 |
#endif |
#endif |
| 586 |
} |
} |