source: trunk/libtransmission/fdlimit.h @ 12397

Last change on this file since 12397 was 12397, checked in by jordan, 10 years ago

(trunk libT) tr_torrentGetFileMTime(): if the file being looked at is aleady open in fdlimit's file cache, use that cached handle instead of deriving our own.

  • Property svn:keywords set to Date Rev Author Id
File size: 4.3 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: fdlimit.h 12397 2011-04-28 18:40:46Z jordan $
11 */
12
13#ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15#endif
16
17#include "transmission.h"
18#include "net.h"
19
20/**
21 * @addtogroup file_io File IO
22 * @{
23 */
24
25void tr_fdSetFileLimit( tr_session * session, int limit );
26
27int tr_fdGetFileLimit( tr_session * session );
28
29void tr_fdSetGlobalPeerLimit( tr_session * session, int limit );
30
31/***
32****
33***/
34
35void tr_set_file_for_single_pass( int fd );
36
37int tr_open_file_for_scanning( const char * filename );
38
39int tr_open_file_for_writing( const char * filename );
40
41void tr_close_file( int fd );
42
43int tr_fsync(int fd);
44
45ssize_t tr_pread(int fd, void *buf, size_t count, off_t offset);
46ssize_t tr_pwrite(int fd, const void *buf, size_t count, off_t offset);
47int tr_prefetch(int fd, off_t offset, size_t count);
48
49
50/**
51 * Returns an fd to the specified filename.
52 *
53 * A small pool of open files is kept to avoid the overhead of
54 * continually opening and closing the same files when downloading
55 * piece data.
56 *
57 * - if do_write is true, subfolders in torrentFile are created if necessary.
58 * - if do_write is true, the target file is created if necessary.
59 *
60 * @param existing_dir An ancestor of filename which must already exist and
61 *                     won't be created by tr_fdFileCheckout(). This prevents
62 *                     directories from being created in error, such as a mount
63 *                     point for an external drive when the drive is unplugged.
64 *
65 * on success, a file descriptor >= 0 is returned.
66 * on failure, a -1 is returned and errno is set.
67 *
68 * @see tr_fdFileClose
69 */
70int  tr_fdFileCheckout( tr_session             * session,
71                        int                      torrent_id,
72                        tr_file_index_t          file_num,
73                        const char             * existing_dir,
74                        const char             * filename,
75                        bool                  do_write,
76                        tr_preallocation_mode    preallocation_mode,
77                        uint64_t                 preallocation_file_size );
78
79int tr_fdFileGetCached( tr_session             * session,
80                        int                      torrent_id,
81                        tr_file_index_t          file_num,
82                        bool                  doWrite );
83
84bool tr_fdFileGetCachedMTime( tr_session       * session,
85                              int                torrent_id,
86                              tr_file_index_t    file_num,
87                              time_t           * mtime );
88
89
90/**
91 * Closes a file that's being held by our file repository.
92 *
93 * If the file isn't checked out, it's fsync()ed and close()d immediately.
94 * If the file is currently checked out, it will be closed upon its return.
95 *
96 * @see tr_fdFileCheckout
97 */
98void tr_fdFileClose( tr_session        * session,
99                     const tr_torrent  * tor,
100                     tr_file_index_t     file_num );
101
102
103/**
104 * Closes all the files associated with a given torrent id
105 */
106void tr_fdTorrentClose( tr_session * session, int torrentId );
107
108
109/***********************************************************************
110 * Sockets
111 **********************************************************************/
112int      tr_fdSocketCreate( tr_session * session, int domain, int type );
113
114int      tr_fdSocketAccept( tr_session  * session,
115                            int           listening_sockfd,
116                            tr_address  * addr,
117                            tr_port     * port );
118
119void     tr_fdSocketClose( tr_session * session, int s );
120
121/***********************************************************************
122 * tr_fdClose
123 ***********************************************************************
124 * Frees resources allocated by tr_fdInit.
125 **********************************************************************/
126void     tr_fdClose( tr_session * session );
127
128
129void     tr_fdSetPeerLimit( tr_session * session, int n );
130
131int      tr_fdGetPeerLimit( const tr_session * );
132
133/* @} */
Note: See TracBrowser for help on using the repository browser.