(trunk libT) remove dead code
This commit is contained in:
parent
4723b4a6e4
commit
5917436e60
|
@ -62,7 +62,7 @@
|
||||||
#include "fdlimit.h"
|
#include "fdlimit.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "platform.h" /* tr_lock */
|
#include "platform.h" /* MAX_PATH_LENGTH, TR_PATH_DELIMITER */
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#define dbgmsg( ... ) \
|
#define dbgmsg( ... ) \
|
||||||
|
@ -95,11 +95,8 @@ struct tr_fd_s
|
||||||
{
|
{
|
||||||
int socketCount;
|
int socketCount;
|
||||||
int socketLimit;
|
int socketLimit;
|
||||||
|
|
||||||
struct tr_openfile * openFiles;
|
|
||||||
int openFileLimit;
|
int openFileLimit;
|
||||||
|
struct tr_openfile * openFiles;
|
||||||
tr_lock * lock;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct tr_fd_s * gFd = NULL;
|
static struct tr_fd_s * gFd = NULL;
|
||||||
|
@ -291,12 +288,12 @@ TrOpenFile( int i,
|
||||||
int flags;
|
int flags;
|
||||||
char * filename;
|
char * filename;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int alreadyExisted;
|
tr_bool alreadyExisted;
|
||||||
|
|
||||||
/* confirm the parent folder exists */
|
/* confirm the parent folder exists */
|
||||||
if( stat( folder, &sb ) || !S_ISDIR( sb.st_mode ) )
|
if( stat( folder, &sb ) || !S_ISDIR( sb.st_mode ) )
|
||||||
{
|
{
|
||||||
tr_err( _( "Couldn't create \"%1$s\": parent folder \"%2$s\" does not exist" ), torrentFile, folder );
|
tr_err( _( "Couldn't create \"%1$s\": \"%2$s\" is not a folder" ), torrentFile, folder );
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,6 +351,9 @@ TrOpenFile( int i,
|
||||||
preallocateFileSparse( file->fd, desiredFileSize );
|
preallocateFileSparse( file->fd, desiredFileSize );
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_FADVISE
|
#ifdef HAVE_POSIX_FADVISE
|
||||||
|
/* this doubles the OS level readahead buffer, which in practice
|
||||||
|
* turns out to be a good thing, because many (most?) clients request
|
||||||
|
* chunks of blocks in order */
|
||||||
posix_fadvise( file->fd, 0, 0, POSIX_FADV_SEQUENTIAL );
|
posix_fadvise( file->fd, 0, 0, POSIX_FADV_SEQUENTIAL );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -361,24 +361,21 @@ TrOpenFile( int i,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static TR_INLINE tr_bool
|
||||||
fileIsOpen( const struct tr_openfile * o )
|
fileIsOpen( const struct tr_openfile * o )
|
||||||
{
|
{
|
||||||
return o->fd >= 0;
|
return o->fd >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
TrCloseFile( int i )
|
TrCloseFile( struct tr_openfile * o )
|
||||||
{
|
{
|
||||||
struct tr_openfile * o = &gFd->openFiles[i];
|
assert( o != NULL );
|
||||||
|
|
||||||
assert( i >= 0 );
|
|
||||||
assert( i < gFd->openFileLimit );
|
|
||||||
assert( fileIsOpen( o ) );
|
assert( fileIsOpen( o ) );
|
||||||
|
|
||||||
tr_close_file( o->fd );
|
tr_close_file( o->fd );
|
||||||
o->fd = -1;
|
o->fd = -1;
|
||||||
o->isCheckedOut = 0;
|
o->isCheckedOut = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -403,13 +400,11 @@ tr_fdFileCheckout( int torrentId,
|
||||||
assert( torrentId > 0 );
|
assert( torrentId > 0 );
|
||||||
assert( folder && *folder );
|
assert( folder && *folder );
|
||||||
assert( torrentFile && *torrentFile );
|
assert( torrentFile && *torrentFile );
|
||||||
assert( doWrite == 0 || doWrite == 1 );
|
assert( tr_isBool( doWrite ) );
|
||||||
|
|
||||||
tr_snprintf( filename, sizeof( filename ), "%s%c%s", folder, TR_PATH_DELIMITER, torrentFile );
|
tr_snprintf( filename, sizeof( filename ), "%s%c%s", folder, TR_PATH_DELIMITER, torrentFile );
|
||||||
dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' );
|
dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' );
|
||||||
|
|
||||||
tr_lockLock( gFd->lock );
|
|
||||||
|
|
||||||
/* is it already open? */
|
/* is it already open? */
|
||||||
for( i=0; i<gFd->openFileLimit; ++i )
|
for( i=0; i<gFd->openFileLimit; ++i )
|
||||||
{
|
{
|
||||||
|
@ -422,20 +417,12 @@ tr_fdFileCheckout( int torrentId,
|
||||||
if( strcmp( filename, o->filename ) )
|
if( strcmp( filename, o->filename ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( fileIsCheckedOut( o ) )
|
assert( !fileIsCheckedOut( o ) );
|
||||||
{
|
|
||||||
dbgmsg( "found it! it's open, but checked out. waiting..." );
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
tr_wait( 200 );
|
|
||||||
tr_lockLock( gFd->lock );
|
|
||||||
i = -1; /* reloop */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( doWrite && !o->isWritable )
|
if( doWrite && !o->isWritable )
|
||||||
{
|
{
|
||||||
dbgmsg( "found it! it's open and available, but isn't writable. closing..." );
|
dbgmsg( "found it! it's open and available, but isn't writable. closing..." );
|
||||||
TrCloseFile( i );
|
TrCloseFile( o );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,22 +455,12 @@ tr_fdFileCheckout( int torrentId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( winner >= 0 )
|
assert( winner >= 0 );
|
||||||
{
|
|
||||||
if( fileIsOpen( &gFd->openFiles[winner] ) )
|
if( fileIsOpen( &gFd->openFiles[winner] ) )
|
||||||
{
|
{
|
||||||
dbgmsg( "closing file '%s', slot #%d",
|
dbgmsg( "closing file \"%s\"", gFd->openFiles[winner].filename );
|
||||||
gFd->openFiles[winner].filename,
|
TrCloseFile( &gFd->openFiles[winner] );
|
||||||
winner );
|
|
||||||
TrCloseFile( winner );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dbgmsg( "everything's full! waiting for someone else to finish something" );
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
tr_wait( 200 );
|
|
||||||
tr_lockLock( gFd->lock );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,9 +468,9 @@ tr_fdFileCheckout( int torrentId,
|
||||||
o = &gFd->openFiles[winner];
|
o = &gFd->openFiles[winner];
|
||||||
if( !fileIsOpen( o ) )
|
if( !fileIsOpen( o ) )
|
||||||
{
|
{
|
||||||
const int err = TrOpenFile( winner, folder, torrentFile, doWrite, preallocationMode, desiredFileSize );
|
const int err = TrOpenFile( winner, folder, torrentFile, doWrite,
|
||||||
|
preallocationMode, desiredFileSize );
|
||||||
if( err ) {
|
if( err ) {
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
errno = err;
|
errno = err;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -508,81 +485,59 @@ tr_fdFileCheckout( int torrentId,
|
||||||
o->torrentId = torrentId;
|
o->torrentId = torrentId;
|
||||||
o->isCheckedOut = 1;
|
o->isCheckedOut = 1;
|
||||||
o->date = tr_date( );
|
o->date = tr_date( );
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
return o->fd;
|
return o->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_fdFileReturn( int fd )
|
tr_fdFileReturn( int fd )
|
||||||
{
|
{
|
||||||
int i;
|
struct tr_openfile * o;
|
||||||
|
const struct tr_openfile * end;
|
||||||
|
|
||||||
tr_lockLock( gFd->lock );
|
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
|
||||||
|
|
||||||
for( i = 0; i < gFd->openFileLimit; ++i )
|
|
||||||
{
|
{
|
||||||
struct tr_openfile * o = &gFd->openFiles[i];
|
|
||||||
if( o->fd != fd )
|
if( o->fd != fd )
|
||||||
continue;
|
continue;
|
||||||
|
dbgmsg( "releasing file \"%s\"", o->filename );
|
||||||
dbgmsg( "releasing file '%s' in slot #%d", o->filename, i );
|
o->isCheckedOut = FALSE;
|
||||||
o->isCheckedOut = 0;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_fdFileClose( const char * filename )
|
tr_fdFileClose( const char * filename )
|
||||||
{
|
{
|
||||||
int i;
|
struct tr_openfile * o;
|
||||||
tr_lockLock( gFd->lock );
|
const struct tr_openfile * end;
|
||||||
|
|
||||||
for( i=0; i<gFd->openFileLimit; ++i )
|
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
|
||||||
{
|
{
|
||||||
struct tr_openfile * o = &gFd->openFiles[i];
|
|
||||||
if( !fileIsOpen( o ) || strcmp( filename, o->filename ) )
|
if( !fileIsOpen( o ) || strcmp( filename, o->filename ) )
|
||||||
continue;
|
continue;
|
||||||
|
dbgmsg( "tr_fdFileClose closing \"%s\"", filename );
|
||||||
dbgmsg( "tr_fdFileClose closing '%s'", filename );
|
|
||||||
|
|
||||||
assert( !o->isCheckedOut && "this is a test assertion... I *think* this is always true now" );
|
assert( !o->isCheckedOut && "this is a test assertion... I *think* this is always true now" );
|
||||||
|
TrCloseFile( o );
|
||||||
TrCloseFile( i );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_fdTorrentClose( int torrentId )
|
tr_fdTorrentClose( int torrentId )
|
||||||
{
|
{
|
||||||
int i;
|
struct tr_openfile * o;
|
||||||
tr_lockLock( gFd->lock );
|
const struct tr_openfile * end;
|
||||||
|
|
||||||
for( i=0; i<gFd->openFileLimit; ++i )
|
|
||||||
{
|
|
||||||
struct tr_openfile * o = &gFd->openFiles[i];
|
|
||||||
|
|
||||||
assert( !o->isCheckedOut && "this is a test assertion... I *think* this is always true now" );
|
|
||||||
|
|
||||||
|
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
|
||||||
if( fileIsOpen( o ) && o->torrentId == torrentId )
|
if( fileIsOpen( o ) && o->torrentId == torrentId )
|
||||||
TrCloseFile( i );
|
TrCloseFile( o );
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
****
|
****
|
||||||
**** Sockets
|
**** Sockets
|
||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
|
|
||||||
static int
|
static TR_INLINE int
|
||||||
getSocketMax( struct tr_fd_s * gFd )
|
getSocketMax( struct tr_fd_s * gFd )
|
||||||
{
|
{
|
||||||
return gFd->socketLimit;
|
return gFd->socketLimit;
|
||||||
|
@ -593,8 +548,6 @@ tr_fdSocketCreate( int domain, int type )
|
||||||
{
|
{
|
||||||
int s = -1;
|
int s = -1;
|
||||||
|
|
||||||
tr_lockLock( gFd->lock );
|
|
||||||
|
|
||||||
if( gFd->socketCount < getSocketMax( gFd ) )
|
if( gFd->socketCount < getSocketMax( gFd ) )
|
||||||
if( ( s = socket( domain, type, 0 ) ) < 0 )
|
if( ( s = socket( domain, type, 0 ) ) < 0 )
|
||||||
{
|
{
|
||||||
|
@ -611,7 +564,6 @@ tr_fdSocketCreate( int domain, int type )
|
||||||
|
|
||||||
assert( gFd->socketCount >= 0 );
|
assert( gFd->socketCount >= 0 );
|
||||||
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +575,6 @@ tr_fdSocketAccept( int b,
|
||||||
int s;
|
int s;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
struct sockaddr_storage sock;
|
struct sockaddr_storage sock;
|
||||||
tr_lockLock( gFd->lock );
|
|
||||||
|
|
||||||
assert( addr );
|
assert( addr );
|
||||||
assert( port );
|
assert( port );
|
||||||
|
@ -664,30 +615,19 @@ tr_fdSocketAccept( int b,
|
||||||
++gFd->socketCount;
|
++gFd->socketCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
socketClose( int fd )
|
tr_fdSocketClose( int fd )
|
||||||
|
{
|
||||||
|
if( fd >= 0 )
|
||||||
{
|
{
|
||||||
EVUTIL_CLOSESOCKET( fd );
|
EVUTIL_CLOSESOCKET( fd );
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
tr_fdSocketClose( int s )
|
|
||||||
{
|
|
||||||
tr_lockLock( gFd->lock );
|
|
||||||
|
|
||||||
if( s >= 0 )
|
|
||||||
{
|
|
||||||
socketClose( s );
|
|
||||||
--gFd->socketCount;
|
--gFd->socketCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( gFd->socketCount >= 0 );
|
assert( gFd->socketCount >= 0 );
|
||||||
|
|
||||||
tr_lockUnlock( gFd->lock );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -705,7 +645,6 @@ tr_fdInit( size_t openFileLimit, size_t socketLimit )
|
||||||
gFd = tr_new0( struct tr_fd_s, 1 );
|
gFd = tr_new0( struct tr_fd_s, 1 );
|
||||||
gFd->openFiles = tr_new0( struct tr_openfile, openFileLimit );
|
gFd->openFiles = tr_new0( struct tr_openfile, openFileLimit );
|
||||||
gFd->openFileLimit = openFileLimit;
|
gFd->openFileLimit = openFileLimit;
|
||||||
gFd->lock = tr_lockNew( );
|
|
||||||
|
|
||||||
#ifdef HAVE_GETRLIMIT
|
#ifdef HAVE_GETRLIMIT
|
||||||
{
|
{
|
||||||
|
@ -729,13 +668,12 @@ tr_fdInit( size_t openFileLimit, size_t socketLimit )
|
||||||
void
|
void
|
||||||
tr_fdClose( void )
|
tr_fdClose( void )
|
||||||
{
|
{
|
||||||
int i = 0;
|
struct tr_openfile * o;
|
||||||
|
const struct tr_openfile * end;
|
||||||
|
|
||||||
for( i = 0; i < gFd->openFileLimit; ++i )
|
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
|
||||||
if( fileIsOpen( &gFd->openFiles[i] ) )
|
if( fileIsOpen( o ) )
|
||||||
TrCloseFile( i );
|
TrCloseFile( o );
|
||||||
|
|
||||||
tr_lockFree( gFd->lock );
|
|
||||||
|
|
||||||
tr_free( gFd->openFiles );
|
tr_free( gFd->openFiles );
|
||||||
tr_free( gFd );
|
tr_free( gFd );
|
||||||
|
|
Loading…
Reference in New Issue