예제 #1
0
파일: Channel.cs 프로젝트: cezary12/kokos
 public virtual void post(int transportId, int priority,
                          IList <byte[]> buffers, int messageHeaderSize,
                          MessageProgressCallback messageProgressCallback)
 {
     channelWriter.post(transportId, priority, buffers,
                        messageHeaderSize, messageProgressCallback);
 }
예제 #2
0
        internal OutgoingFrame(byte[] payload, int transportId, 
            int frameNumber, int messageHeaderSize, 
            MessageProgressCallback messageProgressCallback, 
            int byteCount, int totalByteCount, int priority, bool closeFlag)
        {
            this.payload = payload;
            this.transportId = transportId;
            this.frameNumber = frameNumber;
            this.messageProgressCallback = messageProgressCallback;
            this.byteCount = byteCount;
            this.totalByteCount = totalByteCount;
            this.priority = priority;
            this.closeFlag = closeFlag;
            this.sentAsSingleBuffer = false;

            // create the frame header

            if (payload != null)
            {
                header = new byte[Frame.FRAME_HEADER_SIZE];

                int offset = 0;
                Serialization.storeInt(header, offset, transportId);
                offset += 4;
                Serialization.storeInt(header, offset, frameNumber);
                offset += 4;
                Serialization.storeInt(header, offset, messageHeaderSize);
                offset += 4;
                Serialization.storeInt(header, offset, payload.Length);
            }
        }
예제 #3
0
        internal OutgoingFrame(byte[] payload, int transportId,
                               int frameNumber, int messageHeaderSize,
                               MessageProgressCallback messageProgressCallback,
                               int byteCount, int totalByteCount, int priority, bool closeFlag)
        {
            this.payload                 = payload;
            this.transportId             = transportId;
            this.frameNumber             = frameNumber;
            this.messageProgressCallback = messageProgressCallback;
            this.byteCount               = byteCount;
            this.totalByteCount          = totalByteCount;
            this.priority                = priority;
            this.closeFlag               = closeFlag;
            this.sentAsSingleBuffer      = false;

            // create the frame header

            if (payload != null)
            {
                header = new byte[Frame.FRAME_HEADER_SIZE];

                int offset = 0;
                Serialization.storeInt(header, offset, transportId);
                offset += 4;
                Serialization.storeInt(header, offset, frameNumber);
                offset += 4;
                Serialization.storeInt(header, offset, messageHeaderSize);
                offset += 4;
                Serialization.storeInt(header, offset, payload.Length);
            }
        }
예제 #4
0
 public virtual void registerNewMessage(
     long messageId, MessageProgressCallback message)
 {
     lock (messages)
     {
         messages.Add(messageId, message);
     }
 }
 public virtual void registerNewMessage(
     long messageId, MessageProgressCallback message)
 {
     lock (messages)
     {
         messages.Add(messageId, message);
     }
 }
예제 #6
0
        // notifies cancellation (via the progress callback) for all
        // messages that have complete frames in the given list
        private void notifyCancellation(IList <OutgoingFrame> frames)
        {
            foreach (OutgoingFrame frame in frames)
            {
                if (frame.byteCount == frame.totalByteCount)
                {
                    // this is the last frame for the given message

                    MessageProgressCallback callback =
                        frame.messageProgressCallback;
                    if (callback != null)
                    {
                        callback.progress(0, 0);
                    }
                }
            }
        }
예제 #7
0
        internal virtual void post(int transportId, int priority,
                                   IList <byte[]> buffers, int messageHeaderSize,
                                   MessageProgressCallback messageProgressCallback)
        {
            // add new buffers to the queue of outgoing frames
            const bool closeFlag      = false;
            int        byteCount      = 0;
            int        totalByteCount = 0;

            foreach (byte[] buf in buffers)
            {
                totalByteCount += buf.Length;
            }

            lock (outgoingFrames)
            {
                // find the proper place to insert into the queue
                int insertionIndex = findOutgoingInsertionIndex(priority);

                int frameNumber = 1;
                foreach (byte[] buf in buffers)
                {
                    byteCount += buf.Length;
                    if (frameNumber == buffers.Count)
                    {
                        // the frame number is negative for the last frame
                        frameNumber *= -1;
                    }

                    OutgoingFrame newFrame = new OutgoingFrame(
                        buf, transportId, frameNumber,
                        messageHeaderSize, messageProgressCallback,
                        byteCount, totalByteCount, priority, closeFlag);

                    outgoingFrames.Insert(insertionIndex++, newFrame);

                    ++frameNumber;
                }
            }
        }
