    # File lib/phusion_passenger/message_channel.rb, line 220
            def read_scalar(buffer = new_buffer, max_size = nil)
                    if !@io.read(4, buffer)
                            return nil
                    end
                    while buffer.size < 4
                            tmp = @io.read(4 - buffer.size)
                            if tmp.empty?
                                    return nil
                            else
                                    buffer << tmp
                            end
                    end

                    size = buffer.unpack(UINT32_PACK_FORMAT)[0]
                    if size == 0
                            buffer.replace('')
                            return buffer
                    else
                            if !max_size.nil? && size > max_size
                                    raise SecurityError, "Scalar message size (#{size}) " <<
                                            "exceeds maximum allowed size (#{max_size})."
                            end
                            if !@io.read(size, buffer)
                                    return nil
                            end
                            if buffer.size < size
                                    tmp = ''
                                    while buffer.size < size
                                            if !@io.read(size - buffer.size, tmp)
                                                    return nil
                                            else
                                                    buffer << tmp
                                            end
                                    end
                            end
                            return buffer
                    end
            rescue Errno::ECONNRESET
                    return nil
            end