コード例 #1
0
ファイル: Socket.cs プロジェクト: ReedKimble/corefx
        internal IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
        {
            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "BeginReceive", "");
            }

            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Validate input parameters.
            if (buffers == null)
            {
                throw new ArgumentNullException("buffers");
            }

            if (buffers.Count == 0)
            {
                throw new ArgumentException(SR.Format(SR.net_sockets_zerolist, "buffers"), "buffers");
            }

            // We need to flow the context here.  But we don't need to lock the context - we don't use it until the callback.
            OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Run the receive with this asyncResult.
            errorCode = DoBeginReceive(buffers, socketFlags, asyncResult);

            if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
            {
                asyncResult = null;
            }
            else
            {
                // We're not throwing, so finish the async op posting code so we can return to the user.
                // If the operation already finished, the callback will be called from here.
                asyncResult.FinishPostingAsyncOp(ref Caches.ReceiveClosureCache);
            }

            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "BeginReceive", asyncResult);
            }
            return asyncResult;
        }
コード例 #2
0
ファイル: Socket.cs プロジェクト: ReedKimble/corefx
        // Routine Description:
        // 
        //    BeginReceiveFrom - Async implimentation of RecvFrom call,
        // 
        //    Called when we want to start an async receive.
        //    We kick off the receive, and if it completes synchronously we'll
        //    call the callback. Otherwise we'll return an IASyncResult, which
        //    the caller can use to wait on or retrieve the final status, as needed.
        // 
        //    Uses Winsock 2 overlapped I/O.
        // 
        // Arguments:
        // 
        //    ReadBuffer - status line that we wish to parse
        //    Index - Offset into ReadBuffer to begin reading from
        //    Request - Size of Buffer to recv
        //    Flags - Additonal Flags that may be passed to the underlying winsock call
        //    remoteEP - EndPoint that are to receive from
        //    Callback - Delegate function that holds callback, called on completeion of I/O
        //    State - State used to track callback, set by caller, not required
        // 
        // Return Value:
        // 
        //    IAsyncResult - Async result used to retreive result
        internal IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state)
        {
            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "BeginReceiveFrom", "");
            }

            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Validate input parameters.
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (remoteEP == null)
            {
                throw new ArgumentNullException("remoteEP");
            }
            if (!CanTryAddressFamily(remoteEP.AddressFamily))
            {
                throw new ArgumentException(SR.Format(SR.net_InvalidEndPointAddressFamily, remoteEP.AddressFamily, _addressFamily), "remoteEP");
            }
            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (size < 0 || size > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException("size");
            }
            if (_rightEndPoint == null)
            {
                throw new InvalidOperationException(SR.net_sockets_mustbind);
            }

            // We don't do a CAS demand here because the contents of remoteEP aren't used by
            // WSARecvFrom; all that matters is that we generate a unique-to-this-call SocketAddress
            // with the right address family
            Internals.SocketAddress socketAddress = SnapshotAndSerialize(ref remoteEP);

            // Set up the result and set it to collect the context.
            OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Start the ReceiveFrom.
            DoBeginReceiveFrom(buffer, offset, size, socketFlags, remoteEP, socketAddress, asyncResult);

            // Capture the context, maybe call the callback, and return.
            asyncResult.FinishPostingAsyncOp(ref Caches.ReceiveClosureCache);

            if (asyncResult.CompletedSynchronously && !asyncResult.SocketAddressOriginal.Equals(asyncResult.SocketAddress))
            {
                try
                {
                    remoteEP = remoteEP.Create(asyncResult.SocketAddress);
                }
                catch
                {
                }
            }


            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "BeginReceiveFrom", asyncResult);
            }
            return asyncResult;
        }
コード例 #3
0
ファイル: Socket.cs プロジェクト: ReedKimble/corefx
        // Routine Description:
        // 
        //    BeginSendTo - Async implimentation of SendTo,
        // 
        //    This routine may go pending at which time,
        //    but any case the callback Delegate will be called upon completion
        // 
        // Arguments:
        // 
        //    WriteBuffer - Buffer to transmit
        //    Index - Offset into WriteBuffer to begin sending from
        //    Size - Size of Buffer to transmit
        //    Flags - Specific Socket flags to pass to winsock
        //    remoteEP - EndPoint to transmit To
        //    Callback - Delegate function that holds callback, called on completeion of I/O
        //    State - State used to track callback, set by caller, not required
        // 
        // Return Value:
        // 
        //    IAsyncResult - Async result used to retreive result
        internal IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback callback, object state)
        {
            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "BeginSendTo", "");
            }

            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Validate input parameters.
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (remoteEP == null)
            {
                throw new ArgumentNullException("remoteEP");
            }
            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (size < 0 || size > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException("size");
            }

            // This will check the permissions for connect.
            EndPoint endPointSnapshot = remoteEP;
            Internals.SocketAddress socketAddress = CheckCacheRemote(ref endPointSnapshot, false);

            // Set up the async result and indicate to flow the context.
            OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Post the send.
            DoBeginSendTo(buffer, offset, size, socketFlags, endPointSnapshot, socketAddress, asyncResult);

            // Finish, possibly posting the callback.  The callback won't be posted before this point is reached.
            asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);

            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "BeginSendTo", asyncResult);
            }
            return asyncResult;
        }
