IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
FileDescriptor.cs
Go to the documentation of this file.
1using System;
2using System.Runtime.InteropServices;
3
4using IKVM.Runtime;
6
8{
9
13 static class FileDescriptor
14 {
15
16#if FIRST_PASS == false
17
18 static FileDescriptorAccessor fileDescriptorAccessor;
19
20 static FileDescriptorAccessor FileDescriptorAccessor => JVM.Internal.BaseAccessors.Get(ref fileDescriptorAccessor);
21
22#endif
23
29 static void SetPtr(object self, long ptr)
30 {
31#if FIRST_PASS
32 throw new NotImplementedException();
33#else
34 lock (self)
35 {
36 var p = FileDescriptorAccessor.GetPtr(self);
37 if (p != ptr || ptr == -1)
38 {
39 var stream = (IDisposable)FileDescriptorAccessor.GetStream(self);
40 if (stream != null)
41 {
42 stream.Dispose();
43 FileDescriptorAccessor.SetStream(self, null);
44 }
45 }
46
47 FileDescriptorAccessor.SetPtr(self, ptr);
48 }
49#endif
50 }
51
57 public static int getFd(object self)
58 {
59#if FIRST_PASS
60 throw new NotImplementedException();
61#else
62 lock (self)
63 return (int)FileDescriptorAccessor.GetPtr(self);
64#endif
65 }
66
72 public static void setFd(object self, int value)
73 {
74 SetPtr(self, value);
75 }
76
82 public static long getHandle(object self)
83 {
84#if FIRST_PASS
85 throw new NotImplementedException();
86#else
87 lock (self)
88 return FileDescriptorAccessor.GetPtr(self);
89#endif
90 }
91
97 public static void setHandle(object self, long value)
98 {
99 SetPtr(self, value);
100 }
101
107 public static object standardStream(int fd)
108 {
109#if FIRST_PASS
110 throw new NotImplementedException();
111#else
112 var fdo = FileDescriptorAccessor.Init();
113 FileDescriptorAccessor.SetPtr(fdo, GetStandardHandle(fd));
114 return fdo;
115#endif
116 }
117
118 [DllImport("Kernel32")]
119 static extern IntPtr GetStdHandle(int nStdHandle);
120
126 static long GetStandardHandle(int fd)
127 {
128 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
129 {
130 if (fd == 0)
131 return (long)GetStdHandle(-10);
132 else if (fd == 1)
133 return (long)GetStdHandle(-11);
134 else if (fd == 2)
135 return (long)GetStdHandle(-12);
136 }
137
138 return fd;
139 }
140
141 }
142}
Implements the native methods for 'FileDescriptor'.
static object standardStream(int fd)
Implements the native method 'standardStream'.
static int getFd(object self)
Implements the native method 'getFd'.
static void setHandle(object self, long value)
Implements the native method 'setHandle'.
static void setFd(object self, int value)
Implements the native method 'setFd'.
static long getHandle(object self)
Implements the native method 'getHandle'.
Main state of the running JVM.