Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -115,7 +115,8 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public void StartListening(object data)
{
serverChannel.StartListening(data);
if (serverChannel != null)
serverChannel.StartListening(data);
}
public object ChannelData
@@ -128,7 +129,8 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public void StopListening(object data)
{
serverChannel.StopListening(data);
if (serverChannel != null)
serverChannel.StopListening(data);
}
public string[] GetUrlsForUri(string objectURI)

View File

@@ -26,10 +26,9 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace System.Runtime.Remoting.Channels.Ipc.Win32
{
@@ -89,6 +88,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public const uint OPEN_EXISTING = 3;
public const uint OPEN_ALWAYS = 4;
public const uint TRUNCATE_EXISTING = 5;
public const uint FILE_FLAG_OVERLAPPED = 0x40000000;
// Access flags
public const uint GENERIC_READ = 0x80000000;
@@ -103,6 +103,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public const int ERROR_PIPE_NOT_CONNECTED = 233;
public const int ERROR_PIPE_CONNECTED = 535;
public const int ERROR_PIPE_LISTENING = 536;
public const int ERROR_IO_PENDING = 997;
public const int INVALID_HANDLE_VALUE = -1;
@@ -121,7 +122,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ConnectNamedPipe(
IntPtr hPipe,
IntPtr lpOverlapped
[In] ref NativeOverlapped lpOverlapped
);
[DllImport("kernel32.dll", SetLastError = true)]

View File

@@ -27,8 +27,8 @@
//
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.Runtime.Remoting.Channels.Ipc.Win32
{
@@ -74,7 +74,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
{
IntPtr hPipe = NamedPipeHelper.CreateNamedPipe(
pipeName,
NamedPipeHelper.PIPE_ACCESS_DUPLEX,
NamedPipeHelper.PIPE_ACCESS_DUPLEX | NamedPipeHelper.FILE_FLAG_OVERLAPPED,
NamedPipeHelper.PIPE_TYPE_MESSAGE
| NamedPipeHelper.PIPE_READMODE_MESSAGE
| NamedPipeHelper.PIPE_WAIT,
@@ -85,27 +85,43 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
IntPtr.Zero
);
if (hPipe.ToInt32() == NamedPipeHelper.INVALID_HANDLE_VALUE)
{
throw new NamedPipeException();
if (hPipe.ToInt32 () == NamedPipeHelper.INVALID_HANDLE_VALUE) {
throw new NamedPipeException (Marshal.GetLastWin32Error ());
}
bool canConnect = NamedPipeHelper.ConnectNamedPipe(hPipe, IntPtr.Zero);
int lastError = Marshal.GetLastWin32Error();
if (!canConnect && lastError == NamedPipeHelper.ERROR_PIPE_CONNECTED)
canConnect = true;
// Connect the named pipe with overlapped structure
// in order to make it altertable. This way we will
// wake up when someone aborts a thread waiting
// for this pipe.
NativeOverlapped overlapped = new NativeOverlapped ();
bool canConnect = NamedPipeHelper.ConnectNamedPipe (hPipe, ref overlapped);
if (canConnect)
{
return new NamedPipeSocket(hPipe);
}
else
{
NamedPipeHelper.CloseHandle(hPipe);
throw new NamedPipeException(lastError);
}
int lastError = Marshal.GetLastWin32Error ();
if (!canConnect) {
if (lastError == NamedPipeHelper.ERROR_IO_PENDING) {
uint bytesTransferred = 0;
if (!GetOverlappedResultEx (hPipe, ref overlapped, out bytesTransferred, Timeout.Infinite, true)) {
lastError = Marshal.GetLastWin32Error ();
NamedPipeHelper.CloseHandle (hPipe);
throw new NamedPipeException (lastError);
}
canConnect = true;
} else if (lastError == NamedPipeHelper.ERROR_PIPE_CONNECTED)
canConnect = true;
}
if (!canConnect) {
NamedPipeHelper.CloseHandle (hPipe);
throw new NamedPipeException (lastError);
}
return new NamedPipeSocket (hPipe);
}
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetOverlappedResultEx (IntPtr hFile, [In] ref System.Threading.NativeOverlapped lpOverlapped,
out uint lpNumberOfBytesTransferred, int dwMilliseconds, bool bAltertable);
}
}