Browse Source

Make WebSocket recv and peek simpler and consistent with DataChannel

Paul-Louis Ageneau 2 years ago
parent
commit
c3e66434fa
1 changed files with 4 additions and 14 deletions
  1. 4 14
      src/impl/websocket.cpp

+ 4 - 14
src/impl/websocket.cpp

@@ -146,23 +146,13 @@ bool WebSocket::isClosed() const { return state == State::Closed; }
 size_t WebSocket::maxMessageSize() const { return DEFAULT_MAX_MESSAGE_SIZE; }
 
 optional<message_variant> WebSocket::receive() {
-	while (auto next = mRecvQueue.pop()) {
-		message_ptr message = *next;
-		if (message->type != Message::Control)
-			return to_variant(std::move(*message));
-	}
-	return nullopt;
+	auto next = mRecvQueue.pop();
+	return next ? std::make_optional(to_variant(std::move(**next))) : nullopt;
 }
 
 optional<message_variant> WebSocket::peek() {
-	while (auto next = mRecvQueue.peek()) {
-		message_ptr message = *next;
-		if (message->type != Message::Control)
-			return to_variant(std::move(*message));
-
-		mRecvQueue.pop();
-	}
-	return nullopt;
+	auto next = mRecvQueue.peek();
+	return next ? std::make_optional(to_variant(std::move(**next))) : nullopt;
 }
 
 size_t WebSocket::availableAmount() const { return mRecvQueue.amount(); }