コード例 #4
0
ファイル: Socket.cs プロジェクト: ReedKimble/corefx
        internal IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
        {
            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "BeginReceive", "");
            }

            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Validate input parameters.
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (size < 0 || size > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException("size");
            }

            // We need to flow the context here.  But we don't need to lock the context - we don't use it until the callback.
            OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Run the receive with this asyncResult.
            errorCode = DoBeginReceive(buffer, offset, size, socketFlags, asyncResult);

            if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
            {
                asyncResult = null;
            }
            else
            {
                // We're not throwing, so finish the async op posting code so we can return to the user.
                // If the operation already finished, the callback will be called from here.
                asyncResult.FinishPostingAsyncOp(ref Caches.ReceiveClosureCache);
            }

            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "BeginReceive", asyncResult);
            }
            return asyncResult;
        }
コード例 #5
0
ファイル: Socket.cs プロジェクト: korifey/hackathon-Ideaphone
 internal IAsyncResult BeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
 {
     OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
       asyncResult.StartPostingAsyncOp(false);
       this.DoBeginMultipleSend(buffers, socketFlags, asyncResult);
       asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
       return (IAsyncResult) asyncResult;
 }
コード例 #6
0
ファイル: Socket.cs プロジェクト: REALTOBIZ/mono
        internal IAsyncResult BeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state) {
            // Set up the async result and start the flow.
            OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Start the send.
            DoBeginMultipleSend(buffers, socketFlags, asyncResult);

            // Finish it up (capture, complete).
            asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
            return asyncResult;
        }
コード例 #7
0
ファイル: Socket.cs プロジェクト: korifey/hackathon-Ideaphone
 public IAsyncResult BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginSend", "");
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       if (buffers == null)
     throw new ArgumentNullException("buffers");
       if (buffers.Count == 0)
       {
     throw new ArgumentException(SR.GetString("net_sockets_zerolist", new object[1]
     {
       (object) "buffers"
     }), "buffers");
       }
       else
       {
     OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
     asyncResult.StartPostingAsyncOp(false);
     errorCode = this.DoBeginSend(buffers, socketFlags, asyncResult);
     asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
     if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
       asyncResult = (OverlappedAsyncResult) null;
     if (Socket.s_LoggingEnabled)
       Logging.Exit(Logging.Sockets, (object) this, "BeginSend", (object) asyncResult);
     return (IAsyncResult) asyncResult;
       }
 }
コード例 #8
0
ファイル: Socket.cs プロジェクト: korifey/hackathon-Ideaphone
 public IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback callback, object state)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginSendTo", "");
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       if (buffer == null)
     throw new ArgumentNullException("buffer");
       if (remoteEP == null)
     throw new ArgumentNullException("remoteEP");
       if (offset < 0 || offset > buffer.Length)
     throw new ArgumentOutOfRangeException("offset");
       if (size < 0 || size > buffer.Length - offset)
     throw new ArgumentOutOfRangeException("size");
       EndPoint remoteEP1 = remoteEP;
       SocketAddress socketAddress = this.CheckCacheRemote(ref remoteEP1, false);
       OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
       asyncResult.StartPostingAsyncOp(false);
       this.DoBeginSendTo(buffer, offset, size, socketFlags, remoteEP1, socketAddress, asyncResult);
       asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
       if (Socket.s_LoggingEnabled)
     Logging.Exit(Logging.Sockets, (object) this, "BeginSendTo", (object) asyncResult);
       return (IAsyncResult) asyncResult;
 }
コード例 #9
0
ファイル: Socket.cs プロジェクト: korifey/hackathon-Ideaphone
 public IAsyncResult BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginSend", "");
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       if (buffer == null)
     throw new ArgumentNullException("buffer");
       if (offset < 0 || offset > buffer.Length)
     throw new ArgumentOutOfRangeException("offset");
       if (size < 0 || size > buffer.Length - offset)
     throw new ArgumentOutOfRangeException("size");
       OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
       asyncResult.StartPostingAsyncOp(false);
       errorCode = this.DoBeginSend(buffer, offset, size, socketFlags, asyncResult);
       if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
     asyncResult = (OverlappedAsyncResult) null;
       else
     asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
       if (Socket.s_LoggingEnabled)
     Logging.Exit(Logging.Sockets, (object) this, "BeginSend", (object) asyncResult);
       return (IAsyncResult) asyncResult;
 }
