source: trunk/libtransmission/fdlimit.h @ 9495

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

(trunk libT) #2551 "better buffer cache management": apply jch's prefetch-base.patch

  • Property svn:keywords set to Date Rev Author Id
File size: 4.6 KB
Line 
1/******************************************************************************
2 * $Id: fdlimit.h 9495 2009-11-08 23:43:38Z 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
32/**
33 * @addtogroup file_io File IO
34 * @{
35 */
36
37void tr_fdSetFileLimit( tr_session * session, int limit );
38
39int tr_fdGetFileLimit( const tr_session * session );
40
41void tr_fdSetGlobalPeerLimit( tr_session * session, int limit );
42
43/***
44****
45***/
46
47int tr_open_file_for_scanning( const char * filename );
48
49int tr_open_file_for_writing( const char * filename );
50
51void tr_close_file( int fd );
52
53tr_bool tr_preallocate_file( const char * filename, uint64_t length );
54
55int64_t tr_lseek( int fd, int64_t offset, int whence );
56ssize_t tr_pread(int fd, void *buf, size_t count, off_t offset);
57ssize_t tr_pwrite(int fd, void *buf, size_t count, off_t offset);
58int tr_prefetch(int fd, off_t offset, size_t count);
59
60
61/**
62 * Returns an fd to the specified filename.
63 *
64 * A small pool of open files is kept to avoid the overhead of
65 * continually opening and closing the same files when downloading
66 * piece data.
67 *
68 * - if doWrite is true, subfolders in torrentFile are created if necessary.
69 * - if doWrite is true, the target file is created if necessary.
70 *
71 * on success, a file descriptor >= 0 is returned.
72 * on failure, a -1 is returned and errno is set.
73 *
74 * @see tr_fdFileClose
75 */
76int  tr_fdFileCheckout( tr_session             * session,
77                        int                      torrentId,
78                        tr_file_index_t          fileNum,
79                        const char             * fileName,
80                        tr_bool                  doWrite,
81                        tr_preallocation_mode    preallocationMode,
82                        uint64_t                 desiredFileSize );
83
84int tr_fdFileGetCached( tr_session             * session,
85                        int                      torrentId,
86                        tr_file_index_t          fileNum,
87                        tr_bool                  doWrite );
88
89/**
90 * Closes a file that's being held by our file repository.
91 *
92 * If the file isn't checked out, it's closed immediately.
93 * If the file is currently checked out, it will be closed upon its return.
94 *
95 * @see tr_fdFileCheckout
96 */
97void tr_fdFileClose( tr_session        * session,
98                     const tr_torrent  * tor,
99                     tr_file_index_t     fileNo );
100
101
102/**
103 * Closes all the files associated with a given torrent id
104 */
105void tr_fdTorrentClose( tr_session * session, int torrentId );
106
107
108/***********************************************************************
109 * Sockets
110 **********************************************************************/
111int      tr_fdSocketCreate( tr_session * session, int domain, int type );
112
113int      tr_fdSocketAccept( tr_session  * session,
114                            int           b,
115                            tr_address  * addr,
116                            tr_port     * port );
117
118void     tr_fdSocketClose( tr_session * session, int s );
119
120/***********************************************************************
121 * tr_fdClose
122 ***********************************************************************
123 * Frees resources allocated by tr_fdInit.
124 **********************************************************************/
125void     tr_fdClose( tr_session * session );
126
127
128void     tr_fdSetPeerLimit( tr_session * session, int n );
129
130int      tr_fdGetPeerLimit( const tr_session * );
131
132/* @} */
Note: See TracBrowser for help on using the repository browser.