|
| 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 | +} |
0 commit comments