diff options
author | Tor Lillqvist <tml@iki.fi> | 2018-09-05 15:11:05 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2018-09-10 15:13:43 +0300 |
commit | 75438baa70a0d15b18c5ca829b3e3b1307a27c08 (patch) | |
tree | 0bcfbcd7fb37346155eb07b2bb7b0483f09d6797 /net | |
parent | loleaflet: ensure map does not pan on resize (diff) | |
download | online-75438baa70a0d15b18c5ca829b3e3b1307a27c08.tar.gz online-75438baa70a0d15b18c5ca829b3e3b1307a27c08.zip |
More mobile app stuff, very much early state of work in progress
Re-think Linux vs mobile ifdefs a bit. Use #ifdef __linux only to
surround code that actually is Linux-specific. Use #ifdef MOBILEAPP
for code that is for a mobile version (with no separste wsd, forkit,
and kit processes, and with no WebSocket protocol used).
Bypass UnitFoo for mobile. Possibly we do want the UnitFoo stuff after
all on mobile, to run in some special testing mode? Hard to say, let's
skipt it for now.
Diffstat (limited to 'net')
-rw-r--r-- | net/Socket.cpp | 32 | ||||
-rw-r--r-- | net/Socket.hpp | 2 | ||||
-rw-r--r-- | net/WebSocketHandler.hpp | 2 |
3 files changed, 27 insertions, 9 deletions
diff --git a/net/Socket.cpp b/net/Socket.cpp index 98bb6b996d..38bacdde85 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -24,7 +24,7 @@ #include <SigUtil.hpp> #include "Socket.hpp" -#ifdef __linux +#ifndef MOBILEAPP #include "ServerSocket.hpp" #include "SslSocket.hpp" #endif @@ -34,7 +34,7 @@ int SocketPoll::DefaultPollTimeoutMs = 5000; std::atomic<bool> SocketPoll::InhibitThreadChecks(false); std::atomic<bool> Socket::InhibitThreadChecks(false); -#ifdef __linux +#ifndef MOBILEAPP int Socket::createSocket(Socket::Type type) { @@ -56,6 +56,8 @@ namespace { } } +#endif + SocketPoll::SocketPoll(const std::string& threadName) : _name(threadName), _stop(false), @@ -63,6 +65,7 @@ SocketPoll::SocketPoll(const std::string& threadName) _threadFinished(false), _owner(std::this_thread::get_id()) { +#ifndef MOBILEAPP // Create the wakeup fd. if (::pipe2(_wakeup, O_CLOEXEC | O_NONBLOCK) == -1) { @@ -71,10 +74,12 @@ SocketPoll::SocketPoll(const std::string& threadName) std::lock_guard<std::mutex> lock(getPollWakeupsMutex()); getWakeupsArray().push_back(_wakeup[1]); +#endif } SocketPoll::~SocketPoll() { +#ifndef MOBILEAPP joinThread(); { @@ -91,6 +96,7 @@ SocketPoll::~SocketPoll() ::close(_wakeup[1]); _wakeup[0] = -1; _wakeup[1] = -1; +#endif } void SocketPoll::startThread() @@ -110,6 +116,8 @@ void SocketPoll::startThread() } } +#ifndef MOBILEAPP + void SocketPoll::joinThread() { addCallback([this](){ removeSockets(); }); @@ -126,14 +134,19 @@ void SocketPoll::joinThread() } } +#endif + void SocketPoll::wakeupWorld() { +#ifndef MOBILEAPP for (const auto& fd : getWakeupsArray()) wakeup(fd); +#endif } void SocketPoll::insertNewWebSocketSync(const Poco::URI &uri, const std::shared_ptr<SocketHandlerInterface>& websocketHandler) { +#ifndef MOBILEAPP LOG_INF("Connecting to " << uri.getHost() << " : " << uri.getPort() << " : " << uri.getPath()); // FIXME: put this in a ClientSocket class ? @@ -218,11 +231,10 @@ void SocketPoll::insertNewWebSocketSync(const Poco::URI &uri, const std::shared_ } else LOG_ERR("Failed to lookup client websocket host '" << uri.getHost() << "' skipping"); -} - #endif +} -#ifdef __linux +#ifndef MOBILEAPP void ServerSocket::dumpState(std::ostream& os) { @@ -242,11 +254,11 @@ void SocketDisposition::execute() _socketMove = nullptr; } +#endif + const int WebSocketHandler::InitialPingDelayMs = 25; const int WebSocketHandler::PingFrequencyMs = 18 * 1000; -#endif - void WebSocketHandler::dumpState(std::ostream& os) { os << (_shuttingDown ? "shutd " : "alive ") @@ -281,10 +293,9 @@ void StreamSocket::send(Poco::Net::HTTPResponse& response) send(oss.str()); } -#ifdef __linux - void SocketPoll::dumpState(std::ostream& os) { +#ifndef MOBILEAPP // FIXME: NOT thread-safe! _pollSockets is modified from the polling thread! os << " Poll [" << _pollSockets.size() << "] - wakeup r: " << _wakeup[0] << " w: " << _wakeup[1] << "\n"; @@ -293,8 +304,11 @@ void SocketPoll::dumpState(std::ostream& os) os << "\tfd\tevents\trsize\twsize\n"; for (auto &i : _pollSockets) i->dumpState(os); +#endif } +#ifndef MOBILEAPP + /// Returns true on success only. bool ServerSocket::bind(Type type, int port) { diff --git a/net/Socket.hpp b/net/Socket.hpp index 5275ec61ea..2a336f8fc3 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -429,6 +429,7 @@ public: /// Poll the sockets for available data to read or buffer to write. void poll(int timeoutMaxMs) { +#ifndef MOBILEAPP assertCorrectThread(); std::chrono::steady_clock::time_point now = @@ -527,6 +528,7 @@ public: disposition.execute(); } +#endif } /// Write to a wakeup descriptor diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index 6ef1460e00..3e1faabb40 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -383,9 +383,11 @@ public: /// 0 for closed/invalid socket, and -1 for other errors. int sendMessage(const char* data, const size_t len, const WSOpCode code, const bool flush = true) const { +#ifndef MOBILEAPP int unitReturn = -1; if (UnitBase::get().filterSendMessage(data, len, code, flush, unitReturn)) return unitReturn; +#endif //TODO: Support fragmented messages. |