AaltoTLS.RecordLayer.AsyncSendRecordsResult.GetRecords C# (CSharp) Method

GetRecords() public method

public GetRecords ( uint maxDataLength ) : byte[]
maxDataLength uint
return byte[]
        public byte[] GetRecords(uint maxDataLength)
        {
            MemoryStream memStream = new MemoryStream();
            lock (_lock) {
                while (_queue.Count > 0) {
                    byte[] recordBytes = _queue[0].GetBytes();
                    if (maxDataLength > 0 && memStream.Length+recordBytes.Length > maxDataLength) {
                        return memStream.ToArray();
                    }
                    _queue.RemoveAt(0);

                    memStream.Write(recordBytes, 0, recordBytes.Length);
                    memStream.Flush();
                }
            }
            return memStream.ToArray();
        }

Usage Example

Example #1
0
        private void StartSend(AsyncSendRecordsResult asyncSendResult)
        {
            lock (_sendLock) {
                if (_sending)
                {
                    // Send in progress, add to queue
                    if (asyncSendResult != null)
                    {
                        _sendQueue.Add(asyncSendResult);
                    }
                    return;
                }
                else if (asyncSendResult != null)
                {
                    // No send in progress, insert to queue
                    _sendQueue.Insert(0, asyncSendResult);
                }

                byte[] outputBuffer = new byte[0];
                while (outputBuffer.Length == 0 && _sendQueue.Count > 0)
                {
                    // Get first asyncSendResult in queue
                    asyncSendResult = _sendQueue[0];
                    _sendQueue.Remove(asyncSendResult);

                    // Get output buffer from record bytes
                    outputBuffer = asyncSendResult.GetRecords(0);
                    if (outputBuffer.Length == 0)
                    {
                        asyncSendResult.SetComplete();
                        asyncSendResult = null;
                    }
                }

                if (asyncSendResult != null && outputBuffer.Length > 0)
                {
                    // Start sending the record
                    _innerStream.BeginWrite(outputBuffer, 0, outputBuffer.Length,
                                            new AsyncCallback(WriteCallback),
                                            asyncSendResult);
                    _sending = true;
                }
            }
        }
All Usage Examples Of AaltoTLS.RecordLayer.AsyncSendRecordsResult::GetRecords