[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - net/clientnb.cpp net/common.hpp net/loolnb.cpp net/socket.hpp
Michael Meeks
michael.meeks at collabora.com
Thu Feb 16 11:01:11 UTC 2017
net/clientnb.cpp | 8 --------
net/common.hpp | 48 ------------------------------------------------
net/loolnb.cpp | 30 ++++++++++++++++++++----------
net/socket.hpp | 6 +++---
4 files changed, 23 insertions(+), 69 deletions(-)
New commits:
commit 84094a1d6e582d8caa7946855bfb1b873ae7f593
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Feb 16 11:00:38 2017 +0000
Lean on Poco for request parsing.
diff --git a/net/clientnb.cpp b/net/clientnb.cpp
index 99bda95..a8ec054 100644
--- a/net/clientnb.cpp
+++ b/net/clientnb.cpp
@@ -35,8 +35,6 @@
#include <Poco/Util/Option.h>
#include <Poco/Util/OptionSet.h>
-#include "common.hpp"
-
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
@@ -104,17 +102,11 @@ struct Session
}
};
-void testParseHTTP()
-{
-}
-
struct Client : public Poco::Util::Application
{
public:
int main(const std::vector<std::string>& /* args */) override
{
- testParseHTTP();
-
Session first("init");
Session second("init");
diff --git a/net/common.hpp b/net/common.hpp
deleted file mode 100644
index da1ca25..0000000
--- a/net/common.hpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef NB_COMMON_HPP
-#define NB_COMMON_HPP
-
-typedef std::vector<std::string> HeaderStrings;
-typedef std::vector<unsigned char> Payload;
-
-// FIXME: lots of return conditions:
-// partial data, malicious/invalid data, complete data
-// does this belong in a separate method ?
-size_t parseHTTP(const std::vector<unsigned char> data,
- HeaderStrings &headers, Payload & /* payload */)
-{
- size_t i, start;
- for (i = start = 0; i < data.size(); ++i)
- {
- unsigned char c = data[i];
- if (c == 0)
- { // someone doing something cute.
- return -1;
- }
- if (c == '\r' || c == '\n')
- {
- std::string header(reinterpret_cast<const char *>(&data[start]), i - start);
- while (++i < data.size() &&
- (data[i] == '\n' || data[i] == '\r'))
- {}
- start = i;
- // terminating \r\n
- if (header.size() == 0)
- break;
- headers.push_back(header);
- }
- }
- return i;
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/net/loolnb.cpp b/net/loolnb.cpp
index a6a94eb..963a631 100644
--- a/net/loolnb.cpp
+++ b/net/loolnb.cpp
@@ -18,10 +18,15 @@
#include <thread>
#include <assert.h>
+#include <Poco/MemoryStream.h>
#include <Poco/Net/SocketAddress.h>
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/StringTokenizer.h>
+
+using Poco::MemoryInputStream;
+using Poco::StringTokenizer;
#include "socket.hpp"
-#include "common.hpp"
constexpr int PortNumber = 9191;
@@ -36,17 +41,22 @@ public:
{
std::cerr << "message had size " << _inBuffer.size() << "\n";
- HeaderStrings headers;
- Payload payload;
- size_t skip;
- if ((skip = parseHTTP(_inBuffer, headers, payload) > 0))
+ int number = 0;
+ MemoryInputStream message(&_inBuffer[0], _inBuffer.size());
+ Poco::Net::HTTPRequest req;
+ req.read(message);
+
+ StringTokenizer tokens(req.getURI(), "/?");
+ if (tokens.count() == 4)
{
- for (auto i = headers.begin(); i != headers.end(); ++i)
- {
- std::cerr << "header '" << *i << "'\n";
- }
+ std::string subpool = tokens[2];
+ number = std::stoi(tokens[3]);
}
- // else close socket ? ...
+ else
+ std::cerr << " unknown tokens " << tokens.count() << std::endl;
+
+ // complex algorithmic core:
+ number = number + 1;
std::ostringstream oss;
oss << "HTTP/1.1 200 OK\r\n"
diff --git a/net/socket.hpp b/net/socket.hpp
index 3b55405..f41befc 100644
--- a/net/socket.hpp
+++ b/net/socket.hpp
@@ -282,8 +282,8 @@ public:
}
protected:
- std::vector< unsigned char > _inBuffer;
- std::vector< unsigned char > _outBuffer;
+ std::vector< char > _inBuffer;
+ std::vector< char > _outBuffer;
public:
HandleResult handlePoll( int events ) override
@@ -307,7 +307,7 @@ public:
bool readIncomingData()
{
ssize_t len;
- unsigned char buf[4096];
+ char buf[4096];
do {
len = ::read(getFD(), buf, sizeof(buf));
} while (len < 0 && errno == EINTR);
More information about the Libreoffice-commits
mailing list