Skip to content

Commit 7e56198

Browse files
committed
Add missing LIU server helpers
1 parent b117602 commit 7e56198

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#pragma once
19+
#include <liveupdate>
20+
#include "server.hpp"
21+
22+
void setup_liveupdate_server(net::Inet& inet,
23+
const uint16_t PORT,
24+
liu::LiveUpdate::storage_func func)
25+
{
26+
static liu::LiveUpdate::storage_func save_function;
27+
save_function = func;
28+
29+
// listen for live updates
30+
server(inet, PORT,
31+
[] (liu::buffer_t& buffer)
32+
{
33+
printf("* Live updating from %p (len=%u)\n",
34+
buffer.data(), (uint32_t) buffer.size());
35+
try
36+
{
37+
// run live update process
38+
liu::LiveUpdate::exec(buffer, "test", save_function);
39+
}
40+
catch (std::exception& err)
41+
{
42+
liu::LiveUpdate::restore_environment();
43+
printf("Live update failed:\n%s\n", err.what());
44+
throw;
45+
}
46+
});
47+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Master thesis
3+
* by Alf-Andre Walla 2016-2017
4+
*
5+
**/
6+
#pragma once
7+
#include <stdexcept>
8+
9+
static inline
10+
void server(net::Inet& inet,
11+
const uint16_t port,
12+
delegate<void(liu::buffer_t&)> callback)
13+
{
14+
auto& server = inet.tcp().listen(port);
15+
server.on_connect(
16+
net::tcp::Connection::ConnectCallback::make_packed(
17+
[callback, port] (auto conn)
18+
{
19+
auto* buffer = new liu::buffer_t;
20+
buffer->reserve(3*1024*1024);
21+
printf("Receiving blob on port %u\n", port);
22+
23+
// retrieve binary
24+
conn->on_read(9000,
25+
[conn, buffer] (auto buf)
26+
{
27+
buffer->insert(buffer->end(), buf->begin(), buf->end());
28+
})
29+
.on_disconnect(
30+
net::tcp::Connection::DisconnectCallback::make_packed(
31+
[buffer, callback] (auto conn, auto) {
32+
printf("* Blob size: %u b stored at %p\n",
33+
(uint32_t) buffer->size(), buffer->data());
34+
callback(*buffer);
35+
delete buffer;
36+
conn->close();
37+
}));
38+
}));
39+
}

examples/microLB/service.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
static void print_stats(int);
2323
#define STATS_PERIOD 5s
2424

25-
#include "../LiveUpdate/liu.hpp"
25+
#include "liu_helpers/liu.hpp"
2626
static void save_state(liu::Storage& store, const liu::buffer_t*)
2727
{
2828

0 commit comments

Comments
 (0)