source: trunk/libtransmission/fdlimit.h

Last change on this file was 14479, checked in by mikedld, 6 years ago

Define and use tr_socket_t and TR_BAD_SOCKET instead of int and -1.

Test socket validity by comparing to TR_BAD_SOCKET instead of various
(and sometimes wrong) other tests like x >= 0, x != -1, x > 0,
x > -1, x (valid), and x < 0, x == -1 (invalid).

  • Property svn:keywords set to Date Rev Author Id
File size: 3.3 KB
Line 
1/*
2 * This file Copyright (C) 2005-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: fdlimit.h 14479 2015-03-18 07:34:26Z mikedld $
8 */
9
10#ifndef __TRANSMISSION__
11 #error only libtransmission should #include this header.
12#endif
13
14#include "transmission.h"
15#include "file.h"
16#include "net.h"
17
18/**
19 * @addtogroup file_io File IO
20 * @{
21 */
22
23/***
24****
25***/
26
27/**
28 * Returns an fd to the specified filename.
29 *
30 * A small pool of open files is kept to avoid the overhead of
31 * continually opening and closing the same files when downloading
32 * piece data.
33 *
34 * - if do_write is true, subfolders in torrentFile are created if necessary.
35 * - if do_write is true, the target file is created if necessary.
36 *
37 * on success, a file descriptor >= 0 is returned.
38 * on failure, a TR_BAD_SYS_FILE is returned and errno is set.
39 *
40 * @see tr_fdFileClose
41 */
42tr_sys_file_t  tr_fdFileCheckout (tr_session             * session,
43                                  int                      torrent_id,
44                                  tr_file_index_t          file_num,
45                                  const char             * filename,
46                                  bool                     do_write,
47                                  tr_preallocation_mode    preallocation_mode,
48                                  uint64_t                 preallocation_file_size);
49
50tr_sys_file_t tr_fdFileGetCached (tr_session             * session,
51                                  int                      torrent_id,
52                                  tr_file_index_t          file_num,
53                                  bool                     doWrite);
54
55bool tr_fdFileGetCachedMTime (tr_session       * session,
56                              int                torrent_id,
57                              tr_file_index_t    file_num,
58                              time_t           * mtime);
59
60
61/**
62 * Closes a file that's being held by our file repository.
63 *
64 * If the file isn't checked out, it's fsync ()ed and close ()d immediately.
65 * If the file is currently checked out, it will be closed upon its return.
66 *
67 * @see tr_fdFileCheckout
68 */
69void tr_fdFileClose (tr_session        * session,
70                     const tr_torrent  * tor,
71                     tr_file_index_t     file_num);
72
73
74/**
75 * Closes all the files associated with a given torrent id
76 */
77void tr_fdTorrentClose (tr_session * session, int torrentId);
78
79
80/***********************************************************************
81 * Sockets
82 **********************************************************************/
83tr_socket_t tr_fdSocketCreate (tr_session  * session,
84                               int           domain,
85                               int           type);
86
87tr_socket_t tr_fdSocketAccept (tr_session  * session,
88                               tr_socket_t   listening_sockfd,
89                               tr_address  * addr,
90                               tr_port     * port);
91
92void        tr_fdSocketClose  (tr_session  * session,
93                               tr_socket_t   s);
94
95/***********************************************************************
96 * tr_fdClose
97 ***********************************************************************
98 * Frees resources allocated by tr_fdInit.
99 **********************************************************************/
100void     tr_fdClose (tr_session * session);
101
102/* @} */
Note: See TracBrowser for help on using the repository browser.