• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FML_UNIQUE_FD_H_
6 #define FLUTTER_FML_UNIQUE_FD_H_
7 
8 #include "flutter/fml/build_config.h"
9 #include "flutter/fml/unique_object.h"
10 
11 #if OS_WIN
12 
13 #include <windows.h>
14 
15 #else  // OS_WIN
16 
17 #include <unistd.h>
18 
19 #endif  // OS_WIN
20 
21 namespace fml {
22 namespace internal {
23 
24 #if OS_WIN
25 
26 namespace os_win {
27 
28 struct UniqueFDTraits {
InvalidValueUniqueFDTraits29   static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
IsValidUniqueFDTraits30   static bool IsValid(HANDLE value) { return value != InvalidValue(); }
31   static void Free(HANDLE fd);
32 };
33 
34 }  // namespace os_win
35 
36 #else  // OS_WIN
37 
38 namespace os_unix {
39 
40 struct UniqueFDTraits {
41   static int InvalidValue() { return -1; }
42   static bool IsValid(int value) { return value >= 0; }
43   static void Free(int fd);
44 };
45 
46 }  // namespace os_unix
47 
48 #endif  // OS_WIN
49 
50 }  // namespace internal
51 
52 #if OS_WIN
53 
54 using UniqueFD = UniqueObject<HANDLE, internal::os_win::UniqueFDTraits>;
55 
56 #else  // OS_WIN
57 
58 using UniqueFD = UniqueObject<int, internal::os_unix::UniqueFDTraits>;
59 
60 #endif  // OS_WIN
61 
62 }  // namespace fml
63 
64 #endif  // FLUTTER_FML_UNIQUE_FD_H_
65