/// <devdoc> /// <para>Determines the status of a socket.</para> /// </devdoc> public static void Select(IList checkRead, IList checkWrite, IList checkError, int microSeconds) { // parameter validation if ((checkRead==null || checkRead.Count==0) && (checkWrite==null || checkWrite.Count==0) && (checkError==null || checkError.Count==0)) { throw new ArgumentNullException(SR.GetString(SR.net_sockets_empty_select)); } const int MaxSelect = 65536; if (checkRead!=null && checkRead.Count>MaxSelect) { throw new ArgumentOutOfRangeException("checkRead", SR.GetString(SR.net_sockets_toolarge_select, "checkRead", MaxSelect.ToString(NumberFormatInfo.CurrentInfo))); } if (checkWrite!=null && checkWrite.Count>MaxSelect) { throw new ArgumentOutOfRangeException("checkWrite", SR.GetString(SR.net_sockets_toolarge_select, "checkWrite", MaxSelect.ToString(NumberFormatInfo.CurrentInfo))); } if (checkError!=null && checkError.Count>MaxSelect) { throw new ArgumentOutOfRangeException("checkError", SR.GetString(SR.net_sockets_toolarge_select, "checkError", MaxSelect.ToString(NumberFormatInfo.CurrentInfo))); } IntPtr[] readfileDescriptorSet = SocketListToFileDescriptorSet(checkRead); IntPtr[] writefileDescriptorSet = SocketListToFileDescriptorSet(checkWrite); IntPtr[] errfileDescriptorSet = SocketListToFileDescriptorSet(checkError); // This code used to erroneously pass a non-null timeval structure containing zeroes // to select() when the caller specified (-1) for the microseconds parameter. That // caused select to actually have a *zero* timeout instead of an infinite timeout // turning the operation into a non-blocking poll. // // Now we pass a null timeval struct when microseconds is (-1). // // Negative microsecond values that weren't exactly (-1) were originally successfully // converted to a timeval struct containing unsigned non-zero integers. This code // retains that behavior so that any app working around the original bug with, // for example, (-2) specified for microseconds, will continue to get the same behavior. int socketCount; if (microSeconds != -1) { TimeValue IOwait = new TimeValue(); MicrosecondsToTimeValue((long)(uint)microSeconds, ref IOwait); socketCount = UnsafeNclNativeMethods.OSSOCK.select( 0, // ignored value readfileDescriptorSet, writefileDescriptorSet, errfileDescriptorSet, ref IOwait); } else { socketCount = UnsafeNclNativeMethods.OSSOCK.select( 0, // ignored value readfileDescriptorSet, writefileDescriptorSet, errfileDescriptorSet, IntPtr.Zero); } GlobalLog.Print("Socket::Select() UnsafeNclNativeMethods.OSSOCK.select returns socketCount:" + socketCount); // // if the native call fails we'll throw a SocketException // if ((SocketError)socketCount==SocketError.SocketError) { throw new SocketException(); } SelectFileDescriptor(checkRead, readfileDescriptorSet); SelectFileDescriptor(checkWrite, writefileDescriptorSet); SelectFileDescriptor(checkError, errfileDescriptorSet); }
private static void MicrosecondsToTimeValue(long microSeconds, ref TimeValue socketTime) { socketTime.Seconds = (int) (microSeconds / microcnv); socketTime.Microseconds = (int) (microSeconds % microcnv); }
/// <include file='doc\Socket.uex' path='docs/doc[@for="Socket.Select"]/*' /> /// <devdoc> /// <para>Determines the status of a socket.</para> /// </devdoc> public static void Select( IList checkRead, IList checkWrite, IList checkError, int microSeconds) { // // parameter validation // if ((checkRead==null || checkRead.Count==0) && (checkWrite==null || checkWrite.Count==0) && (checkError==null || checkError.Count==0)) { throw new ArgumentNullException(SR.GetString(SR.net_sockets_empty_select)); } FileDescriptorSet readfileDescriptorSet, writefileDescriptorSet, errfileDescriptorSet; readfileDescriptorSet = SocketListToFileDescriptorSet(checkRead); writefileDescriptorSet = SocketListToFileDescriptorSet(checkWrite); errfileDescriptorSet = SocketListToFileDescriptorSet(checkError); TimeValue IOwait = new TimeValue(); MicrosecondsToTimeValue(microSeconds, ref IOwait); int errorCode = UnsafeNclNativeMethods.OSSOCK.select( 0, // ignored value ref readfileDescriptorSet, ref writefileDescriptorSet, ref errfileDescriptorSet, ref IOwait); // // if the native call fails we'll throw a SocketException // if (errorCode==SocketErrors.SocketError) { throw new SocketException(); } // // call SelectFileDescriptor to update the IList instances, // and keep count of how many sockets are ready // int totalReadySockets = 0; totalReadySockets += SelectFileDescriptor(checkRead, readfileDescriptorSet); totalReadySockets += SelectFileDescriptor(checkWrite, writefileDescriptorSet); totalReadySockets += SelectFileDescriptor(checkError, errfileDescriptorSet); }
/// <devdoc> /// <para> /// Determines the status of the socket. /// </para> /// </devdoc> public bool Poll(int microSeconds, SelectMode mode) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } IntPtr handle = m_Handle.DangerousGetHandle(); IntPtr[] fileDescriptorSet = new IntPtr[2] { (IntPtr) 1, handle }; TimeValue IOwait = new TimeValue(); // // negative timeout value implies indefinite wait // int socketCount; if (microSeconds != -1) { MicrosecondsToTimeValue((long)(uint)microSeconds, ref IOwait); socketCount = UnsafeNclNativeMethods.OSSOCK.select( 0, mode==SelectMode.SelectRead ? fileDescriptorSet : null, mode==SelectMode.SelectWrite ? fileDescriptorSet : null, mode==SelectMode.SelectError ? fileDescriptorSet : null, ref IOwait); } else { socketCount = UnsafeNclNativeMethods.OSSOCK.select( 0, mode==SelectMode.SelectRead ? fileDescriptorSet : null, mode==SelectMode.SelectWrite ? fileDescriptorSet : null, mode==SelectMode.SelectError ? fileDescriptorSet : null, IntPtr.Zero); } GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::Poll() UnsafeNclNativeMethods.OSSOCK.select returns socketCount:" + socketCount); // // if the native call fails we'll throw a SocketException // if ((SocketError)socketCount==SocketError.SocketError) { // // update our internal state after this socket error and throw // SocketException socketException = new SocketException(); UpdateStatusAfterSocketError(socketException); if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "Poll", socketException); throw socketException; } if ((int)fileDescriptorSet[0]==0) { return false; } return fileDescriptorSet[1] == handle; }
private void ReadImpl() { List<IntPtr> dead = null, active = new List<IntPtr>(); List<ISocketCallback> activeCallbacks = new List<ISocketCallback>(); IntPtr[] readSockets = EmptyPointers, errorSockets = EmptyPointers; long lastHeartbeat = Environment.TickCount; SocketPair[] allSocketPairs = null; while (true) { managerState = ManagerState.CheckForHeartbeat; active.Clear(); activeCallbacks.Clear(); if (dead != null) dead.Clear(); // this check is actually a pace-maker; sometimes the Timer callback stalls for // extended periods of time, which can cause socket disconnect long now = Environment.TickCount; if (unchecked(now - lastHeartbeat) >= 15000) { managerState = ManagerState.ExecuteHeartbeat; lastHeartbeat = now; lock (socketLookup) { if (allSocketPairs == null || allSocketPairs.Length != socketLookup.Count) allSocketPairs = new SocketPair[socketLookup.Count]; socketLookup.Values.CopyTo(allSocketPairs, 0); } foreach (var pair in allSocketPairs) { var callback = pair.Callback; if (callback != null) try { callback.OnHeartbeat(); } catch { } } } managerState = ManagerState.LocateActiveSockets; lock (socketLookup) { if (isDisposed) return; if (socketLookup.Count == 0) { // if empty, give it a few seconds chance before exiting managerState = ManagerState.NoSocketsPause; Monitor.Wait(socketLookup, TimeSpan.FromSeconds(20)); if (socketLookup.Count == 0) return; // nothing new came in, so exit } managerState = ManagerState.PrepareActiveSockets; foreach (var pair in socketLookup) { var socket = pair.Value.Socket; if (socket.Handle == pair.Key && socket.Connected) if (pair.Value.Socket.Connected) { active.Add(pair.Key); activeCallbacks.Add(pair.Value.Callback); } else { (dead ?? (dead = new List<IntPtr>())).Add(pair.Key); } } if (dead != null && dead.Count != 0) { managerState = ManagerState.CullDeadSockets; foreach (var socket in dead) socketLookup.Remove(socket); } } int pollingSockets = active.Count; if (pollingSockets == 0) { // nobody had actual sockets; just sleep managerState = ManagerState.NoActiveSocketsPause; Thread.Sleep(10); continue; } if (readSockets.Length < active.Count + 1) { managerState = ManagerState.GrowingSocketArray; ConnectionMultiplexer.TraceWithoutContext("Resizing socket array for " + active.Count + " sockets"); readSockets = new IntPtr[active.Count + 6]; // leave so space for growth errorSockets = new IntPtr[active.Count + 6]; } managerState = ManagerState.CopyingPointersForSelect; readSockets[0] = errorSockets[0] = (IntPtr)active.Count; active.CopyTo(readSockets, 1); active.CopyTo(errorSockets, 1); int ready; try { var timeout = new TimeValue(1000); managerState = ManagerState.ExecuteSelect; ready = select(0, readSockets, null, errorSockets, ref timeout); managerState = ManagerState.ExecuteSelectComplete; if (ready <= 0) // -ve typically means a socket was disposed just before; just retry { bool hasWorkToDo = false; if (ready == 0) { managerState = ManagerState.CheckForStaleConnections; foreach (var s in activeCallbacks) { if (s.IsDataAvailable) { hasWorkToDo = true; } else { s.CheckForStaleConnection(); } } } else { lastErrorTicks = Environment.TickCount; } if (!hasWorkToDo) { continue; } } ConnectionMultiplexer.TraceWithoutContext((int)readSockets[0] != 0, "Read sockets: " + (int)readSockets[0]); ConnectionMultiplexer.TraceWithoutContext((int)errorSockets[0] != 0, "Error sockets: " + (int)errorSockets[0]); } catch (Exception ex) { // this typically means a socket was disposed just before; just retry Trace.WriteLine(ex.Message); continue; } bool haveWork = false; int queueCount = (int)readSockets[0]; if (queueCount != 0) { managerState = ManagerState.EnqueueRead; lock (readQueue) { for (int i = 1; i <= queueCount; i++) { var callback = GetCallback(readSockets[i]); if (callback != null) { readQueue.Enqueue(callback); haveWork = true; } } } } queueCount = (int)errorSockets[0]; if (queueCount != 0) { managerState = ManagerState.EnqueueError; lock (errorQueue) { for (int i = 1; i <= queueCount; i++) { var callback = GetCallback(errorSockets[i]); if (callback != null) { errorQueue.Enqueue(callback); haveWork = true; } } } } if(!haveWork) { // edge case: select is returning 0, but data could still be available managerState = ManagerState.EnqueueReadFallback; lock (readQueue) { foreach (var callback in activeCallbacks) { if(callback.IsDataAvailable) { readQueue.Enqueue(callback); } } } } if (ready >= 5) // number of sockets we should attempt to process by ourself before asking for help { // seek help, work in parallel, then synchronize var obj = new QueueDrainSyncLock(this); lock (obj) { managerState = ManagerState.RequestAssistance; ThreadPool.QueueUserWorkItem(HelpProcessItems, obj); managerState = ManagerState.ProcessQueues; ProcessItems(true); if (!obj.Consume()) { // then our worker arrived and picked up work; we need // to let it finish; note that if it *didn't* get that far // yet, the Consume() call will mean that it never tries Monitor.Wait(obj); } } } else { // just do it ourself managerState = ManagerState.ProcessQueues; ProcessItems(true); } } }
/// <include file='doc\Socket.uex' path='docs/doc[@for="Socket.Poll"]/*' /> /// <devdoc> /// <para> /// Determines the status of the socket. /// </para> /// </devdoc> public bool Poll(int microSeconds, SelectMode mode) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } FileDescriptorSet fileDescriptorSet = new FileDescriptorSet(1); fileDescriptorSet.Array[0] = m_Handle; TimeValue IOwait = new TimeValue(); // // negative timeout value implies indefinite wait // if (microSeconds>=0) { MicrosecondsToTimeValue(microSeconds, ref IOwait); } int errorCode; switch (mode) { case SelectMode.SelectRead: errorCode = (microSeconds>=0) ? UnsafeNclNativeMethods.OSSOCK.select( 0, ref fileDescriptorSet, IntPtr.Zero, IntPtr.Zero, ref IOwait) : UnsafeNclNativeMethods.OSSOCK.select( 0, ref fileDescriptorSet, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); break; case SelectMode.SelectWrite: errorCode = (microSeconds>=0) ? UnsafeNclNativeMethods.OSSOCK.select( 0, IntPtr.Zero, ref fileDescriptorSet, IntPtr.Zero, ref IOwait) : UnsafeNclNativeMethods.OSSOCK.select( 0, IntPtr.Zero, ref fileDescriptorSet, IntPtr.Zero, IntPtr.Zero); break; case SelectMode.SelectError: errorCode = (microSeconds>=0) ? UnsafeNclNativeMethods.OSSOCK.select( 0, IntPtr.Zero, IntPtr.Zero, ref fileDescriptorSet, ref IOwait) : UnsafeNclNativeMethods.OSSOCK.select( 0, IntPtr.Zero, IntPtr.Zero, ref fileDescriptorSet, IntPtr.Zero); break; default: throw new NotSupportedException(SR.GetString(SR.net_SelectModeNotSupportedException, mode.ToString())); }; // // if the native call fails we'll throw a SocketException // if (errorCode==SocketErrors.SocketError) { // // update our internal state after this socket error and throw // SocketException socketException = new SocketException(); UpdateStatusAfterSocketError(); throw socketException; } if (fileDescriptorSet.Count==0) { return false; } //return (fileDescriptorSet.Count!=0); return fileDescriptorSet.Array[0]==m_Handle; }
/// <summary> /// Determines the status of one or more sockets. /// </summary> /// <param name="checkRead">An <see cref="T:System.Collections.IList"/> of <see cref="T:System.Net.Sockets.Socket"/> instances to check for readability. </param><param name="checkWrite">An <see cref="T:System.Collections.IList"/> of <see cref="T:System.Net.Sockets.Socket"/> instances to check for writability. </param><param name="checkError">An <see cref="T:System.Collections.IList"/> of <see cref="T:System.Net.Sockets.Socket"/> instances to check for errors. </param><param name="microSeconds">The time-out value, in microseconds. A -1 value indicates an infinite time-out.</param><exception cref="T:System.ArgumentNullException">The <paramref name="checkRead"/> parameter is null or empty.-and- The <paramref name="checkWrite"/> parameter is null or empty -and- The <paramref name="checkError"/> parameter is null or empty. </exception><exception cref="T:System.Net.Sockets.SocketException">An error occurred when attempting to access the socket. See the Remarks section for more information. </exception> public static void Select(IList checkRead, IList checkWrite, IList checkError, int microSeconds) { if ((checkRead == null || checkRead.Count == 0) && (checkWrite == null || checkWrite.Count == 0) && (checkError == null || checkError.Count == 0)) throw new ArgumentNullException(SR.GetString("net_sockets_empty_select")); if (checkRead != null && checkRead.Count > 65536) throw new ArgumentOutOfRangeException("checkRead", SR.GetString("net_sockets_toolarge_select", (object) "checkRead", (object) 65536.ToString((IFormatProvider) NumberFormatInfo.CurrentInfo))); else if (checkWrite != null && checkWrite.Count > 65536) throw new ArgumentOutOfRangeException("checkWrite", SR.GetString("net_sockets_toolarge_select", (object) "checkWrite", (object) 65536.ToString((IFormatProvider) NumberFormatInfo.CurrentInfo))); else if (checkError != null && checkError.Count > 65536) { throw new ArgumentOutOfRangeException("checkError", SR.GetString("net_sockets_toolarge_select", (object) "checkError", (object) 65536.ToString((IFormatProvider) NumberFormatInfo.CurrentInfo))); } else { IntPtr[] numArray1 = Socket.SocketListToFileDescriptorSet(checkRead); IntPtr[] numArray2 = Socket.SocketListToFileDescriptorSet(checkWrite); IntPtr[] numArray3 = Socket.SocketListToFileDescriptorSet(checkError); int num; if (microSeconds != -1) { TimeValue timeValue = new TimeValue(); Socket.MicrosecondsToTimeValue((long) (uint) microSeconds, ref timeValue); num = UnsafeNclNativeMethods.OSSOCK.select(0, numArray1, numArray2, numArray3, ref timeValue); } else num = UnsafeNclNativeMethods.OSSOCK.select(0, numArray1, numArray2, numArray3, IntPtr.Zero); if (num == -1) throw new SocketException(); Socket.SelectFileDescriptor(checkRead, numArray1); Socket.SelectFileDescriptor(checkWrite, numArray2); Socket.SelectFileDescriptor(checkError, numArray3); } }
/// <summary> /// Determines the status of the <see cref="T:System.Net.Sockets.Socket"/>. /// </summary> /// /// <returns> /// The status of the <see cref="T:System.Net.Sockets.Socket"/> based on the polling mode value passed in the <paramref name="mode"/> parameter.Mode Return Value <see cref="F:System.Net.Sockets.SelectMode.SelectRead"/>true if <see cref="M:System.Net.Sockets.Socket.Listen(System.Int32)"/> has been called and a connection is pending; -or- true if data is available for reading; -or- true if the connection has been closed, reset, or terminated; otherwise, returns false. <see cref="F:System.Net.Sockets.SelectMode.SelectWrite"/>true, if processing a <see cref="M:System.Net.Sockets.Socket.Connect(System.Net.EndPoint)"/>, and the connection has succeeded; -or- true if data can be sent; otherwise, returns false. <see cref="F:System.Net.Sockets.SelectMode.SelectError"/>true if processing a <see cref="M:System.Net.Sockets.Socket.Connect(System.Net.EndPoint)"/> that does not block, and the connection has failed; -or- true if <see cref="F:System.Net.Sockets.SocketOptionName.OutOfBandInline"/> is not set and out-of-band data is available; otherwise, returns false. /// </returns> /// <param name="microSeconds">The time to wait for a response, in microseconds. </param><param name="mode">One of the <see cref="T:System.Net.Sockets.SelectMode"/> values. </param><exception cref="T:System.NotSupportedException">The <paramref name="mode"/> parameter is not one of the <see cref="T:System.Net.Sockets.SelectMode"/> values. </exception><exception cref="T:System.Net.Sockets.SocketException">An error occurred when attempting to access the socket. See remarks below. </exception><exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.Socket"/> has been closed. </exception><PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/></PermissionSet> public bool Poll(int microSeconds, SelectMode mode) { if (this.CleanedUp) throw new ObjectDisposedException(this.GetType().FullName); IntPtr handle = this.m_Handle.DangerousGetHandle(); IntPtr[] numArray = new IntPtr[2] { (IntPtr) 1, handle }; TimeValue timeValue = new TimeValue(); int num; if (microSeconds != -1) { Socket.MicrosecondsToTimeValue((long) (uint) microSeconds, ref timeValue); num = UnsafeNclNativeMethods.OSSOCK.select(0, mode == SelectMode.SelectRead ? numArray : (IntPtr[]) null, mode == SelectMode.SelectWrite ? numArray : (IntPtr[]) null, mode == SelectMode.SelectError ? numArray : (IntPtr[]) null, ref timeValue); } else num = UnsafeNclNativeMethods.OSSOCK.select(0, mode == SelectMode.SelectRead ? numArray : (IntPtr[]) null, mode == SelectMode.SelectWrite ? numArray : (IntPtr[]) null, mode == SelectMode.SelectError ? numArray : (IntPtr[]) null, IntPtr.Zero); if (num == -1) { SocketException socketException = new SocketException(); this.UpdateStatusAfterSocketError(socketException); if (Socket.s_LoggingEnabled) Logging.Exception(Logging.Sockets, (object) this, "Poll", (Exception) socketException); throw socketException; } else if ((int) numArray[0] == 0) return false; else return numArray[1] == handle; }
/// <devdoc> /// <para>Determines the status of a socket.</para> /// </devdoc> public static void Select(IList checkRead, IList checkWrite, IList checkError, int microSeconds) { // parameter validation if ((checkRead==null || checkRead.Count==0) && (checkWrite==null || checkWrite.Count==0) && (checkError==null || checkError.Count==0)) { throw new ArgumentNullException(SR.GetString(SR.net_sockets_empty_select)); } const int MaxSelect = 65536; if (checkRead!=null && checkRead.Count>MaxSelect) { throw new ArgumentOutOfRangeException(SR.GetString(SR.net_sockets_toolarge_select, "checkRead", MaxSelect.ToString(NumberFormatInfo.CurrentInfo))); } if (checkWrite!=null && checkWrite.Count>MaxSelect) { throw new ArgumentOutOfRangeException(SR.GetString(SR.net_sockets_toolarge_select, "checkWrite", MaxSelect.ToString(NumberFormatInfo.CurrentInfo))); } if (checkError!=null && checkError.Count>MaxSelect) { throw new ArgumentOutOfRangeException(SR.GetString(SR.net_sockets_toolarge_select, "checkError", MaxSelect.ToString(NumberFormatInfo.CurrentInfo))); } IntPtr[] readfileDescriptorSet = SocketListToFileDescriptorSet(checkRead); IntPtr[] writefileDescriptorSet = SocketListToFileDescriptorSet(checkWrite); IntPtr[] errfileDescriptorSet = SocketListToFileDescriptorSet(checkError); TimeValue IOwait = new TimeValue(); // if negative, assume infinite if (microSeconds != -1) { MicrosecondsToTimeValue((long)(uint)microSeconds, ref IOwait); } int socketCount = UnsafeNclNativeMethods.OSSOCK.select( 0, // ignored value readfileDescriptorSet, writefileDescriptorSet, errfileDescriptorSet, ref IOwait); GlobalLog.Print("Socket::Select() UnsafeNclNativeMethods.OSSOCK.select returns socketCount:" + socketCount); // // if the native call fails we'll throw a SocketException // if ((SocketError)socketCount==SocketError.SocketError) { throw new SocketException(); } SelectFileDescriptor(checkRead, readfileDescriptorSet); SelectFileDescriptor(checkWrite, writefileDescriptorSet); SelectFileDescriptor(checkError, errfileDescriptorSet); }
public static void Select(IList checkRead, IList checkWrite, IList checkError, int microSeconds) { int num; if ((((checkRead == null) || (checkRead.Count == 0)) && ((checkWrite == null) || (checkWrite.Count == 0))) && ((checkError == null) || (checkError.Count == 0))) { throw new ArgumentNullException(SR.GetString("net_sockets_empty_select")); } if ((checkRead != null) && (checkRead.Count > 0x10000)) { object[] args = new object[] { "checkRead", 0x10000.ToString(NumberFormatInfo.CurrentInfo) }; throw new ArgumentOutOfRangeException("checkRead", SR.GetString("net_sockets_toolarge_select", args)); } if ((checkWrite != null) && (checkWrite.Count > 0x10000)) { object[] objArray2 = new object[] { "checkWrite", 0x10000.ToString(NumberFormatInfo.CurrentInfo) }; throw new ArgumentOutOfRangeException("checkWrite", SR.GetString("net_sockets_toolarge_select", objArray2)); } if ((checkError != null) && (checkError.Count > 0x10000)) { object[] objArray3 = new object[] { "checkError", 0x10000.ToString(NumberFormatInfo.CurrentInfo) }; throw new ArgumentOutOfRangeException("checkError", SR.GetString("net_sockets_toolarge_select", objArray3)); } IntPtr[] readfds = SocketListToFileDescriptorSet(checkRead); IntPtr[] writefds = SocketListToFileDescriptorSet(checkWrite); IntPtr[] exceptfds = SocketListToFileDescriptorSet(checkError); if (microSeconds != -1) { TimeValue socketTime = new TimeValue(); MicrosecondsToTimeValue((long) ((ulong) microSeconds), ref socketTime); num = UnsafeNclNativeMethods.OSSOCK.select(0, readfds, writefds, exceptfds, ref socketTime); } else { num = UnsafeNclNativeMethods.OSSOCK.select(0, readfds, writefds, exceptfds, IntPtr.Zero); } if (num == -1) { throw new SocketException(); } SelectFileDescriptor(checkRead, readfds); SelectFileDescriptor(checkWrite, writefds); SelectFileDescriptor(checkError, exceptfds); }
public bool Poll(int microSeconds, SelectMode mode) { int num; if (this.CleanedUp) { throw new ObjectDisposedException(base.GetType().FullName); } IntPtr handle = this.m_Handle.DangerousGetHandle(); IntPtr[] ptrArray = new IntPtr[] { (IntPtr) 1, handle }; TimeValue socketTime = new TimeValue(); if (microSeconds != -1) { MicrosecondsToTimeValue((long) ((ulong) microSeconds), ref socketTime); num = UnsafeNclNativeMethods.OSSOCK.select(0, (mode == SelectMode.SelectRead) ? ptrArray : null, (mode == SelectMode.SelectWrite) ? ptrArray : null, (mode == SelectMode.SelectError) ? ptrArray : null, ref socketTime); } else { num = UnsafeNclNativeMethods.OSSOCK.select(0, (mode == SelectMode.SelectRead) ? ptrArray : null, (mode == SelectMode.SelectWrite) ? ptrArray : null, (mode == SelectMode.SelectError) ? ptrArray : null, IntPtr.Zero); } if (num == -1) { SocketException socketException = new SocketException(); this.UpdateStatusAfterSocketError(socketException); if (s_LoggingEnabled) { Logging.Exception(Logging.Sockets, this, "Poll", socketException); } throw socketException; } if (((int) ptrArray[0]) == 0) { return false; } return (ptrArray[1] == handle); }