Example #1
0
        protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation)
        {
            var args = new MySocketAsyncEventArgs();

            args.SetBuffer(bytes, offset, length);
            args.UserToken  = asyncContinuation;
            args.Completed += this.SocketOperationCompleted;

            lock (this)
            {
                if (this.MaxQueueSize != 0 && this.pendingRequests.Count >= this.MaxQueueSize)
                {
                    var dequeued = this.pendingRequests.Dequeue();

                    if (dequeued != null)
                    {
                        dequeued.Dispose();
                    }
                }

                this.pendingRequests.Enqueue(args);
            }

            this.ProcessNextQueuedItem();
        }
Example #2
0
        protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation)
        {
            var args = new MySocketAsyncEventArgs();

            args.SetBuffer(bytes, offset, length);
            args.UserToken  = asyncContinuation;
            args.Completed += SocketOperationCompleted;

            lock (this)
            {
                pendingRequests.Enqueue(args);
            }

            ProcessNextQueuedItem();
        }
Example #3
0
        protected override void DoInitialize()
        {
            var args = new MySocketAsyncEventArgs();

            args.RemoteEndPoint = ParseEndpointAddress(new Uri(Address), AddressFamily);
            args.Completed     += SocketOperationCompleted;
            args.UserToken      = null;

            _socket = CreateSocket(args.RemoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _asyncOperationInProgress = true;

            if (!_socket.ConnectAsync(args))
            {
                SocketOperationCompleted(_socket, args);
            }
        }
Example #4
0
        protected override void DoInitialize()
        {
            var uri  = new Uri(Address);
            var args = new MySocketAsyncEventArgs();

            args.RemoteEndPoint = ParseEndpointAddress(new Uri(Address), AddressFamily);
            args.Completed     += _socketOperationCompleted;
            args.UserToken      = null;

            _socket = CreateSocket(uri.Host, args.RemoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            base.BeginInitialize();

            bool asyncOperation = false;

            try
            {
                asyncOperation = _socket.ConnectAsync(args);
            }
            catch (SocketException ex)
            {
                args.SocketError = ex.SocketErrorCode;
            }
            catch (Exception ex)
            {
                if (ex.InnerException is SocketException socketException)
                {
                    args.SocketError = socketException.SocketErrorCode;
                }
                else
                {
                    args.SocketError = SocketError.OperationAborted;
                }
            }

            if (!asyncOperation)
            {
                SocketOperationCompleted(_socket, args);
            }
        }
Example #5
0
        protected override void BeginRequest(NetworkRequestArgs eventArgs)
        {
            var args = new MySocketAsyncEventArgs();

            args.SetBuffer(eventArgs.RequestBuffer, eventArgs.RequestBufferOffset, eventArgs.RequestBufferLength);
            args.UserToken  = eventArgs.AsyncContinuation;
            args.Completed += _socketOperationCompleted;

            bool asyncOperation = false;

            try
            {
                asyncOperation = _socket.SendAsync(args);
            }
            catch (SocketException ex)
            {
                InternalLogger.Error(ex, "NetworkTarget: Error sending tcp request");
                args.SocketError = ex.SocketErrorCode;
            }
            catch (Exception ex)
            {
                InternalLogger.Error(ex, "NetworkTarget: Error sending tcp request");
                if (ex.InnerException is SocketException socketException)
                {
                    args.SocketError = socketException.SocketErrorCode;
                }
                else
                {
                    args.SocketError = SocketError.OperationAborted;
                }
            }

            if (!asyncOperation)
            {
                SocketOperationCompleted(_socket, args);
            }
        }
Example #6
0
        protected override void DoInitialize()
        {
            var args = new MySocketAsyncEventArgs();
            args.RemoteEndPoint = this.ParseEndpointAddress(new Uri(this.Address), this.AddressFamily);
            args.Completed += this.SocketOperationCompleted;
            args.UserToken = null;

            this.socket = this.CreateSocket(args.RemoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this.asyncOperationInProgress = true;

            if (!this.socket.ConnectAsync(args))
            {
                this.SocketOperationCompleted(this.socket, args);
            }
        }
Example #7
0
        protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation)
        {
            var args = new MySocketAsyncEventArgs();
            args.SetBuffer(bytes, offset, length);
            args.UserToken = asyncContinuation;
            args.Completed += this.SocketOperationCompleted;

            lock (this)
            {
                if (this.MaxQueueSize != 0 && this.pendingRequests.Count >= this.MaxQueueSize)
                {
                    var dequeued = this.pendingRequests.Dequeue();

                    if (dequeued != null)
                    {
                        dequeued.Dispose();
                    }
                }

                this.pendingRequests.Enqueue(args);
            }

            this.ProcessNextQueuedItem();
        }
        protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation)
        {
            var args = new MySocketAsyncEventArgs();
            args.SetBuffer(bytes, offset, length);
            args.UserToken = asyncContinuation;
            args.Completed += this.SocketOperationCompleted;

            lock (this)
            {
                this.pendingRequests.Enqueue(args);
            }

            this.ProcessNextQueuedItem();
        }