/// <summary>
        /// Receive a single frame from <paramref cref="socket"/>, blocking until one arrives.
        /// Indicate whether further frames exist via <paramref name="more"/>.
        /// </summary>
        /// <param name="socket">The socket to receive from.</param>        
        /// <param name="bytes">Array to populate with the frame data. If pre-allocated and large enough the allocated array will be used. Otherwise new array will be allocated.</param>                
        /// <param name="length">The length of the frame receieved.</param>
        /// <param name="more"><c>true</c> if another frame of the same message follows, otherwise <c>false</c>.</param>
        public static void ReceiveFrameBytes(this IReceive socket, ref byte[] bytes, out int length, out bool more)
        {
            var frame = new Frame();
            socket.ReceiveFrame(ref frame);

            if (bytes != null && bytes.Length >= frame.Length)
                frame.CopyDataTo(bytes);
            else
                bytes = frame.CloneData();

            length = frame.Length;
            more = frame.More;

            frame.Close();
        }
        /// <summary>
        /// Attempt to receive a single frame from <paramref cref="socket"/>.  Reusing existing bytes-array if large enough.
        /// If no message is available within <paramref name="timeout"/>, return <c>false</c>.
        /// Indicate whether further frames exist via <paramref name="more"/>.
        /// </summary>
        /// <param name="socket">The socket to receive from.</param>
        /// <param name="timeout">The maximum period of time to wait for a message to become available.</param>
        /// <param name="bytes">The content of the received message frame. If pre-allocated and large enough the allocated array will be used. Otherwise new array will be allocated.</param>
        /// <param name="length">The length of the frame receieved.</param>        
        /// <param name="more"><c>true</c> if another frame of the same message follows, otherwise <c>false</c>.</param>               
        /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
        public static bool TryReceiveFrameBytes(this IReceive socket, TimeSpan timeout, ref byte[] bytes, out int length, out bool more)
        {
            var frame = new Frame();

            if (!socket.TryReceiveFrame(ref frame, timeout))
            {
                frame.Close();
                bytes = null;
                more = false;
                length = 0;
                return false;
            }

            if (bytes != null && bytes.Length >= frame.Length)
                frame.CopyDataTo(bytes);
            else
                bytes = frame.CloneData();

            length = frame.Length;
            more = frame.More;

            frame.Close();
            return true;
        }