Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / ipc / glue / FileDescriptorUtils.h
blobe8aab0639ee7bd61176c2b3d9c60a7faaa644c21
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_FileDescriptorUtils_h
8 #define mozilla_ipc_FileDescriptorUtils_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ipc/FileDescriptor.h"
12 #include "nsThreadUtils.h"
13 #include <stdio.h>
15 namespace mozilla {
16 namespace ipc {
18 // When Dispatch() is called (from main thread) this class arranges to close the
19 // provided FileDescriptor on one of the socket transport service threads (to
20 // avoid main thread I/O).
21 class CloseFileRunnable final : public Runnable {
22 typedef mozilla::ipc::FileDescriptor FileDescriptor;
24 FileDescriptor mFileDescriptor;
26 public:
27 explicit CloseFileRunnable(const FileDescriptor& aFileDescriptor);
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_NSIRUNNABLE
32 void Dispatch();
34 private:
35 ~CloseFileRunnable();
37 void CloseFile();
40 // On failure, FileDescriptorToFILE returns nullptr; on success,
41 // returns duplicated FILE*.
42 // This is meant for use with FileDescriptors received over IPC.
43 FILE* FileDescriptorToFILE(const FileDescriptor& aDesc, const char* aOpenMode);
45 // FILEToFileDescriptor does not consume the given FILE*; it must be
46 // fclose()d as normal, and this does not invalidate the returned
47 // FileDescriptor.
48 FileDescriptor FILEToFileDescriptor(FILE* aStream);
50 } // namespace ipc
51 } // namespace mozilla
53 #endif // mozilla_ipc_FileDescriptorUtils_h