source: trunk/libtransmission/fdlimit.h @ 8389

Last change on this file since 8389 was 8389, checked in by charles, 13 years ago

(trunk) #920: add "move data" to libT so all clients can use it

  • Property svn:keywords set to Date Rev Author Id
File size: 4.0 KB
Line 
1/******************************************************************************
2 * $Id: fdlimit.h 8389 2009-05-13 15:54:04Z charles $
3 *
4 * Copyright (c) 2005-2008 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef __TRANSMISSION__
26#error only libtransmission should #include this header.
27#endif
28
29#include "transmission.h"
30#include "net.h"
31
32void tr_fdInit( size_t openFileLimit,
33                size_t globalPeerLimit );
34
35int tr_open_file_for_scanning( const char * filename );
36
37int tr_open_file_for_writing( const char * filename );
38
39void tr_close_file( int fd );
40
41tr_bool tr_preallocate_file( const char * filename, uint64_t length );
42
43int64_t tr_lseek( int fd, int64_t offset, int whence );
44
45
46/**
47 * Returns an fd to the specified filename.
48 *
49 * A small pool of open files is kept to avoid the overhead of
50 * continually opening and closing the same files when downloading
51 * piece data.    It's also used to ensure only one caller can
52 * write to the file at a time.  Callers check out a file, use it,
53 * and then check it back in via tr_fdFileReturn() when done.
54 *
55 * - if `folder' doesn't exist, errno is set to ENOENT.
56 * - if doWrite is true, subfolders in torrentFile are created if necessary.
57 * - if doWrite is true, the target file is created if necessary.
58 *
59 * on success, a file descriptor >= 0 is returned.
60 * on failure, a -1 is returned and errno is set.
61 *
62 * @see tr_fdFileReturn
63 * @see tr_fdFileClose
64 */
65int  tr_fdFileCheckout( const char             * folder,
66                        const char             * torrentFile,
67                        tr_bool                  doWrite,
68                        tr_preallocation_mode    preallocationMode,
69                        uint64_t                 desiredFileSize );
70
71/**
72 * Returns an fd from tr_fdFileCheckout() so that other clients may borrow it.
73 *
74 * @see tr_fdFileCheckout
75 * @see tr_fdFileClose
76 */
77void tr_fdFileReturn( int file );
78
79/**
80 * Closes a file that's being held by our file repository.
81 *
82 * If the file isn't checked out, it's closed immediately.
83 * If the file is currently checked out, it will be closed upon its return.
84 *
85 * @see tr_fdFileCheckout
86 * @see tr_fdFileReturn
87 */
88void     tr_fdFileClose( const char * filename );
89
90
91/***********************************************************************
92 * Sockets
93 **********************************************************************/
94int      tr_fdSocketCreate( int domain, int type );
95
96int      tr_fdSocketAccept( int           b,
97                            tr_address  * addr,
98                            tr_port     * port );
99
100void     tr_fdSocketClose( int s );
101
102/***********************************************************************
103 * tr_fdClose
104 ***********************************************************************
105 * Frees resources allocated by tr_fdInit.
106 **********************************************************************/
107void     tr_fdClose( void );
108
109
110void     tr_fdSetPeerLimit( uint16_t n );
111
112uint16_t tr_fdGetPeerLimit( void );
113
Note: See TracBrowser for help on using the repository browser.