[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - net/loolnb.cpp
Michael Meeks
michael.meeks at collabora.com
Thu Feb 16 17:49:29 UTC 2017
net/loolnb.cpp | 64 ++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 45 insertions(+), 19 deletions(-)
New commits:
commit 67a9ca928672d4ed5a013808586814c49b6c0006
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Feb 16 17:49:03 2017 +0000
More WS-ness.
diff --git a/net/loolnb.cpp b/net/loolnb.cpp
index 01fc3c5..636a4d9 100644
--- a/net/loolnb.cpp
+++ b/net/loolnb.cpp
@@ -34,9 +34,14 @@ constexpr int PortNumber = 9191;
class SimpleResponseClient : public ClientSocket
{
+ int _wsVersion;
+ std::string _wsKey;
+ std::string _wsProtocol;
+
public:
SimpleResponseClient(const int fd) :
- ClientSocket(fd)
+ ClientSocket(fd),
+ _wsVersion(0)
{
}
virtual void handleIncomingMessage() override
@@ -48,32 +53,53 @@ public:
Poco::Net::HTTPRequest req;
req.read(message);
+ // if we succeeded - remove that from our input buffer
+ size_t consumed = std::min(_inBuffer.size(),
+ std::max((size_t)message.tellg(), size_t(0)));
+ _inBuffer.erase(_inBuffer.begin(), _inBuffer.begin() + consumed);
+
StringTokenizer tokens(req.getURI(), "/?");
if (tokens.count() == 4)
{
std::string subpool = tokens[2];
number = std::stoi(tokens[3]);
+
+ // complex algorithmic core:
+ number = number + 1;
+
+ std::string numberString = std::to_string(number);
+ std::ostringstream oss;
+ oss << "HTTP/1.1 200 OK\r\n"
+ << "Date: Once, Upon a time GMT\r\n" // Mon, 27 Jul 2009 12:28:53 GMT
+ << "Server: madeup string (Linux)\r\n"
+ << "Content-Length: " << numberString.size() << "\r\n"
+ << "Content-Type: text/plain\r\n"
+ << "Connection: Closed\r\n"
+ << "\r\n"
+ << numberString;
+ ;
+ std::string str = oss.str();
+ _outBuffer.insert(_outBuffer.end(), str.begin(), str.end());
+ }
+ else if (tokens.count() == 2 && tokens[1] == "ws")
+ { // create our websocket goodness ...
+ _wsVersion = std::stoi(req.get("Sec-WebSocket-Version", "13"));
+ _wsKey = req.get("Sec-WebSocket-Key", "");
+ _wsProtocol = req.get("Sec-WebSocket-Protocol", "chat");
+ std::cerr << "version " << _wsVersion << " key '" << _wsKey << "\n";
+ // FIXME: other sanity checks ...
+
+ std::ostringstream oss;
+ oss << "HTTP/1.1 101 Switching Protocols\r\n"
+ << "Upgrade: websocket\r\n"
+ << "Connection: Upgrade\r\n"
+ << "Sec-Websocket-Accept: " << _wsKey << "\r\n"
+ << "\r\n";
+ std::string str = oss.str();
+ _outBuffer.insert(_outBuffer.end(), str.begin(), str.end());
}
else
std::cerr << " unknown tokens " << tokens.count() << std::endl;
-
- // complex algorithmic core:
- number = number + 1;
-
- std::string numberString = std::to_string(number);
- std::ostringstream oss;
- oss << "HTTP/1.1 200 OK\r\n"
- << "Date: Once, Upon a time GMT\r\n" // Mon, 27 Jul 2009 12:28:53 GMT
- << "Server: madeup string (Linux)\r\n"
- << "Content-Length: " << numberString.size() << "\r\n"
- << "Content-Type: text/plain\r\n"
- << "Connection: Closed\r\n"
- << "\r\n"
- << numberString;
- ;
- std::string str = oss.str();
- _outBuffer.insert(_outBuffer.end(), str.begin(), str.end());
- _inBuffer.clear();
}
};
More information about the Libreoffice-commits
mailing list