From 5cfda7737f69864e9ab639e083428f239d672dfb Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Tue, 12 May 2020 10:25:43 -0700 Subject: [PATCH] make Poll enums shared --- .../src/Interop/Unix/Interop.Poll.Structs.cs | 28 +++++++++++++++ .../src/Interop/Unix/System.Native/Interop.Poll.cs | 19 ---------- .../System.Console/src/System.Console.csproj | 2 ++ .../System.Console/src/System/ConsolePal.Unix.cs | 2 +- .../src/System.IO.FileSystem.Watcher.csproj | 2 ++ .../src/System/IO/FileSystemWatcher.Linux.cs | 6 ++-- .../System.IO.Pipes/src/System.IO.Pipes.csproj | 2 -- .../src/Interop/Unix/Interop.Serial.cs | 19 ---------- .../System.IO.Ports/src/System.IO.Ports.csproj | 2 ++ .../src/System/IO/Ports/SerialStream.Unix.cs | 20 +++++------ .../System.Net.Http/src/System.Net.Http.csproj | 2 ++ .../src/System.Net.Sockets.csproj | 2 ++ .../src/System/Net/Sockets/SocketPal.Unix.cs | 42 +++++++++++----------- 13 files changed, 73 insertions(+), 75 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Unix/Interop.Poll.Structs.cs diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Poll.Structs.cs b/src/libraries/Common/src/Interop/Unix/Interop.Poll.Structs.cs new file mode 100644 index 0000000..34ca249 --- /dev/null +++ b/src/libraries/Common/src/Interop/Unix/Interop.Poll.Structs.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + [Flags] + internal enum PollEvents : short + { + POLLNONE = 0x0000, // No events occurred. + POLLIN = 0x0001, // non-urgent readable data available + POLLPRI = 0x0002, // urgent readable data available + POLLOUT = 0x0004, // data can be written without blocked + POLLERR = 0x0008, // an error occurred + POLLHUP = 0x0010, // the file descriptor hung up + POLLNVAL = 0x0020, // the requested events were invalid + } + + internal struct PollEvent + { + internal int FileDescriptor; // The file descriptor to poll + internal PollEvents Events; // The events to poll for + internal PollEvents TriggeredEvents; // The events that occurred which triggered the poll + } +} diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Poll.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Poll.cs index 5496172..895ce72 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Poll.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Poll.cs @@ -10,25 +10,6 @@ internal static partial class Interop { internal static partial class Sys { - [Flags] - internal enum PollEvents : short - { - POLLNONE = 0x0000, // No events occurred. - POLLIN = 0x0001, // non-urgent readable data available - POLLPRI = 0x0002, // urgent readable data available - POLLOUT = 0x0004, // data can be written without blocked - POLLERR = 0x0008, // an error occurred - POLLHUP = 0x0010, // the file descriptor hung up - POLLNVAL = 0x0020, // the requested events were invalid - } - - internal struct PollEvent - { - internal int FileDescriptor; // The file descriptor to poll - internal PollEvents Events; // The events to poll for - internal PollEvents TriggeredEvents; // The events that occurred which triggered the poll - } - /// /// Polls a set of file descriptors for signals and returns what signals have been set /// diff --git a/src/libraries/System.Console/src/System.Console.csproj b/src/libraries/System.Console/src/System.Console.csproj index 4336824..23b21f1 100644 --- a/src/libraries/System.Console/src/System.Console.csproj +++ b/src/libraries/System.Console/src/System.Console.csproj @@ -194,6 +194,8 @@ Link="Common\Interop\Unix\Interop.OpenFlags.cs" /> + + diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs index def4ae5..5b04282 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @@ -680,11 +680,11 @@ namespace System.IO // that's actually what's needed (otherwise it'd be fine to block indefinitely waiting // for the next event to arrive). const int MillisecondsTimeout = 2; - Interop.Sys.PollEvents events; - Interop.Sys.Poll(_inotifyHandle, Interop.Sys.PollEvents.POLLIN, MillisecondsTimeout, out events); + Interop.PollEvents events; + Interop.Sys.Poll(_inotifyHandle, Interop.PollEvents.POLLIN, MillisecondsTimeout, out events); // If we error or don't have any signaled handles, send the deleted event - if (events == Interop.Sys.PollEvents.POLLNONE) + if (events == Interop.PollEvents.POLLNONE) { // There isn't any more data in the queue so this is a deleted event watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, expandedName); diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj index ee5dd28..9c2991a 100644 --- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj +++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj @@ -151,8 +151,6 @@ Link="Common\Interop\Unix\Interop.Permissions.cs" /> - + diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index 887c869..dd8ea97 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -464,7 +464,7 @@ namespace System.IO.Ports // Will wait `timeout` miliseconds or until reading or writing is possible // If no operation is requested it will throw // Returns event which has happened - private Interop.Serial.PollEvents PollEvents(int timeout, bool pollReadEvents, bool pollWriteEvents, out Interop.ErrorInfo? error) + private Interop.PollEvents PollEvents(int timeout, bool pollReadEvents, bool pollWriteEvents, out Interop.ErrorInfo? error) { if (!pollReadEvents && !pollWriteEvents) { @@ -472,19 +472,19 @@ namespace System.IO.Ports throw new Exception(); } - Interop.Serial.PollEvents eventsToPoll = Interop.Serial.PollEvents.POLLERR; + Interop.PollEvents eventsToPoll = Interop.PollEvents.POLLERR; if (pollReadEvents) { - eventsToPoll |= Interop.Serial.PollEvents.POLLIN; + eventsToPoll |= Interop.PollEvents.POLLIN; } if (pollWriteEvents) { - eventsToPoll |= Interop.Serial.PollEvents.POLLOUT; + eventsToPoll |= Interop.PollEvents.POLLOUT; } - Interop.Serial.PollEvents events = Interop.Serial.PollEvents.POLLNONE; + Interop.PollEvents events = Interop.PollEvents.POLLNONE; Interop.Error ret = Interop.Serial.Poll( _handle, eventsToPoll, @@ -843,7 +843,7 @@ namespace System.IO.Ports } else { - Interop.Serial.PollEvents events = PollEvents(1, + Interop.PollEvents events = PollEvents(1, pollReadEvents: hasPendingReads, pollWriteEvents: hasPendingWrites, out Interop.ErrorInfo? error); @@ -854,21 +854,21 @@ namespace System.IO.Ports break; } - if (events.HasFlag(Interop.Serial.PollEvents.POLLNVAL) || - events.HasFlag(Interop.Serial.PollEvents.POLLERR)) + if (events.HasFlag(Interop.PollEvents.POLLNVAL) || + events.HasFlag(Interop.PollEvents.POLLERR)) { // bad descriptor or some other error we can't handle FinishPendingIORequests(); break; } - if (events.HasFlag(Interop.Serial.PollEvents.POLLIN)) + if (events.HasFlag(Interop.PollEvents.POLLIN)) { int bytesRead = DoIORequest(_readQueue, _processReadDelegate); _totalBytesRead += bytesRead; } - if (events.HasFlag(Interop.Serial.PollEvents.POLLOUT)) + if (events.HasFlag(Interop.PollEvents.POLLOUT)) { DoIORequest(_writeQueue, _processWriteDelegate); } diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 18b5292..ee9e25b 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -541,6 +541,8 @@ Link="Common\Interop\Unix\System.Native\Interop.Pipe.cs" /> + +