Skip to content

Commit

Permalink
Merge pull request #1105 from hioa-cs/dev
Browse files Browse the repository at this point in the history
v0.10.0-rc.2
  • Loading branch information
alfreb authored Jan 30, 2017
2 parents 151a2b9 + 8277a0a commit c1e9172
Show file tree
Hide file tree
Showing 76 changed files with 1,262 additions and 481 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ endif(silent)
set(CAPABS "${CAPABS} ${OPTIMIZE}")

# these kinda work with llvm
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}\\\"")
set(CMAKE_C_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -c -m32 -DOS_VERSION=\"\"${OS_VERSION}\"\"")
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}\\\"")
set(CMAKE_C_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -DOS_VERSION=\"\"${OS_VERSION}\"\"")

# either download or cross-compile needed libraries
option(from_bundle "Download and use pre-compiled libraries for cross-comilation" ON)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ More information is [available on the wiki](https://github.com/hioa-cs/IncludeOS

### Writing your first service

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.
2. Update the [CMakeLists.txt](./seed/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc.
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.
2. Update the [CMakeLists.txt](./seed/service/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc.

**Example:**

```
$ cp -r seed ~/my_service
$ cp -r seed/service ~/my_service
$ cd ~/my_service
$ emacs service.cpp
... add your code
Expand Down
6 changes: 0 additions & 6 deletions api/kernel/mman.hpp

This file was deleted.

31 changes: 15 additions & 16 deletions api/net/http/client.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2016 Oslo and Akershus University College of Applied Sciences
// Copyright 2016-2017 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,26 +19,24 @@
#ifndef HTTP_CLIENT_HPP
#define HTTP_CLIENT_HPP

#include "common.hpp"
#include "request.hpp"
#include "response.hpp"
// http
#include "client_connection.hpp"

#include <net/tcp/tcp.hpp>
#include "connection.hpp"
#include "error.hpp"
#include <vector>
#include <map>

namespace http {

class Client {
public:
using TCP = net::TCP;
using Host = net::tcp::Socket;
using TCP = net::TCP;
using Host = net::tcp::Socket;

using Connection_set = std::vector<std::unique_ptr<Connection>>;
using Connection_mapset = std::map<Host, Connection_set>;
using Connection_set = std::vector<std::unique_ptr<Client_connection>>;
using Connection_mapset = std::map<Host, Connection_set>;

using timeout_duration = Connection::timeout_duration;
using timeout_duration = Client_connection::timeout_duration;

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

private:
TCP& tcp_;
Connection_mapset conns_;
friend class Client_connection;

bool keep_alive_ = false;
TCP& tcp_;
Connection_mapset conns_;
bool keep_alive_ = false;

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

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

Connection& get_connection(const Host host);
Client_connection& get_connection(const Host host);

void close(Connection&);
void close(Client_connection&);

}; // < class Client

Expand Down
69 changes: 69 additions & 0 deletions api/net/http/client_connection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2016-2017 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
#ifndef HTTP_CLIENT_CONNECTION_HPP
#define HTTP_CLIENT_CONNECTION_HPP

// http
#include "common.hpp"
#include "connection.hpp"
#include "error.hpp"

#include <util/timer.hpp>

namespace http {

class Client;

class Client_connection : public Connection {
public:
using timeout_duration = std::chrono::milliseconds;

public:
explicit Client_connection(Client&, TCP_conn);

bool available() const
{ return on_response_ == nullptr && keep_alive_; }

bool occupied() const
{ return !available(); }

void send(Request_ptr, Response_handler, const size_t bufsize, timeout_duration = timeout_duration::zero());

private:
Client& client_;
Response_handler on_response_;
Timer timer_;
timeout_duration timeout_dur_;

void send_request(const size_t bufsize);

void recv_response(buffer_t buf, size_t len);

void end_response(Error err = Error::NONE);

void timeout_request()
{ end_response(Error::TIMEOUT); }

void close();

}; // < class Client_connection

} // < namespace http

#endif // < HTTP_CLIENT_CONNECTION_HPP
79 changes: 32 additions & 47 deletions api/net/http/connection.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2016 Oslo and Akershus University College of Applied Sciences
// Copyright 2016-2017 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,74 +19,59 @@
#ifndef HTTP_CONNECTION_HPP
#define HTTP_CONNECTION_HPP

#include "common.hpp"
// http
#include "request.hpp"
#include "response.hpp"
#include "error.hpp"

#include <net/tcp/connection.hpp>
#include <map>
#include <vector>
#include <delegate>
#include <util/timer.hpp>

namespace http {

class Connection {
public:
using TCP_conn_ptr = net::tcp::Connection_ptr;
using Peer = net::tcp::Socket;
using buffer_t = net::tcp::buffer_t;
using Close_handler = delegate<void(Connection&)>;
using timeout_duration = std::chrono::milliseconds;
using TCP_conn = net::tcp::Connection_ptr;
using Peer = net::tcp::Socket;
using buffer_t = net::tcp::buffer_t;

public:

explicit Connection(TCP_conn_ptr, Close_handler);
inline explicit Connection(TCP_conn tcpconn, bool keep_alive = true);

template <typename TCP>
explicit Connection(TCP&, Peer, Close_handler);

bool available() const
{ return on_response_ == nullptr && keep_alive_; }

bool occupied() const
{ return !available(); }
explicit Connection(TCP&, Peer);

void send(Request_ptr, Response_handler, const size_t bufsize, timeout_duration = timeout_duration::zero());

net::tcp::port_t local_port() const
net::tcp::port_t local_port() const noexcept
{ return (tcpconn_) ? tcpconn_->local_port() : 0; }

Peer peer() const
Peer peer() const noexcept
{ return (tcpconn_) ? tcpconn_->remote() : Peer(); }
//bool operator==(const Connection& other)
//{ return this == &other; }
//{ return tcpconn_->local_port() == other.tcpconn_->local_port(); }

private:
TCP_conn_ptr tcpconn_;
void timeout()
{ tcpconn_->is_closing() ? tcpconn_->abort() : tcpconn_->close(); }

protected:
TCP_conn tcpconn_;
Request_ptr req_;
Response_ptr res_;
Close_handler on_close_;
Response_handler on_response_;
Timer timer_;

timeout_duration timeout_dur_;
bool keep_alive_;

void send_request(const size_t bufsize);

void recv_response(buffer_t buf, size_t len);

void end_response(Error err = Error::NONE);

void timeout_request()
{ end_response(Error::TIMEOUT); }

void close();
bool keep_alive_;

}; // < class Connection

inline Connection::Connection(TCP_conn tcpconn, bool keep_alive)
: tcpconn_{std::move(tcpconn)},
req_{nullptr},
res_{nullptr},
keep_alive_{keep_alive}
{
Ensures(tcpconn_ != nullptr);
debug("<http::Connection> Created %u -> %s %p\n", local_port(), peer().to_string().c_str(), this);
}

template <typename TCP>
Connection::Connection(TCP& tcp, Peer addr)
: Connection(tcp.connect(addr))
{
}

} // < namespace http

#endif // < HTTP_CONNECTION_HPP
11 changes: 11 additions & 0 deletions api/posix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IncludeOS POSIX extensions

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.

### Other providers of POSIX content
* *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.
* *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.

### Guidelines for this folder
* Only actually standardized POSIX content should live here, and only content not allready provided by alternative sources above.
* 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.
39 changes: 39 additions & 0 deletions api/posix/dlfcn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2017 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.

#ifndef POSIX_DLFCN_H
#define POSIX_DLFCN_H

#ifdef __cplusplus
extern "C" {
#endif

#define RTLD_LAZY 1 // Relocations are performed at an implementation-dependent time.
#define RTLD_NOW 2 // Relocations are performed when the object is loaded.
#define RTLD_GLOBAL 3 // All symbols are available for relocation processing of other modules.
#define RTLD_LOCAL 4 // All symbols are not made available for relocation processing by other modules.

void *dlopen(const char *, int);
void *dlsym(void *, const char *);
int dlclose(void *);
char *dlerror(void);

#ifdef __cplusplus
}
#endif

#endif // < POSIX_DLFCN_H
8 changes: 7 additions & 1 deletion api/sys/math.h → api/posix/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#ifndef SYS_MATH_H
#define SYS_MATH_H

#ifdef __cplusplus
extern "C" {
#endif

// Long double math stubs
long double cosl(long double);
Expand Down Expand Up @@ -85,7 +88,10 @@ long double tgammal(long double);
long double truncl(long double);
long double nanl(const char*);


#ifdef __cplusplus
}
#endif

#include_next <math.h>

#endif
Loading

0 comments on commit c1e9172

Please sign in to comment.