예제 #8
0
 public virtual void post(int transportId, int priority, 
     IList<byte[]> buffers, int messageHeaderSize, 
     MessageProgressCallback messageProgressCallback)
 {
     channelWriter.post(transportId, priority, buffers,
         messageHeaderSize, messageProgressCallback);
 }
예제 #9
0
        internal virtual void post(int transportId, int priority, 
            IList<byte[]> buffers, int messageHeaderSize, 
            MessageProgressCallback messageProgressCallback)
        {
            // add new buffers to the queue of outgoing frames
            const bool closeFlag = false;
            int byteCount = 0;
            int totalByteCount = 0;
            foreach (byte[] buf in buffers)
            {
                totalByteCount += buf.Length;
            }

            lock (outgoingFrames)
            {
            // find the proper place to insert into the queue
                int insertionIndex = findOutgoingInsertionIndex(priority);

                int frameNumber = 1;
                foreach (byte[] buf in buffers)
                {
                    byteCount += buf.Length;
                    if (frameNumber == buffers.Count)
                    {
                    // the frame number is negative for the last frame
                        frameNumber *= -1;
                    }

                    OutgoingFrame newFrame = new OutgoingFrame(
                        buf, transportId, frameNumber,
                        messageHeaderSize, messageProgressCallback,
                        byteCount, totalByteCount, priority, closeFlag);

                    outgoingFrames.Insert(insertionIndex++, newFrame);

                    ++frameNumber;
                }
            }
        }
예제 #10
0
        internal virtual void doSomeOutput()
        {
            OutgoingFrame frame;

            lock (outgoingFrames)
            {
                if (outgoingFrames.Count == 0)
                {
                    return;
                }
                frame = outgoingFrames[0];

                if (frame.closeFlag)
                {
                    outgoingFrames.RemoveAt(0);

                    // this artificial exception forces the worker to
                    // physically close this connection and remove it
                    // from the set of channels
                    throw new YAMIIOException("dummy");
                }
            }

            if (connection.connectedChannel != null)
            {
                // TCP connection
                int sent =
                    connection.connectedChannel.Send(frame.BuffersToSent);
                frame.AddSentBytes(sent);
            }
            else if (connection.ssl != null)
            {
                // TCP SSL connection
                int sent =
                    connection.writingQueue.PutMany(frame.BuffersToSent);
                frame.AddSentBytes(sent);
            }
            else
            {
                // UDP connection
                connection.datagramChannel.SendTo(
                    frame.SingleBuffer, connection.targetAddress);
            }

            if (frame.buffersConsumed())
            {
                // the first frame (head in the queue) was complmesetely
                // sent -> notify its progress callback and remove
                // the head from the queue
                lock (outgoingFrames)
                {
                    outgoingFrames.RemoveAt(0);
                }

                MessageProgressCallback callback =
                    frame.messageProgressCallback;
                if (callback != null)
                {
                    callback.progress(frame.byteCount, frame.totalByteCount);
                }

                if (logCallback != null)
                {
                    if (logLevel == LogEventArgs.LogLevel.HIGH)
                    {
                        logCallback.Log(LogEventArgs.LogLevel.HIGH,
                                        "Frame sent:"
                                        + " target: " + target
                                        + " tid: " + frame.transportId
                                        + " fid: " + frame.frameNumber
                                        + " size: "
                                        + frame.byteCount + "/" + frame.totalByteCount);
                    }
                }
            }
        }