Ejemplo n.º 1
0
		private void DoBeginAccept(Socket acceptSocket, int receiveSize, AcceptOverlappedAsyncResult asyncResult)
		{
			if (this.m_RightEndPoint == null)
			{
				throw new InvalidOperationException("net_sockets_mustbind");
			}
			if (!this.isListening)
			{
				throw new InvalidOperationException("net_sockets_mustlisten");
			}
			if (acceptSocket == null)
			{
				acceptSocket = new Socket(this.addressFamily, this.socketType, this.protocolType);
			}
			else
			{
				if (acceptSocket.m_RightEndPoint != null)
				{
					throw new InvalidOperationException("net_sockets_namedmustnotbebound");
				}
			}
			asyncResult.AcceptSocket = acceptSocket;
			int num = this.m_RightEndPoint.Serialize().Size + 16;
			byte[] buffer = new byte[receiveSize + num * 2];
			asyncResult.SetUnmanagedStructures(buffer, num);
			SocketError socketError = SocketError.Success;
			int num2;
			if (!this.AcceptEx(this.m_Handle, acceptSocket.m_Handle, Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult.Buffer, 0), receiveSize, num, num, out num2, asyncResult.OverlappedHandle))
			{
				socketError = (SocketError)Marshal.GetLastWin32Error();
			}
			socketError = asyncResult.CheckAsyncCallOverlappedResult(socketError);
			if (socketError != SocketError.Success)
			{
				SocketException ex = new SocketException(socketError);
				this.UpdateStatusAfterSocketError(ex); 
				throw ex;
			}
		}
Ejemplo n.º 2
0
		/// <summary>Begins an asynchronous operation to accept an incoming connection attempt from a specified socket and receives the first block of data sent by the client application.</summary>
		/// <returns>An <see cref="T:System.IAsyncResult" /> object that references the asynchronous <see cref="T:namespace SockCel.Socket" /> object creation.</returns>
		/// <param name="acceptSocket">The accepted <see cref="T:namespace SockCel.Socket" /> object. This value may be null. </param>
		/// <param name="receiveSize">The maximum number of bytes to receive. </param>
		/// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate. </param>
		/// <param name="state">An object that contains state information for this request. </param>
		/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:namespace SockCel.Socket" /> object has been closed. </exception>
		/// <exception cref="T:System.NotSupportedException">Windows NT is required for this method. </exception>
		/// <exception cref="T:System.InvalidOperationException">The accepting socket is not listening for connections. You must call <see cref="M:namespace SockCel.Socket.Bind(System.Net.EndPoint)" /> and <see cref="M:namespace SockCel.Socket.Listen(System.Int32)" /> before calling <see cref="M:namespace SockCel.Socket.BeginAccept(System.AsyncCallback,System.Object)" />.-or- The accepted socket is bound. </exception>
		/// <exception cref="T:System.ArgumentOutOfRangeException">
		///   <paramref name="receiveSize" /> is less than 0. </exception>
		/// <exception cref="T:namespace SockCel.SocketException">An error occurred when attempting to access the socket. See the Remarks section for more information. </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 IAsyncResult BeginAccept(Socket acceptSocket, int receiveSize, AsyncCallback callback, object state)
		{
			if (this.CleanedUp)
			{
				throw new ObjectDisposedException(base.GetType().FullName);
			}
			if (receiveSize < 0)
			{
				throw new ArgumentOutOfRangeException("size");
			}
			AcceptOverlappedAsyncResult acceptOverlappedAsyncResult = new AcceptOverlappedAsyncResult(this, state, callback);
			acceptOverlappedAsyncResult.StartPostingAsyncOp(false);
			this.DoBeginAccept(acceptSocket, receiveSize, acceptOverlappedAsyncResult);
			acceptOverlappedAsyncResult.FinishPostingAsyncOp();
			return acceptOverlappedAsyncResult;
		}