99
1010#include < AK/Noncopyable.h>
1111#include < AK/StdLibExtras.h>
12- #include < LibCore/File.h>
13- #include < LibCore/System.h>
12+ #include < LibCore/Forward.h>
1413
1514namespace IPC {
1615
@@ -20,62 +19,24 @@ class File {
2019public:
2120 File () = default ;
2221
23- static File adopt_file (NonnullOwnPtr<Core::File> file)
24- {
25- return File (file->leak_fd ());
26- }
22+ static File adopt_file (NonnullOwnPtr<Core::File> file);
23+ static File adopt_fd (int fd);
24+ static ErrorOr<File> clone_fd (int fd);
2725
28- static File adopt_fd (int fd)
29- {
30- return File (fd);
31- }
26+ File (File&& other);
27+ File& operator =(File&& other);
3228
33- static ErrorOr<File> clone_fd (int fd)
34- {
35- int new_fd = TRY (Core::System::dup (fd));
36- return File (new_fd);
37- }
38-
39- File (File&& other)
40- : m_fd(exchange(other.m_fd, -1 ))
41- {
42- }
43-
44- File& operator =(File&& other)
45- {
46- if (this != &other) {
47- m_fd = exchange (other.m_fd , -1 );
48- }
49- return *this ;
50- }
51-
52- ~File ()
53- {
54- if (m_fd != -1 )
55- (void )Core::System::close (m_fd);
56- }
29+ ~File ();
5730
5831 int fd () const { return m_fd; }
5932
60- // NOTE: This is 'const' since generated IPC messages expose all parameters by const reference.
61- [[nodiscard]] int take_fd () const
62- {
63- return exchange (m_fd, -1 );
64- }
33+ // This is 'const' since generated IPC messages expose all parameters by const reference.
34+ [[nodiscard]] int take_fd () const { return exchange (m_fd, -1 ); }
6535
66- // FIXME: IPC::Files transferred over the wire are always set O_CLOEXEC during decoding.
67- // Perhaps we should add an option to IPC::File to allow the receiver to decide whether to
68- // make it O_CLOEXEC or not. Or an attribute in the .ipc file?
69- ErrorOr<void > clear_close_on_exec ()
70- {
71- return Core::System::set_close_on_exec (m_fd, false );
72- }
36+ ErrorOr<void > clear_close_on_exec ();
7337
7438private:
75- explicit File (int fd)
76- : m_fd(fd)
77- {
78- }
39+ explicit File (int fd);
7940
8041 mutable int m_fd { -1 };
8142};
0 commit comments