transmission: update from 2.13 to 2.22
[tomato.git] / release / src / router / transmission / libtransmission / fdlimit.h
blobbe9491fe00b914722cf84ae70b8342377a6378e4
1 /*
2 * This file Copyright (C) Mnemosyne LLC
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.
10 * $Id: fdlimit.h 11817 2011-02-02 23:29:17Z jordan $
13 #ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15 #endif
17 #include "transmission.h"
18 #include "net.h"
20 /**
21 * @addtogroup file_io File IO
22 * @{
25 void tr_fdSetFileLimit( tr_session * session, int limit );
27 int tr_fdGetFileLimit( tr_session * session );
29 void tr_fdSetGlobalPeerLimit( tr_session * session, int limit );
31 /***
32 ****
33 ***/
35 void tr_set_file_for_single_pass( int fd );
37 int tr_open_file_for_scanning( const char * filename );
39 int tr_open_file_for_writing( const char * filename );
41 void tr_close_file( int fd );
43 int tr_fsync(int fd);
45 ssize_t tr_pread(int fd, void *buf, size_t count, off_t offset);
46 ssize_t tr_pwrite(int fd, const void *buf, size_t count, off_t offset);
47 int tr_prefetch(int fd, off_t offset, size_t count);
50 /**
51 * Returns an fd to the specified filename.
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.
57 * - if doWrite is true, subfolders in torrentFile are created if necessary.
58 * - if doWrite is true, the target file is created if necessary.
60 * on success, a file descriptor >= 0 is returned.
61 * on failure, a -1 is returned and errno is set.
63 * @see tr_fdFileClose
65 int tr_fdFileCheckout( tr_session * session,
66 int torrentId,
67 tr_file_index_t fileNum,
68 const char * fileName,
69 tr_bool doWrite,
70 tr_preallocation_mode preallocationMode,
71 uint64_t desiredFileSize );
73 int tr_fdFileGetCached( tr_session * session,
74 int torrentId,
75 tr_file_index_t fileNum,
76 tr_bool doWrite );
78 /**
79 * Closes a file that's being held by our file repository.
81 * If the file isn't checked out, it's fsync()ed and close()d immediately.
82 * If the file is currently checked out, it will be closed upon its return.
84 * @see tr_fdFileCheckout
86 void tr_fdFileClose( tr_session * session,
87 const tr_torrent * tor,
88 tr_file_index_t fileNo );
91 /**
92 * Closes all the files associated with a given torrent id
94 void tr_fdTorrentClose( tr_session * session, int torrentId );
97 /***********************************************************************
98 * Sockets
99 **********************************************************************/
100 int tr_fdSocketCreate( tr_session * session, int domain, int type );
102 int tr_fdSocketAccept( tr_session * session,
103 int listening_sockfd,
104 tr_address * addr,
105 tr_port * port );
107 void tr_fdSocketClose( tr_session * session, int s );
109 /***********************************************************************
110 * tr_fdClose
111 ***********************************************************************
112 * Frees resources allocated by tr_fdInit.
113 **********************************************************************/
114 void tr_fdClose( tr_session * session );
117 void tr_fdSetPeerLimit( tr_session * session, int n );
119 int tr_fdGetPeerLimit( const tr_session * );
121 /* @} */