Browse Source

Added operator<< for WebSocket::State

Paul-Louis Ageneau 1 year ago
parent
commit
26216800e1
2 changed files with 25 additions and 0 deletions
  1. 2 0
      include/rtc/websocket.hpp
  2. 23 0
      src/websocket.cpp

+ 2 - 0
include/rtc/websocket.hpp

@@ -58,6 +58,8 @@ private:
 	using CheshireCat<impl::WebSocket>::impl;
 };
 
+std::ostream &operator<<(std::ostream &out, WebSocket::State state);
+
 } // namespace rtc
 
 #endif

+ 23 - 0
src/websocket.cpp

@@ -68,6 +68,29 @@ optional<string> WebSocket::path() const {
 	return state != State::Connecting && handshake ? make_optional(handshake->path()) : nullopt;
 }
 
+std::ostream &operator<<(std::ostream &out, WebSocket::State state) {
+	using State = WebSocket::State;
+	const char *str;
+	switch (state) {
+	case State::Connecting:
+		str = "connecting";
+		break;
+	case State::Open:
+		str = "open";
+		break;
+	case State::Closing:
+		str = "closing";
+		break;
+	case State::Closed:
+		str = "closed";
+		break;
+	default:
+		str = "unknown";
+		break;
+	}
+	return out << str;
+}
+
 } // namespace rtc
 
 #endif