mirror of
https://github.com/ohwgiles/laminar.git
synced 2026-09-24 12:56:42 +00:00
Initial commit
This commit is contained in:
62
src/server.h
Normal file
62
src/server.h
Normal file
@@ -0,0 +1,62 @@
|
||||
///
|
||||
/// Copyright 2015 Oliver Giles
|
||||
///
|
||||
/// This file is part of Laminar
|
||||
///
|
||||
/// Laminar is free software: you can redistribute it and/or modify
|
||||
/// it under the terms of the GNU General Public License as published by
|
||||
/// the Free Software Foundation, either version 3 of the License, or
|
||||
/// (at your option) any later version.
|
||||
///
|
||||
/// Laminaris distributed in the hope that it will be useful,
|
||||
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
/// GNU General Public License for more details.
|
||||
///
|
||||
/// You should have received a copy of the GNU General Public License
|
||||
/// along with Laminar. If not, see <http://www.gnu.org/licenses/>
|
||||
///
|
||||
#ifndef _LAMINAR_SERVER_H_
|
||||
#define _LAMINAR_SERVER_H_
|
||||
|
||||
#include <kj/async-io.h>
|
||||
#include <capnp/message.h>
|
||||
#include <capnp/capability.h>
|
||||
#include <functional>
|
||||
|
||||
struct LaminarInterface;
|
||||
|
||||
// This class abstracts the HTTP/Websockets and Cap'n Proto RPC interfaces.
|
||||
// It also manages the program's asynchronous event loop
|
||||
class Server final : public kj::TaskSet::ErrorHandler {
|
||||
public:
|
||||
// Initializes the server with a LaminarInterface to handle requests from
|
||||
// HTTP/Websocket or RPC clients and bind addresses for each of those
|
||||
// interfaces. See the documentation for kj::AsyncIoProvider::getNetwork
|
||||
// for a description of the address format
|
||||
Server(LaminarInterface& li, kj::StringPtr rpcBindAddress, kj::StringPtr httpBindAddress);
|
||||
~Server();
|
||||
void start();
|
||||
void stop();
|
||||
void addProcess(int fd, std::function<void(char*,size_t)> readCb, std::function<void()> cb);
|
||||
|
||||
private:
|
||||
void acceptHttpClient(kj::Own<kj::ConnectionReceiver>&& listener);
|
||||
void acceptRpcClient(kj::Own<kj::ConnectionReceiver>&& listener);
|
||||
kj::Promise<void> handleProcessOutput(kj::AsyncInputStream* stream, std::function<void(char*,size_t)> readCb);
|
||||
|
||||
void taskFailed(kj::Exception&& exception) override {
|
||||
kj::throwFatalException(kj::mv(exception));
|
||||
}
|
||||
|
||||
private:
|
||||
int efd;
|
||||
capnp::Capability::Client rpcInterface;
|
||||
struct WebsocketConnection;
|
||||
struct HttpImpl;
|
||||
HttpImpl* httpInterface;
|
||||
kj::AsyncIoContext ioContext;
|
||||
kj::TaskSet tasks;
|
||||
};
|
||||
|
||||
#endif // _LAMINAR_SERVER_H_
|
||||
Reference in New Issue
Block a user