source: trunk/libtransmission/fdlimit.h @ 7397

Last change on this file since 7397 was 7397, checked in by charles, 12 years ago

(trunk libT) add ipv6 support by jhujhiti. I think this is the largest user-contributed patch we've ever used... thanks jhujhiti :)

  • Property svn:keywords set to Date Rev Author Id
File size: 3.9 KB
Line 
1/******************************************************************************
2 * $Id: fdlimit.h 7397 2008-12-15 00:17:08Z 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 "net.h"
30
31/***********************************************************************
32 * tr_fdInit
33 ***********************************************************************
34 * Detect the maximum number of open files and initializes things.
35 **********************************************************************/
36void tr_fdInit( int globalPeerLimit );
37
38void tr_fdClose( void );
39
40/**
41 * Returns an fd to the specified filename.
42 *
43 * A small pool of open files is kept to avoid the overhead of
44 * continually opening and closing the same files when downloading
45 * piece data.    It's also used to ensure only one caller can
46 * write to the file at a time.  Callers check out a file, use it,
47 * and then check it back in via tr_fdFileReturn() when done.
48 *
49 * - if `folder' doesn't exist, errno is set to ENOENT.
50 * - if doWrite is true, subfolders in torrentFile are created if necessary.
51 * - if doWrite is true, the target file is created if necessary.
52 *
53 * on success, a file descriptor >= 0 is returned.
54 * on failure, a -1 is returned and errno is set.
55 *
56 * @see tr_fdFileReturn
57 * @see tr_fdFileClose
58 */
59int  tr_fdFileCheckout( const char * folder,
60                        const char * torrentFile,
61                        int          doWrite,
62                        int          doPreallocate,
63                        uint64_t     desiredFileSize );
64
65/**
66 * Returns an fd from tr_fdFileCheckout() so that other clients may borrow it.
67 *
68 * @see tr_fdFileCheckout
69 * @see tr_fdFileClose
70 */
71void tr_fdFileReturn( int file );
72
73/**
74 * Closes a file that's being held by our file repository.
75 *
76 * If the file isn't checked out, it's closed immediately.
77 * If the file is currently checked out, it will be closed upon its return.
78 *
79 * @see tr_fdFileCheckout
80 * @see tr_fdFileReturn
81 */
82void     tr_fdFileClose( const char * filename );
83
84
85/***********************************************************************
86 * Sockets
87 **********************************************************************/
88int      tr_fdSocketCreate( int domain, int type );
89
90int      tr_fdSocketAccept( int           b,
91                            tr_address  * addr,
92                            tr_port     * port );
93
94void     tr_fdSocketClose( int s );
95
96/***********************************************************************
97 * tr_fdClose
98 ***********************************************************************
99 * Frees resources allocated by tr_fdInit.
100 **********************************************************************/
101void     tr_fdClose( void );
102
103
104void     tr_fdSetPeerLimit( uint16_t n );
105
106uint16_t tr_fdGetPeerLimit( void );
107
Note: See TracBrowser for help on using the repository browser.