コード例 #10
0
ファイル: Socket.cs プロジェクト: korifey/hackathon-Ideaphone
 public IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginReceiveFrom", "");
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       if (buffer == null)
     throw new ArgumentNullException("buffer");
       if (remoteEP == null)
     throw new ArgumentNullException("remoteEP");
       if (!this.CanTryAddressFamily(remoteEP.AddressFamily))
       {
     throw new ArgumentException(SR.GetString("net_InvalidEndPointAddressFamily", (object) remoteEP.AddressFamily, (object) this.addressFamily), "remoteEP");
       }
       else
       {
     if (offset < 0 || offset > buffer.Length)
       throw new ArgumentOutOfRangeException("offset");
     if (size < 0 || size > buffer.Length - offset)
       throw new ArgumentOutOfRangeException("size");
     if (this.m_RightEndPoint == null)
       throw new InvalidOperationException(SR.GetString("net_sockets_mustbind"));
     SocketAddress socketAddress = this.SnapshotAndSerialize(ref remoteEP);
     OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
     asyncResult.StartPostingAsyncOp(false);
     this.DoBeginReceiveFrom(buffer, offset, size, socketFlags, remoteEP, socketAddress, asyncResult);
     asyncResult.FinishPostingAsyncOp(ref this.Caches.ReceiveClosureCache);
     if (asyncResult.CompletedSynchronously)
     {
       if (!asyncResult.SocketAddressOriginal.Equals((object) asyncResult.SocketAddress))
       {
     try
     {
       remoteEP = remoteEP.Create(asyncResult.SocketAddress);
     }
     catch
     {
     }
       }
     }
     if (Socket.s_LoggingEnabled)
       Logging.Exit(Logging.Sockets, (object) this, "BeginReceiveFrom", (object) asyncResult);
     return (IAsyncResult) asyncResult;
       }
 }
コード例 #11
0
ファイル: socket.cs プロジェクト: svermeulen/iris
        public IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state)
        {
            if (Logging.On) Logging.Enter(Logging.Sockets, this, "BeginReceiveFrom", "");

            if (CleanedUp) {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            //
            // parameter validation
            //
            if (buffer==null) {
                throw new ArgumentNullException("buffer");
            }
            if (remoteEP==null) {
                throw new ArgumentNullException("remoteEP");
            }
            if (offset<0 || offset>buffer.Length) {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (size<0 || size>buffer.Length-offset) {
                throw new ArgumentOutOfRangeException("size");
            }
            if (m_RightEndPoint==null) {
                throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustbind));
            }

            // This will check the permissions for connect.
            EndPoint endPointSnapshot = remoteEP;
            SocketAddress socketAddress = CheckCacheRemote(ref endPointSnapshot, false);

            // Set up the result and set it to collect the context.
            OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Start the ReceiveFrom.
            DoBeginReceiveFrom(buffer, offset, size, socketFlags, endPointSnapshot, socketAddress, asyncResult);

            // Capture the context, maybe call the callback, and return.
            asyncResult.FinishPostingAsyncOp(ref Caches.ReceiveClosureCache);

            if (asyncResult.CompletedSynchronously && !asyncResult.SocketAddressOriginal.Equals(asyncResult.SocketAddress)) {
                try {
                    remoteEP = endPointSnapshot.Create(asyncResult.SocketAddress);
                }
                catch {
                }
            }

            if(Logging.On)Logging.Exit(Logging.Sockets, this, "BeginReceiveFrom", asyncResult);
            return asyncResult;
        }
コード例 #12
0
 public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
 {
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "BeginReceive", "");
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if ((offset < 0) || (offset > buffer.Length))
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     if ((size < 0) || (size > (buffer.Length - offset)))
     {
         throw new ArgumentOutOfRangeException("size");
     }
     OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
     asyncResult.StartPostingAsyncOp(false);
     errorCode = this.DoBeginReceive(buffer, offset, size, socketFlags, asyncResult);
     if ((errorCode != SocketError.Success) && (errorCode != SocketError.IOPending))
     {
         asyncResult = null;
     }
     else
     {
         asyncResult.FinishPostingAsyncOp(ref this.Caches.ReceiveClosureCache);
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "BeginReceive", asyncResult);
     }
     return asyncResult;
 }
コード例 #13
0
 public IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
 {
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "BeginReceive", "");
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (buffers == null)
     {
         throw new ArgumentNullException("buffers");
     }
     if (buffers.Count == 0)
     {
         throw new ArgumentException(SR.GetString("net_sockets_zerolist", new object[] { "buffers" }), "buffers");
     }
     OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
     asyncResult.StartPostingAsyncOp(false);
     errorCode = this.DoBeginReceive(buffers, socketFlags, asyncResult);
     if ((errorCode != SocketError.Success) && (errorCode != SocketError.IOPending))
     {
         asyncResult = null;
     }
     else
     {
         asyncResult.FinishPostingAsyncOp(ref this.Caches.ReceiveClosureCache);
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "BeginReceive", asyncResult);
     }
     return asyncResult;
 }