libreoffice-online/loolwsd/MigratorySocketTransport.cpp
Tor Lillqvist 1b0230e4df Intermediate commit of start on transporting sockets to child process
Will be needed if we want loolwsd to run on Windows. Then we will have one
process receiving the connections from WebSocket clients and sending the
accepted connection sockets to child processes thatr might be already running,
either because they have been "pre-forked", or because of a collaboration
scenario where new clients join a session working on a document.

But initially we will write this as if for Unix only, so development of this
migratory socket stuff is paused for now. (And it isn't even clear whether the
API design so far is a good idea and elegantly implementable.)
2015-03-16 12:30:56 +02:00

61 lines
1.5 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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/.
*/
#include <Poco/Net/Socket.h>
#include <Poco/Net/StreamSocketImpl.h>
#include "MigratorySocketTransport.hpp"
#include "socketpair.c"
using Poco::Net::Socket;
using Poco::Net::StreamSocketImpl;
MigratorySocketTransport MigratorySocketTransport::create()
{
poco_socket_t sockets[2];
if (dumb_socketpair(sockets, 0) != 0)
throw new std::runtime_error("Failed to create socket pair");
return MigratorySocketTransport(sockets);
}
MigratorySocketTransport::MigratorySocketTransport(poco_socket_t sockets[2]):
Socket(new StreamSocketImpl(sockets[0])),
_thisIsParent(true)
{
_sockets[0] = sockets[0];
_sockets[1] = sockets[1];
}
MigratorySocketTransport::MigratorySocketTransport(std::string string):
Socket(new StreamSocketImpl(std::stoi(string))),
_thisIsParent(false)
{
}
MigratorySocketTransport::~MigratorySocketTransport()
{
}
std::string MigratorySocketTransport::string()
{
return std::to_string(sockfd());
}
void MigratorySocketTransport::send(MigratorySocket socket)
{
}
MigratorySocket MigratorySocketTransport::receive()
{
return MigratorySocket(Socket());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */