Skip to content

Commit

Permalink
Add missing LIU server helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Mar 11, 2019
1 parent b117602 commit 7e56198
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
47 changes: 47 additions & 0 deletions examples/microLB/liu_helpers/liu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
#include <liveupdate>
#include "server.hpp"

void setup_liveupdate_server(net::Inet& inet,
const uint16_t PORT,
liu::LiveUpdate::storage_func func)
{
static liu::LiveUpdate::storage_func save_function;
save_function = func;

// listen for live updates
server(inet, PORT,
[] (liu::buffer_t& buffer)
{
printf("* Live updating from %p (len=%u)\n",
buffer.data(), (uint32_t) buffer.size());
try
{
// run live update process
liu::LiveUpdate::exec(buffer, "test", save_function);
}
catch (std::exception& err)
{
liu::LiveUpdate::restore_environment();
printf("Live update failed:\n%s\n", err.what());
throw;
}
});
}
39 changes: 39 additions & 0 deletions examples/microLB/liu_helpers/server.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Master thesis
* by Alf-Andre Walla 2016-2017
*
**/
#pragma once
#include <stdexcept>

static inline
void server(net::Inet& inet,
const uint16_t port,
delegate<void(liu::buffer_t&)> callback)
{
auto& server = inet.tcp().listen(port);
server.on_connect(
net::tcp::Connection::ConnectCallback::make_packed(
[callback, port] (auto conn)
{
auto* buffer = new liu::buffer_t;
buffer->reserve(3*1024*1024);
printf("Receiving blob on port %u\n", port);

// retrieve binary
conn->on_read(9000,
[conn, buffer] (auto buf)
{
buffer->insert(buffer->end(), buf->begin(), buf->end());
})
.on_disconnect(
net::tcp::Connection::DisconnectCallback::make_packed(
[buffer, callback] (auto conn, auto) {
printf("* Blob size: %u b stored at %p\n",
(uint32_t) buffer->size(), buffer->data());
callback(*buffer);
delete buffer;
conn->close();
}));
}));
}
2 changes: 1 addition & 1 deletion examples/microLB/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
static void print_stats(int);
#define STATS_PERIOD 5s

#include "../LiveUpdate/liu.hpp"
#include "liu_helpers/liu.hpp"
static void save_state(liu::Storage& store, const liu::buffer_t*)
{

Expand Down

0 comments on commit 7e56198

Please sign in to comment.