Protocol::WebSocketSourceProtocolWebSocketFramer

class Framer

Wraps an underlying Async::IO::Stream for reading and writing binary data into structured frames.

Definitions

def close

Close the underlying stream.

Implementation

def close
	@stream.close
end

def flush

Flush the underlying stream.

Implementation

def flush
	@stream.flush
end

def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE)

Read a frame from the underlying stream.

Signature

returns Frame

the frame read from the stream.

Implementation

def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE)
	# Read the header:
	finished, flags, opcode = read_header
	
	# Read the frame:
	klass = @frames[opcode] || Frame
	frame = klass.read(finished, flags, opcode, @stream, maximum_frame_size)
	
	return frame
end

def write_frame(frame)

Write a frame to the underlying stream.

Implementation

def write_frame(frame)
	frame.write(@stream)
end

def read_header

Read the header of the frame.

Implementation

def read_header
	if buffer = @stream.read(1) and buffer.bytesize == 1
		return Frame.parse_header(buffer)
	end
	
	raise EOFError, "Could not read frame header!"
end