-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters