Skip to content

Commit b9f1c70

Browse files
R-Goctrflynn89
authored andcommitted
LibIPC: Add missing include and impl on win32
This commit adds a missing include to MessageWindows after header cleanup. It also implement IPC::File which had its implementation moved out of the header, without the matching change to the windows implementation.
1 parent dca80ad commit b9f1c70

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Libraries/LibIPC/FileWindows.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7+
#include <LibCore/File.h>
8+
#include <LibCore/System.h>
79
#include <LibIPC/Decoder.h>
810
#include <LibIPC/File.h>
911
#include <LibIPC/HandleType.h>
@@ -12,6 +14,53 @@
1214

1315
namespace IPC {
1416

17+
File File::adopt_file(NonnullOwnPtr<Core::File> file)
18+
{
19+
return File(file->leak_fd());
20+
}
21+
22+
File File::adopt_fd(int fd)
23+
{
24+
return File(fd);
25+
}
26+
27+
ErrorOr<File> File::clone_fd(int fd)
28+
{
29+
int new_fd = TRY(Core::System::dup(fd));
30+
return File(new_fd);
31+
}
32+
33+
File::File(int fd)
34+
: m_fd(fd)
35+
{
36+
}
37+
38+
File::File(File&& other)
39+
: m_fd(exchange(other.m_fd, -1))
40+
{
41+
}
42+
43+
File& File::operator=(File&& other)
44+
{
45+
if (this != &other) {
46+
m_fd = exchange(other.m_fd, -1);
47+
}
48+
return *this;
49+
}
50+
51+
File::~File()
52+
{
53+
if (m_fd != -1)
54+
(void)Core::System::close(m_fd);
55+
}
56+
57+
// FIXME: IPC::Files transferred over the wire always set O_CLOEXEC during decoding. Perhaps we should add an option to
58+
// allow the receiver to decide whether to make it O_CLOEXEC or not. Or an attribute in the .ipc file?
59+
ErrorOr<void> File::clear_close_on_exec()
60+
{
61+
return Core::System::set_close_on_exec(m_fd, false);
62+
}
63+
1564
template<>
1665
ErrorOr<File> decode(Decoder& decoder)
1766
{

Libraries/LibIPC/MessageWindows.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <AK/ByteReader.h>
9+
#include <LibCore/System.h>
910
#include <LibIPC/HandleType.h>
1011
#include <LibIPC/Message.h>
1112

0 commit comments

Comments
 (0)