MCPcopy Index your code
hub / github.com/apache/tomcat / WsFrameBase

Class WsFrameBase

java/org/apache/tomcat/websocket/WsFrameBase.java:43–1099  ·  view source on GitHub ↗

Takes the ServletInputStream, processes the WebSocket frames it contains and extracts the messages. WebSocket Pings received will be responded to automatically without any action required by the application.

Source from the content-addressed store, hash-verified

41 * received will be responded to automatically without any action required by the application.
42 */
43public abstract class WsFrameBase {
44
45 private static final StringManager sm = StringManager.getManager(WsFrameBase.class);
46
47 // Connection level attributes
48 /**
49 * The WebSocket session for this frame.
50 */
51 protected final WsSession wsSession;
52 /**
53 * The input buffer for reading data.
54 */
55 protected final ByteBuffer inputBuffer;
56 private final Transformation transformation;
57
58 // Attributes for control messages
59 // They can appear in the middle of other messages so need separate attributes
60 private final ByteBuffer controlBufferBinary = ByteBuffer.allocate(125);
61 private final CharBuffer controlBufferText = CharBuffer.allocate(125);
62
63 // Attributes of the current message
64 private final CharsetDecoder utf8DecoderControl = StandardCharsets.UTF_8.newDecoder()
65 .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
66 private final CharsetDecoder utf8DecoderMessage = StandardCharsets.UTF_8.newDecoder()
67 .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
68 private boolean continuationExpected = false;
69 private boolean textMessage = false;
70 private ByteBuffer messageBufferBinary;
71 private CharBuffer messageBufferText;
72 // Cache the message handler in force when the message starts so it is used
73 // consistently for the entire message
74 private MessageHandler binaryMsgHandler = null;
75 private MessageHandler textMsgHandler = null;
76
77 // Attributes of the current frame
78 private boolean fin = false;
79 private int rsv = 0;
80 private byte opCode = 0;
81 private final byte[] mask = new byte[4];
82 private int maskIndex = 0;
83 private long payloadLength = 0;
84 private volatile long payloadWritten = 0;
85
86 // Attributes tracking state
87 private volatile State state = State.NEW_FRAME;
88 private volatile boolean open = true;
89
90 private static final AtomicReferenceFieldUpdater<WsFrameBase,ReadState> READ_STATE_UPDATER =
91 AtomicReferenceFieldUpdater.newUpdater(WsFrameBase.class, ReadState.class, "readState");
92 private volatile ReadState readState = ReadState.WAITING;
93
94 /**
95 * Constructs a new WsFrameBase.
96 *
97 * @param wsSession The WebSocket session
98 * @param transformation The transformation to apply
99 */
100 public WsFrameBase(WsSession wsSession, Transformation transformation) {

Callers

nothing calls this directly

Calls 3

getManagerMethod · 0.95
newDecoderMethod · 0.80
allocateMethod · 0.65

Tested by

no test coverage detected