Skip to content

Commit c1e9172

Browse files
authored
Merge pull request #1105 from hioa-cs/dev
v0.10.0-rc.2
2 parents 151a2b9 + 8277a0a commit c1e9172

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1262
-481
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ endif(silent)
8282
set(CAPABS "${CAPABS} ${OPTIMIZE}")
8383

8484
# these kinda work with llvm
85-
set(CMAKE_CXX_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -c -m32 -std=c++14 -D_LIBCPP_HAS_NO_THREADS=1 -DOS_VERSION=\\\"${OS_VERSION}\\\"")
86-
set(CMAKE_C_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -c -m32 -DOS_VERSION=\"\"${OS_VERSION}\"\"")
85+
set(CMAKE_CXX_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -std=c++14 -D_LIBCPP_HAS_NO_THREADS=1 -DOS_VERSION=\\\"${OS_VERSION}\\\"")
86+
set(CMAKE_C_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -DOS_VERSION=\"\"${OS_VERSION}\"\"")
8787

8888
# either download or cross-compile needed libraries
8989
option(from_bundle "Download and use pre-compiled libraries for cross-comilation" ON)

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ More information is [available on the wiki](https://github.com/hioa-cs/IncludeOS
9797

9898
### Writing your first service
9999

100-
1. Copy the [./seed](./seed) directory to a convenient location like `~/your_service`. Then, just start implementing the `Service::start` function in the `Service` class, located in [your_service/service.cpp](./seed/service.cpp) (Very simple example provided). This function will be called once the OS is up and running.
101-
2. Update the [CMakeLists.txt](./seed/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc.
100+
1. Copy the [./seed/service](./seed/service) directory to a convenient location like `~/your_service`. Then, just start implementing the `Service::start` function in the `Service` class, located in [your_service/service.cpp](./seed/service/service.cpp) (Very simple example provided). This function will be called once the OS is up and running.
101+
2. Update the [CMakeLists.txt](./seed/service/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc.
102102

103103
**Example:**
104104

105105
```
106-
$ cp -r seed ~/my_service
106+
$ cp -r seed/service ~/my_service
107107
$ cd ~/my_service
108108
$ emacs service.cpp
109109
... add your code

api/kernel/mman.hpp

-6
This file was deleted.

api/net/http/client.hpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is a part of the IncludeOS unikernel - www.includeos.org
22
//
3-
// Copyright 2016 Oslo and Akershus University College of Applied Sciences
3+
// Copyright 2016-2017 Oslo and Akershus University College of Applied Sciences
44
// and Alfred Bratterud
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,26 +19,24 @@
1919
#ifndef HTTP_CLIENT_HPP
2020
#define HTTP_CLIENT_HPP
2121

22-
#include "common.hpp"
23-
#include "request.hpp"
24-
#include "response.hpp"
22+
// http
23+
#include "client_connection.hpp"
24+
2525
#include <net/tcp/tcp.hpp>
26-
#include "connection.hpp"
27-
#include "error.hpp"
2826
#include <vector>
2927
#include <map>
3028

3129
namespace http {
3230

3331
class Client {
3432
public:
35-
using TCP = net::TCP;
36-
using Host = net::tcp::Socket;
33+
using TCP = net::TCP;
34+
using Host = net::tcp::Socket;
3735

38-
using Connection_set = std::vector<std::unique_ptr<Connection>>;
39-
using Connection_mapset = std::map<Host, Connection_set>;
36+
using Connection_set = std::vector<std::unique_ptr<Client_connection>>;
37+
using Connection_mapset = std::map<Host, Connection_set>;
4038

41-
using timeout_duration = Connection::timeout_duration;
39+
using timeout_duration = Client_connection::timeout_duration;
4240

4341
const static timeout_duration DEFAULT_TIMEOUT; // client.cpp, 5s
4442
constexpr static size_t DEFAULT_BUFSIZE = 2048;
@@ -153,10 +151,11 @@ namespace http {
153151
inline void post(Host host, std::string path, Header_set hfields, const std::string& data, Response_handler cb, Options options = {});
154152

155153
private:
156-
TCP& tcp_;
157-
Connection_mapset conns_;
154+
friend class Client_connection;
158155

159-
bool keep_alive_ = false;
156+
TCP& tcp_;
157+
Connection_mapset conns_;
158+
bool keep_alive_ = false;
160159

161160
void resolve(const std::string& host, ResolveCallback);
162161

@@ -172,9 +171,9 @@ namespace http {
172171
/** Add data and content length */
173172
void add_data(Request&, const std::string& data);
174173

175-
Connection& get_connection(const Host host);
174+
Client_connection& get_connection(const Host host);
176175

177-
void close(Connection&);
176+
void close(Client_connection&);
178177

179178
}; // < class Client
180179

api/net/http/client_connection.hpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2016-2017 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+
#ifndef HTTP_CLIENT_CONNECTION_HPP
20+
#define HTTP_CLIENT_CONNECTION_HPP
21+
22+
// http
23+
#include "common.hpp"
24+
#include "connection.hpp"
25+
#include "error.hpp"
26+
27+
#include <util/timer.hpp>
28+
29+
namespace http {
30+
31+
class Client;
32+
33+
class Client_connection : public Connection {
34+
public:
35+
using timeout_duration = std::chrono::milliseconds;
36+
37+
public:
38+
explicit Client_connection(Client&, TCP_conn);
39+
40+
bool available() const
41+
{ return on_response_ == nullptr && keep_alive_; }
42+
43+
bool occupied() const
44+
{ return !available(); }
45+
46+
void send(Request_ptr, Response_handler, const size_t bufsize, timeout_duration = timeout_duration::zero());
47+
48+
private:
49+
Client& client_;
50+
Response_handler on_response_;
51+
Timer timer_;
52+
timeout_duration timeout_dur_;
53+
54+
void send_request(const size_t bufsize);
55+
56+
void recv_response(buffer_t buf, size_t len);
57+
58+
void end_response(Error err = Error::NONE);
59+
60+
void timeout_request()
61+
{ end_response(Error::TIMEOUT); }
62+
63+
void close();
64+
65+
}; // < class Client_connection
66+
67+
} // < namespace http
68+
69+
#endif // < HTTP_CLIENT_CONNECTION_HPP

api/net/http/connection.hpp

+32-47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is a part of the IncludeOS unikernel - www.includeos.org
22
//
3-
// Copyright 2016 Oslo and Akershus University College of Applied Sciences
3+
// Copyright 2016-2017 Oslo and Akershus University College of Applied Sciences
44
// and Alfred Bratterud
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,74 +19,59 @@
1919
#ifndef HTTP_CONNECTION_HPP
2020
#define HTTP_CONNECTION_HPP
2121

22-
#include "common.hpp"
22+
// http
2323
#include "request.hpp"
2424
#include "response.hpp"
25-
#include "error.hpp"
25+
2626
#include <net/tcp/connection.hpp>
27-
#include <map>
28-
#include <vector>
29-
#include <delegate>
30-
#include <util/timer.hpp>
3127

3228
namespace http {
3329

3430
class Connection {
3531
public:
36-
using TCP_conn_ptr = net::tcp::Connection_ptr;
37-
using Peer = net::tcp::Socket;
38-
using buffer_t = net::tcp::buffer_t;
39-
using Close_handler = delegate<void(Connection&)>;
40-
using timeout_duration = std::chrono::milliseconds;
32+
using TCP_conn = net::tcp::Connection_ptr;
33+
using Peer = net::tcp::Socket;
34+
using buffer_t = net::tcp::buffer_t;
4135

4236
public:
43-
44-
explicit Connection(TCP_conn_ptr, Close_handler);
37+
inline explicit Connection(TCP_conn tcpconn, bool keep_alive = true);
4538

4639
template <typename TCP>
47-
explicit Connection(TCP&, Peer, Close_handler);
48-
49-
bool available() const
50-
{ return on_response_ == nullptr && keep_alive_; }
51-
52-
bool occupied() const
53-
{ return !available(); }
40+
explicit Connection(TCP&, Peer);
5441

55-
void send(Request_ptr, Response_handler, const size_t bufsize, timeout_duration = timeout_duration::zero());
56-
57-
net::tcp::port_t local_port() const
42+
net::tcp::port_t local_port() const noexcept
5843
{ return (tcpconn_) ? tcpconn_->local_port() : 0; }
5944

60-
Peer peer() const
45+
Peer peer() const noexcept
6146
{ return (tcpconn_) ? tcpconn_->remote() : Peer(); }
62-
//bool operator==(const Connection& other)
63-
//{ return this == &other; }
64-
//{ return tcpconn_->local_port() == other.tcpconn_->local_port(); }
6547

66-
private:
67-
TCP_conn_ptr tcpconn_;
48+
void timeout()
49+
{ tcpconn_->is_closing() ? tcpconn_->abort() : tcpconn_->close(); }
50+
51+
protected:
52+
TCP_conn tcpconn_;
6853
Request_ptr req_;
6954
Response_ptr res_;
70-
Close_handler on_close_;
71-
Response_handler on_response_;
72-
Timer timer_;
73-
74-
timeout_duration timeout_dur_;
75-
bool keep_alive_;
76-
77-
void send_request(const size_t bufsize);
78-
79-
void recv_response(buffer_t buf, size_t len);
80-
81-
void end_response(Error err = Error::NONE);
82-
83-
void timeout_request()
84-
{ end_response(Error::TIMEOUT); }
85-
86-
void close();
55+
bool keep_alive_;
8756

8857
}; // < class Connection
8958

59+
inline Connection::Connection(TCP_conn tcpconn, bool keep_alive)
60+
: tcpconn_{std::move(tcpconn)},
61+
req_{nullptr},
62+
res_{nullptr},
63+
keep_alive_{keep_alive}
64+
{
65+
Ensures(tcpconn_ != nullptr);
66+
debug("<http::Connection> Created %u -> %s %p\n", local_port(), peer().to_string().c_str(), this);
67+
}
68+
69+
template <typename TCP>
70+
Connection::Connection(TCP& tcp, Peer addr)
71+
: Connection(tcp.connect(addr))
72+
{
73+
}
74+
9075
} // < namespace http
9176

9277
#endif // < HTTP_CONNECTION_HPP

api/posix/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# IncludeOS POSIX extensions
2+
3+
IncludeOS intends to provide a POSIX interface suffucient for linking and running many conventional C libraries and programs. A lot of the POSIX functionality will be header-only stubs and some of it is provided externally by e.g. the compiler or standard library.
4+
5+
### Other providers of POSIX content
6+
* *newlib*: is our current C library which also provides many POSIX features (indeed the C standard itself overlaps with POSIX). Newlib provides most of the C standard library, including `stdlib.h`, `stdio.h`, `math.h` etc., but is mising some C11 extensions. Those are rarely used and provided here as stubs.
7+
* *clang*: Clang provides a few POSIX headers such as `stddef.h`, `stdarg.h` and `limits.h`. It also provides compiler intrinsics such as `x86intrin.h`. When building IncludeOS we use the `-nostdlibinc` flag to allow inclusion of these headers, without including the standard library headers from the host.
8+
9+
### Guidelines for this folder
10+
* Only actually standardized POSIX content should live here, and only content not allready provided by alternative sources above.
11+
* Extensions to POSIX headers that IncludeOS needs, but which isn't present on one of the supportet platforms (e.g. macOS or Linux) should not live here, since we'd like to be able to build directly on those platforms with their respective POSIX implementations. As an example, our syslog implementation defines `LOG_INTERNAL` in addition to `LOG_MAIL` etc. While defining this symbol in the `syslog.h` POSIX header is allowed by the standard it introduces an implicit expectation in IncludeOS application code making it less portable. Such extensions can be placed in the IncludeOS API instead.

api/posix/dlfcn.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 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+
#ifndef POSIX_DLFCN_H
19+
#define POSIX_DLFCN_H
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
#define RTLD_LAZY 1 // Relocations are performed at an implementation-dependent time.
26+
#define RTLD_NOW 2 // Relocations are performed when the object is loaded.
27+
#define RTLD_GLOBAL 3 // All symbols are available for relocation processing of other modules.
28+
#define RTLD_LOCAL 4 // All symbols are not made available for relocation processing by other modules.
29+
30+
void *dlopen(const char *, int);
31+
void *dlsym(void *, const char *);
32+
int dlclose(void *);
33+
char *dlerror(void);
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif // < POSIX_DLFCN_H

api/sys/math.h api/posix/math.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#ifndef SYS_MATH_H
1919
#define SYS_MATH_H
2020

21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
2124

2225
// Long double math stubs
2326
long double cosl(long double);
@@ -85,7 +88,10 @@ long double tgammal(long double);
8588
long double truncl(long double);
8689
long double nanl(const char*);
8790

88-
91+
#ifdef __cplusplus
92+
}
8993
#endif
9094

9195
#include_next <math.h>
96+
97+
#endif

0 commit comments

Comments
 (0)