1 | /* |
---|
2 | * This file Copyright (C) 2007-2010 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 10905 2010-06-29 01:21:38Z charles $ |
---|
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 | |
---|
25 | void tr_fdSetFileLimit( tr_session * session, int limit ); |
---|
26 | |
---|
27 | int tr_fdGetFileLimit( const tr_session * session ); |
---|
28 | |
---|
29 | void tr_fdSetGlobalPeerLimit( tr_session * session, int limit ); |
---|
30 | |
---|
31 | /*** |
---|
32 | **** |
---|
33 | ***/ |
---|
34 | |
---|
35 | int tr_open_file_for_scanning( const char * filename ); |
---|
36 | |
---|
37 | int tr_open_file_for_writing( const char * filename ); |
---|
38 | |
---|
39 | void tr_close_file( int fd ); |
---|
40 | |
---|
41 | ssize_t tr_pread(int fd, void *buf, size_t count, off_t offset); |
---|
42 | ssize_t tr_pwrite(int fd, const void *buf, size_t count, off_t offset); |
---|
43 | int tr_prefetch(int fd, off_t offset, size_t count); |
---|
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. |
---|
52 | * |
---|
53 | * - if doWrite is true, subfolders in torrentFile are created if necessary. |
---|
54 | * - if doWrite is true, the target file is created if necessary. |
---|
55 | * |
---|
56 | * on success, a file descriptor >= 0 is returned. |
---|
57 | * on failure, a -1 is returned and errno is set. |
---|
58 | * |
---|
59 | * @see tr_fdFileClose |
---|
60 | */ |
---|
61 | int tr_fdFileCheckout( tr_session * session, |
---|
62 | int torrentId, |
---|
63 | tr_file_index_t fileNum, |
---|
64 | const char * fileName, |
---|
65 | tr_bool doWrite, |
---|
66 | tr_preallocation_mode preallocationMode, |
---|
67 | uint64_t desiredFileSize ); |
---|
68 | |
---|
69 | int tr_fdFileGetCached( tr_session * session, |
---|
70 | int torrentId, |
---|
71 | tr_file_index_t fileNum, |
---|
72 | tr_bool doWrite ); |
---|
73 | |
---|
74 | /** |
---|
75 | * Closes a file that's being held by our file repository. |
---|
76 | * |
---|
77 | * If the file isn't checked out, it's closed immediately. |
---|
78 | * If the file is currently checked out, it will be closed upon its return. |
---|
79 | * |
---|
80 | * @see tr_fdFileCheckout |
---|
81 | */ |
---|
82 | void tr_fdFileClose( tr_session * session, |
---|
83 | const tr_torrent * tor, |
---|
84 | tr_file_index_t fileNo ); |
---|
85 | |
---|
86 | |
---|
87 | /** |
---|
88 | * Closes all the files associated with a given torrent id |
---|
89 | */ |
---|
90 | void tr_fdTorrentClose( tr_session * session, int torrentId ); |
---|
91 | |
---|
92 | |
---|
93 | /*********************************************************************** |
---|
94 | * Sockets |
---|
95 | **********************************************************************/ |
---|
96 | int tr_fdSocketCreate( tr_session * session, int domain, int type ); |
---|
97 | |
---|
98 | int tr_fdSocketAccept( tr_session * session, |
---|
99 | int b, |
---|
100 | tr_address * addr, |
---|
101 | tr_port * port ); |
---|
102 | |
---|
103 | void tr_fdSocketClose( tr_session * session, int s ); |
---|
104 | |
---|
105 | /*********************************************************************** |
---|
106 | * tr_fdClose |
---|
107 | *********************************************************************** |
---|
108 | * Frees resources allocated by tr_fdInit. |
---|
109 | **********************************************************************/ |
---|
110 | void tr_fdClose( tr_session * session ); |
---|
111 | |
---|
112 | |
---|
113 | void tr_fdSetPeerLimit( tr_session * session, int n ); |
---|
114 | |
---|
115 | int tr_fdGetPeerLimit( const tr_session * ); |
---|
116 | |
---|
117 | /* @} */ |
---|