/// <summary>
        /// expect packet from transport.
        /// </summary>
        /// <param name="buffer">
        /// a BytesBuffer object that contains the received data from endpoint.
        /// </param>
        /// <param name="decoder">
        /// a DecodePacketCallback delegate that is used to decode packet from buffer.
        /// </param>
        /// <param name="endpoint">
        /// an object that specifies the endpoint for decoder.<para/>
        /// remember: this endpoint must be the endpoint that is returned to the user,
        /// that is the endpoint return by Connect().
        /// </param>
        /// <param name="timeout">
        /// a TimeSpan object that indicates the timeout to expect event.
        /// </param>
        /// <param name="packetCache">
        /// a list that contains the stackpackets.
        /// </param>
        /// <returns>
        /// a StackPacket object that specifies the received packet.
        /// </returns>
        public static StackPacket Visit(
            BytesBuffer buffer, DecodePacketCallback decoder, object endpoint,
            TimeSpan timeout, SyncFilterQueue <StackPacket> packetCache)
        {
            // get the packet in packet list.
            if (packetCache.Count > 0)
            {
                return(Utility.GetOne <StackPacket>(packetCache, null));
            }

            // the consumed length of decoder.
            int consumedLength = 0;

            // decode packet, return null or at least one packet.
            StackPacket[] packets = ExpectMultiPacketsVisitor.Visit(
                buffer, decoder, endpoint, timeout, out consumedLength);

            // packet is null, buffer is closed, no packet will come.
            if (packets == null)
            {
                return(null);
            }

            // if packet arrived, add to packet list, and return the first.
            foreach (StackPacket packet in packets)
            {
                packetCache.Enqueue(packet);
            }

            return(Utility.GetOne <StackPacket>(packetCache, null));
        }
Beispiel #2
0
        public StackPacket[] ExpectPacket(TimeSpan timeout, out int consumedLength)
        {
            ValidateConnectionDisposed();

            return(ExpectMultiPacketsVisitor.Visit(
                       this.buffer, this.server.Decoder, this.remoteEndPoint, timeout, out consumedLength));
        }
Beispiel #3
0
        /// <summary>
        /// expect packet from transport.
        /// </summary>
        /// <param name="timeout">
        /// a TimeSpan object that indicates the timeout to expect event.
        /// </param>
        /// <param name="consumedLength">
        /// return an int value that specifies the consumed length.
        /// </param>
        /// <returns>
        /// a StackPacket object that specifies the received packet.
        /// </returns>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        public StackPacket[] ExpectPacket(TimeSpan timeout, out int consumedLength)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("NetbiosServerConnection");
            }

            return(ExpectMultiPacketsVisitor.Visit(
                       this.buffer, this.server.Decoder, this.remoteEndPoint, timeout, out consumedLength));
        }