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"
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
;
27 explicit CloseFileRunnable(const FileDescriptor
& aFileDescriptor
);
29 NS_DECL_ISUPPORTS_INHERITED
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
48 FileDescriptor
FILEToFileDescriptor(FILE* aStream
);
51 } // namespace mozilla
53 #endif // mozilla_ipc_FileDescriptorUtils_h