2006-07-16 19:39:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2005-2008 Transmission authors and contributors
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2007-07-31 14:26:44 +00:00
|
|
|
#include "net.h"
|
|
|
|
|
2007-01-14 12:00:21 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* tr_fdInit
|
|
|
|
***********************************************************************
|
|
|
|
* Detect the maximum number of open files and initializes things.
|
|
|
|
**********************************************************************/
|
2007-12-24 07:02:40 +00:00
|
|
|
void tr_fdInit( int globalPeerLimit );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-10-30 18:35:06 +00:00
|
|
|
void tr_fdClose( void );
|
|
|
|
|
2007-11-21 16:16:59 +00:00
|
|
|
/**
|
|
|
|
* Returns an fd to the specified filename.
|
|
|
|
*
|
2008-01-18 19:13:32 +00:00
|
|
|
* A small pool of open files is kept to avoid the overhead of
|
|
|
|
* continually opening and closing the same files when downloading
|
|
|
|
* piece data. It's also used to ensure only one caller can
|
|
|
|
* write to the file at a time. Callers check out a file, use it,
|
|
|
|
* and then check it back in via tr_fdFileReturn() when done.
|
2007-11-21 16:16:59 +00:00
|
|
|
*
|
2008-10-03 04:49:06 +00:00
|
|
|
* - if `folder' doesn't exist, errno is set to ENOENT.
|
2008-01-18 19:13:32 +00:00
|
|
|
* - if doWrite is true, subfolders in torrentFile are created if necessary.
|
|
|
|
* - if doWrite is true, the target file is created if necessary.
|
|
|
|
*
|
|
|
|
* on success, a file descriptor >= 0 is returned.
|
2008-10-03 04:49:06 +00:00
|
|
|
* on failure, a -1 is returned and errno is set.
|
2007-11-21 16:16:59 +00:00
|
|
|
*
|
|
|
|
* @see tr_fdFileReturn
|
|
|
|
* @see tr_fdFileClose
|
|
|
|
*/
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_fdFileCheckout( const char * folder,
|
|
|
|
const char * torrentFile,
|
2008-11-05 05:56:06 +00:00
|
|
|
int doWrite,
|
|
|
|
int doPreallocate,
|
|
|
|
uint64_t desiredFileSize );
|
2007-11-21 16:16:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an fd from tr_fdFileCheckout() so that other clients may borrow it.
|
|
|
|
*
|
|
|
|
* @see tr_fdFileCheckout
|
|
|
|
* @see tr_fdFileClose
|
|
|
|
*/
|
|
|
|
void tr_fdFileReturn( int file );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes a file that's being held by our file repository.
|
|
|
|
*
|
|
|
|
* If the file isn't checked out, it's closed immediately.
|
|
|
|
* If the file is currently checked out, it will be closed upon its return.
|
|
|
|
*
|
|
|
|
* @see tr_fdFileCheckout
|
|
|
|
* @see tr_fdFileReturn
|
|
|
|
*/
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_fdFileClose( const char * filename );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
2007-01-14 12:00:21 +00:00
|
|
|
/***********************************************************************
|
2007-01-21 19:42:11 +00:00
|
|
|
* Sockets
|
2007-01-14 12:00:21 +00:00
|
|
|
**********************************************************************/
|
2008-10-14 20:44:41 +00:00
|
|
|
int tr_fdSocketCreate( int type );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
int tr_fdSocketAccept( int b,
|
|
|
|
struct in_addr * addr,
|
|
|
|
tr_port_t * port );
|
|
|
|
|
|
|
|
void tr_fdSocketClose( int s );
|
2007-01-14 12:00:21 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* tr_fdClose
|
|
|
|
***********************************************************************
|
|
|
|
* Frees resources allocated by tr_fdInit.
|
|
|
|
**********************************************************************/
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_fdClose( void );
|
2007-01-21 07:16:18 +00:00
|
|
|
|
2007-12-20 21:44:16 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_fdSetPeerLimit( uint16_t n );
|
2007-12-20 21:44:16 +00:00
|
|
|
|
|
|
|
uint16_t tr_fdGetPeerLimit( void );
|
|
|
|
|