예제 #1
0
        /// <summary>
        /// Handles a received packet.
        /// </summary>
        /// <param name="asyncResult">The result of the async operation.</param>
        private void ReceiveFromHandler(IAsyncResult asyncResult)
        {
            try
            {
                NetworkBuffer buffer = this.EndReceiveFrom(asyncResult);
                SCTPPacket    packet = SCTPPacket.FromArray(buffer.Buffer, 0, buffer.BytesReceived);
                if (packet != null)
                {
                    packet.ReceivedFrom = buffer.ReceivedFrom;
                    this.sctpSocket.ProcessInboundPacket(packet);
                }

                this.BeginReceiveFrom();
            }
            catch (SocketException ex)
            {
                if (ex.ErrorCode == 10040)
                {
                    // Message too long.
                    // reduce mtu...
                }

                sctpSocket.WriteConsole(ConsoleColor.Red, ex.ToString());
                Environment.FailFast("-------------------------", ex);
            }
            catch (Exception ex)
            {
                sctpSocket.WriteConsole(ConsoleColor.Red, ex.ToString());
                Environment.FailFast("-------------------------", ex);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private IAsyncResult BeginReceiveFrom()
        {
            NetworkBuffer    buffer  = new NetworkBuffer(this.socket, this.mtu);
            AsyncReceiveFrom asyncOp = new AsyncReceiveFrom(buffer, ReceiveFromHandler);

            asyncOp.BeginReceiveFrom(SocketFlags.None);
            return(asyncOp);
        }
예제 #3
0
        /// <summary>
        /// Sends the packet to the end point.
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="destinationAddress"></param>
        internal void SendPacket(SCTPPacket packet, IPEndPoint destinationAddress)
        {
            NetworkBuffer buffer = new NetworkBuffer(this.socket, packet.ToArray());

            buffer.SendTo(SocketFlags.None, destinationAddress);

            // Increment the flight size.
            Interlocked.Increment(ref this.flightSize);
        }