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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
|
|
|
#error only libtransmission should #include this header.
|
|
|
|
#endif
|
|
|
|
|
2009-01-16 16:38:16 +00:00
|
|
|
#include "transmission.h"
|
2007-07-31 14:26:44 +00:00
|
|
|
#include "net.h"
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup file_io File IO
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-10-23 03:41:36 +00:00
|
|
|
void tr_fdSetFileLimit( tr_session * session, int limit );
|
|
|
|
|
|
|
|
int tr_fdGetFileLimit( const tr_session * session );
|
|
|
|
|
|
|
|
void tr_fdSetGlobalPeerLimit( tr_session * session, int limit );
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-04-26 20:44:18 +00:00
|
|
|
int tr_open_file_for_scanning( const char * filename );
|
2009-04-26 00:51:51 +00:00
|
|
|
|
2009-05-13 15:54:04 +00:00
|
|
|
int tr_open_file_for_writing( const char * filename );
|
|
|
|
|
2009-04-26 20:44:18 +00:00
|
|
|
void tr_close_file( int fd );
|
2009-04-26 00:51:51 +00:00
|
|
|
|
2009-05-13 15:54:04 +00:00
|
|
|
tr_bool tr_preallocate_file( const char * filename, uint64_t length );
|
|
|
|
|
2009-04-26 16:14:47 +00:00
|
|
|
int64_t tr_lseek( int fd, int64_t offset, int whence );
|
2009-11-08 23:43:38 +00:00
|
|
|
ssize_t tr_pread(int fd, void *buf, size_t count, off_t offset);
|
|
|
|
ssize_t tr_pwrite(int fd, void *buf, size_t count, off_t offset);
|
|
|
|
int tr_prefetch(int fd, off_t offset, size_t count);
|
2009-04-26 16:14:47 +00:00
|
|
|
|
2009-04-07 20:25:32 +00:00
|
|
|
|
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
|
2009-08-15 15:52:10 +00:00
|
|
|
* piece data.
|
2007-11-21 16:16:59 +00:00
|
|
|
*
|
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_fdFileClose
|
|
|
|
*/
|
2009-10-23 03:41:36 +00:00
|
|
|
int tr_fdFileCheckout( tr_session * session,
|
|
|
|
int torrentId,
|
2009-10-19 05:05:00 +00:00
|
|
|
tr_file_index_t fileNum,
|
2009-10-21 19:33:37 +00:00
|
|
|
const char * fileName,
|
2009-01-16 16:38:16 +00:00
|
|
|
tr_bool doWrite,
|
|
|
|
tr_preallocation_mode preallocationMode,
|
|
|
|
uint64_t desiredFileSize );
|
2007-11-21 16:16:59 +00:00
|
|
|
|
2009-10-23 03:41:36 +00:00
|
|
|
int tr_fdFileGetCached( tr_session * session,
|
|
|
|
int torrentId,
|
2009-10-19 05:05:00 +00:00
|
|
|
tr_file_index_t fileNum,
|
|
|
|
tr_bool doWrite );
|
|
|
|
|
2007-11-21 16:16:59 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2009-10-23 03:41:36 +00:00
|
|
|
void tr_fdFileClose( tr_session * session,
|
|
|
|
const tr_torrent * tor,
|
|
|
|
tr_file_index_t fileNo );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
2009-06-21 07:36:51 +00:00
|
|
|
/**
|
|
|
|
* Closes all the files associated with a given torrent id
|
|
|
|
*/
|
2009-10-23 03:41:36 +00:00
|
|
|
void tr_fdTorrentClose( tr_session * session, int torrentId );
|
2009-06-21 07:36:51 +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
|
|
|
**********************************************************************/
|
2009-10-23 03:41:36 +00:00
|
|
|
int tr_fdSocketCreate( tr_session * session, int domain, int type );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-10-23 03:41:36 +00:00
|
|
|
int tr_fdSocketAccept( tr_session * session,
|
|
|
|
int b,
|
2008-12-02 03:41:58 +00:00
|
|
|
tr_address * addr,
|
|
|
|
tr_port * port );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-10-23 03:41:36 +00:00
|
|
|
void tr_fdSocketClose( tr_session * session, int s );
|
2007-01-14 12:00:21 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* tr_fdClose
|
|
|
|
***********************************************************************
|
|
|
|
* Frees resources allocated by tr_fdInit.
|
|
|
|
**********************************************************************/
|
2009-10-23 03:41:36 +00:00
|
|
|
void tr_fdClose( tr_session * session );
|
2007-01-21 07:16:18 +00:00
|
|
|
|
2007-12-20 21:44:16 +00:00
|
|
|
|
2009-10-23 03:41:36 +00:00
|
|
|
void tr_fdSetPeerLimit( tr_session * session, int n );
|
2007-12-20 21:44:16 +00:00
|
|
|
|
2009-10-23 03:41:36 +00:00
|
|
|
int tr_fdGetPeerLimit( const tr_session * );
|
2007-12-20 21:44:16 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* @} */
|