Commit 6278d88f authored by octal's avatar octal

Renamed library to pistache

parent 7b2b963d
......@@ -13,13 +13,8 @@ else()
endif()
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
file(GLOB HEADER_FILES "include/*.h")
install(FILES ${HEADER_FILES} DESTINATION include/pistache)
file(GLOB SERIALIZER_HEADER_FILES "include/serializer/*.h")
install(FILES ${SERIALIZER_HEADER_FILES} DESTINATION include/pistache/serializer)
add_subdirectory (src)
include_directories (src)
add_subdirectory (examples)
......
add_executable(http_server http_server.cc)
target_link_libraries(http_server net_static)
function(pistache_example example_name)
set(EXAMPLE_EXECUTABLE run_${example_name})
set(EXAMPLE_SOURCE ${example_name}.cc)
add_executable(hello_server hello_server.cc)
target_link_libraries(hello_server net_static)
add_executable(${EXAMPLE_EXECUTABLE} ${EXAMPLE_SOURCE})
target_link_libraries(${EXAMPLE_EXECUTABLE} pistache)
endfunction()
add_executable(http_client http_client.cc)
target_link_libraries(http_client net_static)
add_executable(custom_header custom_header.cc)
target_link_libraries(custom_header net_static)
add_executable(rest_server rest_server.cc)
target_link_libraries(rest_server net_static)
pistache_example(http_server)
pistache_example(http_client)
pistache_example(rest_server)
pistache_example(custom_header)
find_package(RapidJSON)
if (RapidJSON_FOUND)
include_directories(${RapidJSON_INCLUDE_DIRS})
add_executable(rest_description rest_description.cc)
target_link_libraries(rest_description net_static)
pistache_example(rest_description)
endif()
......@@ -4,12 +4,11 @@
Example of custom headers registering
*/
#include "net.h"
#include "http_headers.h"
#include "client.h"
#include <pistache/net.h>
#include <pistache/http_headers.h>
using namespace Net;
using namespace Net::Http;
using namespace Pistache;
using namespace Pistache::Http;
class XProtocolVersion : public Header::Header {
public:
......
......@@ -4,11 +4,14 @@
* Http client example
*/
#include "net.h"
#include "http.h"
#include "client.h"
#include <atomic>
using namespace Net;
#include <pistache/net.h>
#include <pistache/http.h>
#include <pistache/client.h>
using namespace Pistache;
using namespace Pistache::Http;
int main(int argc, char *argv[]) {
if (argc < 2) {
......
......@@ -4,15 +4,15 @@
Example of an http server
*/
#include "net.h"
#include "http.h"
#include "peer.h"
#include "http_headers.h"
#include "cookie.h"
#include "endpoint.h"
#include <pistache/net.h>
#include <pistache/http.h>
#include <pistache/peer.h>
#include <pistache/http_headers.h>
#include <pistache/cookie.h>
#include <pistache/endpoint.h>
using namespace std;
using namespace Net;
using namespace Pistache;
struct PrintException {
void operator()(std::exception_ptr exc) const {
......@@ -25,7 +25,7 @@ struct PrintException {
};
struct LoadMonitor {
LoadMonitor(const std::shared_ptr<Net::Http::Endpoint>& endpoint)
LoadMonitor(const std::shared_ptr<Http::Endpoint>& endpoint)
: endpoint_(endpoint)
, interval(std::chrono::seconds(1))
{ }
......@@ -49,18 +49,18 @@ struct LoadMonitor {
}
private:
std::shared_ptr<Net::Http::Endpoint> endpoint_;
std::shared_ptr<Http::Endpoint> endpoint_;
std::unique_ptr<std::thread> thread;
std::chrono::seconds interval;
std::atomic<bool> shutdown_;
void run() {
Net::Tcp::Listener::Load old;
Tcp::Listener::Load old;
while (!shutdown_) {
if (!endpoint_->isBound()) continue;
endpoint_->requestLoad(old).then([&](const Net::Tcp::Listener::Load& load) {
endpoint_->requestLoad(old).then([&](const Tcp::Listener::Load& load) {
old = load;
double global = load.global;
......@@ -79,18 +79,18 @@ private:
};
class MyHandler : public Net::Http::Handler {
class MyHandler : public Http::Handler {
HTTP_PROTOTYPE(MyHandler)
void onRequest(
const Net::Http::Request& req,
Net::Http::ResponseWriter response) {
const Http::Request& req,
Http::ResponseWriter response) {
if (req.resource() == "/ping") {
if (req.method() == Net::Http::Method::Get) {
if (req.method() == Http::Method::Get) {
using namespace Net::Http;
using namespace Http;
auto query = req.query();
if (query.has("chunked")) {
......@@ -103,22 +103,22 @@ class MyHandler : public Net::Http::Handler {
response.cookies()
.add(Cookie("lang", "en-US"));
auto stream = response.stream(Net::Http::Code::Ok);
auto stream = response.stream(Http::Code::Ok);
stream << "PO";
stream << "NG";
stream << ends;
}
else {
response.send(Net::Http::Code::Ok, "PONG");
response.send(Http::Code::Ok, "PONG");
}
}
}
else if (req.resource() == "/echo") {
if (req.method() == Net::Http::Method::Post) {
response.send(Net::Http::Code::Ok, req.body(), MIME(Text, Plain));
if (req.method() == Http::Method::Post) {
response.send(Http::Code::Ok, req.body(), MIME(Text, Plain));
} else {
response.send(Net::Http::Code::Method_Not_Allowed);
response.send(Http::Code::Method_Not_Allowed);
}
}
else if (req.resource() == "/exception") {
......@@ -128,8 +128,8 @@ class MyHandler : public Net::Http::Handler {
response.timeoutAfter(std::chrono::seconds(2));
}
else if (req.resource() == "/static") {
if (req.method() == Net::Http::Method::Get) {
Net::Http::serveFile(response, "README.md").then([](ssize_t bytes) {;
if (req.method() == Http::Method::Get) {
Http::serveFile(response, "README.md").then([](ssize_t bytes) {;
std::cout << "Sent " << bytes << " bytes" << std::endl;
}, Async::NoExcept);
}
......@@ -139,16 +139,16 @@ class MyHandler : public Net::Http::Handler {
}
void onTimeout(const Net::Http::Request& req, Net::Http::ResponseWriter response) {
void onTimeout(const Http::Request& req, Http::ResponseWriter response) {
response
.send(Net::Http::Code::Request_Timeout, "Timeout")
.send(Http::Code::Request_Timeout, "Timeout")
.then([=](ssize_t) { }, PrintException());
}
};
int main(int argc, char *argv[]) {
Net::Port port(9080);
Port port(9080);
int thr = 2;
......@@ -159,17 +159,17 @@ int main(int argc, char *argv[]) {
thr = std::stol(argv[2]);
}
Net::Address addr(Net::Ipv4::any(), port);
Address addr(Ipv4::any(), port);
static constexpr size_t Workers = 4;
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
auto server = std::make_shared<Net::Http::Endpoint>(addr);
auto server = std::make_shared<Http::Endpoint>(addr);
auto opts = Net::Http::Endpoint::options()
auto opts = Http::Endpoint::options()
.threads(thr)
.flags(Net::Tcp::Options::InstallSignalHandler);
.flags(Tcp::Options::InstallSignalHandler);
server->init(opts);
server->setHandler(Http::make_handler<MyHandler>());
server->serve();
......
......@@ -4,13 +4,14 @@
Example of how to use the Description mechanism
*/
#include "http.h"
#include "description.h"
#include "endpoint.h"
#include "serializer/rapidjson.h"
#include <pistache/http.h>
#include <pistache/description.h>
#include <pistache/endpoint.h>
#include <pistache/serializer/rapidjson.h>
using namespace std;
using namespace Net;
using namespace Pistache;
namespace Generic {
......@@ -22,15 +23,15 @@ void handleReady(const Rest::Request&, Http::ResponseWriter response) {
class BankerService {
public:
BankerService(Net::Address addr)
: httpEndpoint(std::make_shared<Net::Http::Endpoint>(addr))
BankerService(Address addr)
: httpEndpoint(std::make_shared<Http::Endpoint>(addr))
, desc("Banking API", "0.1")
{ }
void init(size_t thr = 2) {
auto opts = Net::Http::Endpoint::options()
auto opts = Http::Endpoint::options()
.threads(thr)
.flags(Net::Tcp::Options::InstallSignalHandler);
.flags(Tcp::Options::InstallSignalHandler);
httpEndpoint->init(opts);
createDescription();
}
......@@ -130,13 +131,13 @@ private:
response.send(Http::Code::Ok, "The bank is closed, come back later");
}
std::shared_ptr<Net::Http::Endpoint> httpEndpoint;
std::shared_ptr<Http::Endpoint> httpEndpoint;
Rest::Description desc;
Rest::Router router;
};
int main(int argc, char *argv[]) {
Net::Port port(9080);
Port port(9080);
int thr = 2;
......@@ -147,7 +148,7 @@ int main(int argc, char *argv[]) {
thr = std::stol(argv[2]);
}
Net::Address addr(Net::Ipv4::any(), port);
Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
......
......@@ -4,15 +4,16 @@
Example of a REST endpoint with routing
*/
#include "http.h"
#include "router.h"
#include "endpoint.h"
#include <algorithm>
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/endpoint.h>
using namespace std;
using namespace Net;
using namespace Pistache;
void printCookies(const Net::Http::Request& req) {
void printCookies(const Http::Request& req) {
auto cookies = req.cookies();
std::cout << "Cookies: [" << std::endl;
const std::string indent(4, ' ');
......@@ -32,14 +33,14 @@ void handleReady(const Rest::Request&, Http::ResponseWriter response) {
class StatsEndpoint {
public:
StatsEndpoint(Net::Address addr)
: httpEndpoint(std::make_shared<Net::Http::Endpoint>(addr))
StatsEndpoint(Address addr)
: httpEndpoint(std::make_shared<Http::Endpoint>(addr))
{ }
void init(size_t thr = 2) {
auto opts = Net::Http::Endpoint::options()
auto opts = Http::Endpoint::options()
.threads(thr)
.flags(Net::Tcp::Options::InstallSignalHandler);
.flags(Tcp::Options::InstallSignalHandler);
httpEndpoint->init(opts);
setupRoutes();
}
......@@ -55,7 +56,7 @@ public:
private:
void setupRoutes() {
using namespace Net::Rest;
using namespace Rest;
Routes::Post(router, "/record/:name/:value?", Routes::bind(&StatsEndpoint::doRecordMetric, this));
Routes::Get(router, "/value/:name", Routes::bind(&StatsEndpoint::doGetMetric, this));
......@@ -64,7 +65,7 @@ private:
}
void doRecordMetric(const Rest::Request& request, Net::Http::ResponseWriter response) {
void doRecordMetric(const Rest::Request& request, Http::ResponseWriter response) {
auto name = request.param(":name").as<std::string>();
Guard guard(metricsLock);
......@@ -90,7 +91,7 @@ private:
}
void doGetMetric(const Rest::Request& request, Net::Http::ResponseWriter response) {
void doGetMetric(const Rest::Request& request, Http::ResponseWriter response) {
auto name = request.param(":name").as<std::string>();
Guard guard(metricsLock);
......@@ -107,7 +108,7 @@ private:
}
void doAuth(const Rest::Request& request, Net::Http::ResponseWriter response) {
void doAuth(const Rest::Request& request, Http::ResponseWriter response) {
printCookies(request);
response.cookies()
.add(Http::Cookie("lang", "en-US"));
......@@ -144,12 +145,12 @@ private:
Lock metricsLock;
std::vector<Metric> metrics;
std::shared_ptr<Net::Http::Endpoint> httpEndpoint;
std::shared_ptr<Http::Endpoint> httpEndpoint;
Rest::Router router;
};
int main(int argc, char *argv[]) {
Net::Port port(9080);
Port port(9080);
int thr = 2;
......@@ -160,7 +161,7 @@ int main(int argc, char *argv[]) {
thr = std::stol(argv[2]);
}
Net::Address addr(Net::Ipv4::any(), port);
Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
......
......@@ -14,10 +14,11 @@
#include <vector>
#include <mutex>
#include <condition_variable>
#include <condition_variable>
#include "optional.h"
#include "typeid.h"
#include <pistache/optional.h>
#include <pistache/typeid.h>
namespace Pistache {
namespace Async {
class Error : public std::runtime_error {
......@@ -1537,3 +1538,4 @@ namespace Async {
}
} // namespace Async
} // namespace Pistache
......@@ -5,19 +5,20 @@
*/
#pragma once
#include "async.h"
#include "os.h"
#include "http.h"
#include "reactor.h"
#include "timer_pool.h"
#include "view.h"
#include <atomic>
#include <deque>
#include <sys/types.h>
#include <sys/socket.h>
#include <deque>
namespace Net {
#include <pistache/async.h>
#include <pistache/os.h>
#include <pistache/http.h>
#include <pistache/timer_pool.h>
#include <pistache/reactor.h>
#include <pistache/view.h>
namespace Pistache {
namespace Http {
class ConnectionPool;
......@@ -72,7 +73,7 @@ struct Connection : public std::enable_shared_from_this<Connection> {
Connected
};
void connect(Net::Address addr);
void connect(Address addr);
void close();
bool isIdle() const;
bool isConnected() const;
......@@ -131,7 +132,7 @@ private:
std::deque<RequestEntry> inflightRequests;
Net::TimerPool timerPool_;
TimerPool timerPool_;
Private::Parser<Http::Response> parser_;
};
......@@ -354,6 +355,4 @@ private:
};
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -11,9 +11,10 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#define unsafe
......@@ -48,10 +49,12 @@
#define unreachable() __builtin_unreachable()
namespace Pistache {
namespace Const {
static constexpr int MaxBacklog = 128;
static constexpr int MaxEvents = 1024;
static constexpr int MaxBuffer = 4096;
static constexpr int ChunkSize = 1024;
}
} // namespace Const
} // namespace Pistache
......@@ -6,15 +6,15 @@
#pragma once
#include "optional.h"
#include "http_defs.h"
#include <ctime>
#include <string>
#include <map>
#include <unordered_map>
namespace Net {
#include <pistache/optional.h>
#include <pistache/http_defs.h>
namespace Pistache {
namespace Http {
struct Cookie {
......@@ -95,5 +95,4 @@ private:
};
} // namespace Net
} // namespace Http
} // namespace Pistache
......@@ -12,16 +12,15 @@
#include <type_traits>
#include <memory>
#include <algorithm>
#include "http_defs.h"
#include "mime.h"
#include "optional.h"
#include "router.h"
#include "iterator_adapter.h"
namespace Net {
#include <pistache/http_defs.h>
#include <pistache/mime.h>
#include <pistache/optional.h>
#include <pistache/router.h>
#include <pistache/iterator_adapter.h>
namespace Pistache {
namespace Rest {
namespace Type {
// Data Types
......@@ -453,5 +452,4 @@ private:
};
} // namespace Rest
} // namespace Net
} // namespace Pistache
......@@ -6,12 +6,11 @@
#pragma once
#include "listener.h"
#include "net.h"
#include "http.h"
namespace Net {
#include <pistache/listener.h>
#include <pistache/net.h>
#include <pistache/http.h>
namespace Pistache {
namespace Http {
class Endpoint {
......@@ -30,7 +29,7 @@ public:
Options();
};
Endpoint();
Endpoint(const Net::Address& addr);
Endpoint(const Address& addr);
template<typename... Args>
void initArgs(Args&& ...args) {
......@@ -75,7 +74,7 @@ private:
}
std::shared_ptr<Handler> handler_;
Net::Tcp::Listener listener;
Tcp::Listener listener;
};
template<typename Handler>
......@@ -96,5 +95,4 @@ void listenAndServe(Address addr, const Endpoint::Options& options)
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -5,10 +5,13 @@
*/
#pragma once
#include <type_traits>
#include <climits>
#include <iostream>
namespace Pistache {
// Looks like gcc 4.6 does not implement std::underlying_type
namespace detail {
template<size_t N> struct TypeStorage;
......@@ -120,9 +123,11 @@ private:
T val;
};
} // namespace Pistache
#define DEFINE_BITWISE_OP(Op, T) \
inline T operator Op (T lhs, T rhs) { \
typedef detail::UnderlyingType<T>::Type UnderlyingType; \
typedef Pistache::detail::UnderlyingType<T>::Type UnderlyingType; \
return static_cast<T>( \
static_cast<UnderlyingType>(lhs) Op static_cast<UnderlyingType>(rhs) \
); \
......@@ -133,8 +138,8 @@ private:
DEFINE_BITWISE_OP(|, T)
template<typename T>
std::ostream& operator<<(std::ostream& os, Flags<T> flags) {
typedef typename detail::UnderlyingType<T>::Type UnderlyingType;
std::ostream& operator<<(std::ostream& os, Pistache::Flags<T> flags) {
typedef typename Pistache::detail::UnderlyingType<T>::Type UnderlyingType;
auto val = static_cast<UnderlyingType>(static_cast<T>(flags));
for (ssize_t i = (sizeof(UnderlyingType) * CHAR_BIT) - 1; i >= 0; --i) {
......@@ -143,3 +148,4 @@ std::ostream& operator<<(std::ostream& os, Flags<T> flags) {
return os;
}
......@@ -6,24 +6,25 @@
#pragma once
#include <sys/timerfd.h>
#include <type_traits>
#include <stdexcept>
#include <array>
#include <sstream>
#include "net.h"
#include "http_headers.h"
#include "http_defs.h"
#include "cookie.h"
#include "stream.h"
#include "mime.h"
#include "async.h"
#include "peer.h"
#include "tcp.h"
#include "transport.h"
namespace Net {
#include <sys/timerfd.h>
#include <pistache/net.h>
#include <pistache/http_headers.h>
#include <pistache/http_defs.h>
#include <pistache/cookie.h>
#include <pistache/stream.h>
#include <pistache/mime.h>
#include <pistache/async.h>
#include <pistache/peer.h>
#include <pistache/tcp.h>
#include <pistache/transport.h>
namespace Pistache {
namespace Http {
namespace details {
......@@ -40,8 +41,8 @@ namespace details {
};
#define HTTP_PROTOTYPE(Class) \
PROTOTYPE_OF(Net::Tcp::Handler, Class) \
typedef Net::Http::details::prototype_tag tag;
PROTOTYPE_OF(Pistache::Tcp::Handler, Class) \
typedef Pistache::Http::details::prototype_tag tag;
namespace Private {
class ParserBase;
......@@ -338,7 +339,7 @@ inline ResponseStream& flush(ResponseStream& stream) {
template<typename T>
ResponseStream& operator<<(ResponseStream& stream, const T& val) {
Net::Size<T> size;
Size<T> size;
std::ostream os(&stream.buf_);
os << std::hex << size(val) << crlf;
......@@ -737,7 +738,7 @@ namespace Private {
} // namespace Private
class Handler : public Net::Tcp::Handler {
class Handler : public Tcp::Handler {
public:
void onInput(const char* buffer, size_t len, const std::shared_ptr<Tcp::Peer>& peer);
......@@ -761,7 +762,4 @@ std::shared_ptr<H> make_handler(Args&& ...args) {
}
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -5,6 +5,7 @@
*/
#pragma once
#include <string>
#include <ostream>
#include <stdexcept>
......@@ -12,8 +13,7 @@
#include <ctime>
#include <functional>
namespace Net {
namespace Pistache {
namespace Http {
#define HTTP_METHODS \
......@@ -198,14 +198,13 @@ private:
};
} // namespace Http
} // namespace Net
} // namespace Pistache
namespace std {
template<>
struct hash<Net::Http::Method> {
size_t operator()(Net::Http::Method method) const {
struct hash<Pistache::Http::Method> {
size_t operator()(Pistache::Http::Method method) const {
return std::hash<int>()(static_cast<int>(method));
}
};
......
......@@ -6,21 +6,20 @@
#pragma once
#include "mime.h"
#include "net.h"
#include "http_defs.h"
#include <string>
#include <type_traits>
#include <memory>
#include <ostream>
#include <vector>
#define SAFE_HEADER_CAST
#include <pistache/mime.h>
#include <pistache/net.h>
#include <pistache/http_defs.h>
namespace Net {
#define SAFE_HEADER_CAST
namespace Pistache {
namespace Http {
namespace Header {
#ifdef SAFE_HEADER_CAST
......@@ -45,7 +44,7 @@ constexpr uint64_t hash(const char* str)
#ifdef SAFE_HEADER_CAST
#define NAME(header_name) \
static constexpr uint64_t Hash = Net::Http::Header::detail::hash(header_name); \
static constexpr uint64_t Hash = Pistache::Http::Header::detail::hash(header_name); \
uint64_t hash() const { return Hash; } \
static constexpr const char *Name = header_name; \
const char *name() const { return Name; }
......@@ -337,7 +336,7 @@ public:
{ }
explicit Host(const std::string& host);
explicit Host(const std::string& host, Net::Port port)
explicit Host(const std::string& host, Port port)
: host_(host)
, port_(port)
{ }
......@@ -346,11 +345,11 @@ public:
void write(std::ostream& os) const;
std::string host() const { return host_; }
Net::Port port() const { return port_; }
Port port() const { return port_; }
private:
std::string host_;
Net::Port port_;
Port port_;
};
class Location : public Header {
......@@ -438,8 +437,5 @@ private:
};
} // namespace Header
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -9,12 +9,11 @@
#include <unordered_map>
#include <vector>
#include <memory>
#include "http_header.h"
namespace Net {
#include <pistache/http_header.h>
namespace Pistache {
namespace Http {
namespace Header {
class Collection {
......@@ -145,7 +144,5 @@ struct Registrar {
} // namespace Header
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -6,6 +6,8 @@
#pragma once
namespace Pistache {
template<typename Map>
struct FlatMapIteratorAdapter {
typedef typename Map::key_type Key;
......@@ -42,3 +44,5 @@ FlatMapIteratorAdapter<Map>
makeFlatMapIterator(const Map&, typename Map::const_iterator it) {
return FlatMapIteratorAdapter<Map>(it);
}
} // namespace Pistache
......@@ -6,19 +6,20 @@
#pragma once
#include "tcp.h"
#include "net.h"
#include "os.h"
#include "flags.h"
#include "async.h"
#include "reactor.h"
#include <vector>
#include <memory>
#include <thread>
#include <sys/resource.h>
namespace Net {
#include <pistache/tcp.h>
#include <pistache/net.h>
#include <pistache/os.h>
#include <pistache/flags.h>
#include <pistache/async.h>
#include <pistache/reactor.h>
namespace Pistache {
namespace Tcp {
class Peer;
......@@ -88,5 +89,4 @@ private:
};
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -6,15 +6,19 @@
*/
#pragma once
#include "common.h"
#include "os.h"
#include <atomic>
#include <stdexcept>
#include <array>
#include <sys/eventfd.h>
#include <unistd.h>
#include <pistache/common.h>
#include <pistache/os.h>
namespace Pistache {
static constexpr size_t CachelineSize = 64;
typedef char cacheline_pad_t[CachelineSize];
......@@ -414,3 +418,5 @@ private:
cacheline_pad_t pad1;
std::atomic<size_t> dequeueIndex;
};
} // namespace Pistache
......@@ -6,16 +6,15 @@
#pragma once
#include "optional.h"
#include <string>
#include <unordered_map>
#include <stdexcept>
#include <cassert>
namespace Net {
#include <pistache/optional.h>
namespace Pistache {
namespace Http {
namespace Mime {
#define MIME_TYPES \
......@@ -213,13 +212,11 @@ inline bool operator==(const MediaType& lhs, const MediaType& rhs) {
}
} // namespace Mime
} // namespace Http
} // namespace Net
} // namespace Pistache
#define MIME(top, sub) \
Net::Http::Mime::MediaType(Net::Http::Mime::Type::top, Net::Http::Mime::Subtype::sub)
Pistache::Http::Mime::MediaType(Pistache::Http::Mime::Type::top, Pistache::Http::Mime::Subtype::sub)
#define MIME3(top, sub, suffix) \
Net::Http::Mime::MediaType(Net::Http::Mime::Type::top, Net::Http::Mime::Subtype::sub, Net::Http::Mime::Suffix::suffix)
Pistache::Http::Mime::MediaType(Pistache::Http::Mime::Type::top, Pistache::Http::Mime::Subtype::sub, Pistache::Http::Mime::Suffix::suffix)
......@@ -5,12 +5,14 @@
*/
#pragma once
#include <string>
#include <sys/socket.h>
#include <cstring>
#include <stdexcept>
#include <limits>
#include <sys/socket.h>
#ifndef _KERNEL_FASTOPEN
#define _KERNEL_FASTOPEN
......@@ -20,7 +22,7 @@
#endif
#endif
namespace Net {
namespace Pistache {
class Port {
public:
......@@ -147,5 +149,4 @@ struct Size<char> {
}
};
} // namespace Net
} // namespace Pistache
......@@ -14,13 +14,15 @@
#include <tuple>
#include <functional>
namespace Pistache {
template<typename T> class Optional;
namespace types {
template<typename T>
class Some {
public:
template<typename U> friend class ::Optional;
template<typename U> friend class Pistache::Optional;
Some(const T &val) : val_(val) { }
Some(T &&val) : val_(std::move(val)) { }
......@@ -376,3 +378,5 @@ Optional<T> optionally_filter(const Optional<T> &option, Func func) {
return None();
}
} // namespace Pistache
......@@ -10,9 +10,13 @@
#include <chrono>
#include <vector>
#include <bitset>
#include <sched.h>
#include "flags.h"
#include "common.h"
#include <pistache/flags.h>
#include <pistache/common.h>
namespace Pistache {
typedef int Fd;
......@@ -135,3 +139,4 @@ private:
int event_fd;
};
} // namespace Pistache
......@@ -6,17 +6,17 @@
#pragma once
#include "net.h"
#include "os.h"
#include "async.h"
#include "stream.h"
#include <string>
#include <iostream>
#include <memory>
#include <unordered_map>
namespace Net {
#include <pistache/net.h>
#include <pistache/os.h>
#include <pistache/async.h>
#include <pistache/stream.h>
namespace Pistache {
namespace Tcp {
class Transport;
......@@ -68,5 +68,4 @@ private:
std::ostream& operator<<(std::ostream& os, const Peer& peer);
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -9,12 +9,16 @@
#include <type_traits>
#include <memory>
namespace Pistache {
/* In a sense, a Prototype is just a class that provides a clone() method */
template<typename Class>
struct Prototype {
virtual std::shared_ptr<Class> clone() const = 0;
};
} // namespace Pistache
#define PROTOTYPE_OF(Base, Class) \
private: \
std::shared_ptr<Base> clone() const { \
......
......@@ -10,19 +10,22 @@
#pragma once
#include "flags.h"
#include "os.h"
#include "net.h"
#include "prototype.h"
#include <thread>
#include <mutex>
#include <atomic>
#include <memory>
#include <unordered_map>
#include <sys/time.h>
#include <sys/resource.h>
#include <atomic>
#include <pistache/flags.h>
#include <pistache/os.h>
#include <pistache/net.h>
#include <pistache/prototype.h>
namespace Pistache {
namespace Aio {
// A set of fds that are ready
......@@ -222,3 +225,4 @@ private:
};
} // namespace Aio
} // namespace Pistache
/*
Mathieu Stefani, 27 février 2016
A special bind() method for REST routes
*/
#pragma once
namespace Pistache {
namespace Rest {
namespace Route {
void Get(Router& router, std::string resource, Route::Handler handler);
void Post(Router& router, std::string resource, Route::Handler handler);
void Put(Router& router, std::string resource, Route::Handler handler);
void Delete(Router& router, std::string resource, Route::Handler handler);
namespace details {
template <class... Args>
struct TypeList
{
template<size_t N>
struct At {
static_assert(N < sizeof...(Args), "Invalid index");
typedef typename std::tuple_element<N, std::tuple<Args...>>::type Type;
};
};
template<typename... Args>
void static_checks() {
static_assert(sizeof...(Args) == 2, "Function should take 2 parameters");
typedef details::TypeList<Args...> Arguments;
// Disabled now as it
// 1/ does not compile
// 2/ might not be relevant
#if 0
static_assert(std::is_same<Arguments::At<0>::Type, const Rest::Request&>::value, "First argument should be a const Rest::Request&");
static_assert(std::is_same<typename Arguments::At<0>::Type, Http::Response>::value, "Second argument should be a Http::Response");
#endif
}
}
template<typename Result, typename Cls, typename... Args, typename Obj>
Route::Handler bind(Result (Cls::*func)(Args...), Obj obj) {
details::static_checks<Args...>();
#define CALL_MEMBER_FN(obj, pmf) ((obj)->*(pmf))
return [=](const Rest::Request& request, Http::ResponseWriter response) {
CALL_MEMBER_FN(obj, func)(request, std::move(response));
};
#undef CALL_MEMBER_FN
}
template<typename Result, typename... Args>
Route::Handler bind(Result (*func)(Args...)) {
details::static_checks<Args...>();
return [=](const Rest::Request& request, Http::ResponseWriter response) {
func(request, std::move(response));
};
}
} // namespace Route
} // namespace Rest
} // namespace Pistache
......@@ -8,12 +8,12 @@
#include <string>
#include <tuple>
#include "http.h"
#include "http_defs.h"
#include "flags.h"
namespace Net {
#include <pistache/http.h>
#include <pistache/http_defs.h>
#include <pistache/flags.h>
namespace Pistache {
namespace Rest {
class Description;
......@@ -63,7 +63,7 @@ class Request;
struct Route {
enum class Result { Ok, Failure };
typedef std::function<Result (const Request&, Net::Http::ResponseWriter)> Handler;
typedef std::function<Result (const Request&, Http::ResponseWriter)> Handler;
Route(std::string resource, Http::Method method, Handler handler)
: resource_(std::move(resource))
......@@ -119,7 +119,7 @@ private:
};
std::string resource_;
Net::Http::Method method_;
Http::Method method_;
Handler handler_;
/* @Performance: since we know that resource_ will live as long as the vector underneath,
* we would benefit from std::experimental::string_view to store fragments.
......@@ -167,7 +167,7 @@ private:
namespace Private {
class RouterHandler : public Net::Http::Handler {
class RouterHandler : public Http::Handler {
public:
RouterHandler(const Rest::Router& router);
......@@ -176,7 +176,7 @@ namespace Private {
Http::ResponseWriter response);
private:
std::shared_ptr<Net::Tcp::Handler> clone() const {
std::shared_ptr<Tcp::Handler> clone() const {
return std::make_shared<RouterHandler>(router);
}
......@@ -267,7 +267,5 @@ namespace Routes {
}
} // namespace Routing
} // namespace Rest
} // namespace Net
} // namespace Pistache
......@@ -6,15 +6,14 @@
#pragma once
#include "description.h"
#include <rapidjson/prettywriter.h>
#include "http_defs.h"
#include "mime.h"
namespace Net {
#include <pistache/description.h>
#include <pistache/http_defs.h>
#include <pistache/mime.h>
namespace Pistache {
namespace Rest {
namespace Serializer {
template<typename Writer>
......@@ -212,7 +211,5 @@ std::string rapidJson(const Description& desc) {
}
} // namespace Serializer
} // namespace Rest
} // namespace Net
} // namespace Pistache
......@@ -13,7 +13,10 @@
#include <vector>
#include <limits>
#include <iostream>
#include "os.h"
#include <pistache/os.h>
namespace Pistache {
static constexpr char CR = 0xD;
static constexpr char LF = 0xA;
......@@ -332,3 +335,5 @@ bool match_until(std::initializer_list<char> chars, StreamCursor& cursor, CaseSe
bool match_double(double* val, StreamCursor& cursor);
void skip_whitespaces(StreamCursor& cursor);
} // namespace Pistache
......@@ -6,13 +6,13 @@
#pragma once
#include "flags.h"
#include "prototype.h"
#include <memory>
#include <stdexcept>
namespace Net {
#include <pistache/flags.h>
#include <pistache/prototype.h>
namespace Pistache {
namespace Tcp {
class Peer;
......@@ -56,5 +56,4 @@ private:
};
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -14,11 +14,13 @@
#include <vector>
#include <mutex>
#include <atomic>
#include <unistd.h>
#include "os.h"
#include "reactor.h"
namespace Net {
#include <pistache/os.h>
#include <pistache/reactor.h>
namespace Pistache {
namespace Default {
static constexpr size_t InitialPoolSize = 128;
......@@ -79,4 +81,4 @@ private:
std::vector<std::shared_ptr<Entry>> timers;
};
} // namespace Net
} // namespace Pistache
......@@ -6,14 +6,13 @@
#pragma once
#include "reactor.h"
#include "mailbox.h"
#include "optional.h"
#include "async.h"
#include "stream.h"
namespace Net {
#include <pistache/reactor.h>
#include <pistache/mailbox.h>
#include <pistache/optional.h>
#include <pistache/async.h>
#include <pistache/stream.h>
namespace Pistache {
namespace Tcp {
class Peer;
......@@ -50,7 +49,7 @@ public:
auto it = toWrite.find(fd);
if (it != std::end(toWrite)) {
reject(Net::Error("Multiple writes on the same fd"));
reject(Pistache::Error("Multiple writes on the same fd"));
return;
}
......@@ -255,5 +254,4 @@ private:
};
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -11,6 +11,8 @@
#pragma once
namespace Pistache {
class TypeId {
public:
template<typename T>
......@@ -51,9 +53,11 @@ inline bool operator<(const TypeId& lhs, const TypeId& rhs) {
#undef APPLY_OP
} // namespace Pistache
namespace std {
template<> struct hash<TypeId> {
size_t operator()(const TypeId& id) {
template<> struct hash<Pistache::TypeId> {
size_t operator()(const Pistache::TypeId& id) {
return static_cast<size_t>(id);
}
};
......
......@@ -13,6 +13,8 @@
#include <cstring>
#include <stdexcept>
namespace Pistache {
template<typename T>
class ViewBase {
public:
......@@ -253,3 +255,5 @@ View<typename impl::ViewBuilder<Cont>::Type> make_view(const Cont& cont, size_t
{
return impl::ViewBuilder<Cont>::buildSized(cont, size);
}
} // namespace Pistache
......@@ -2,17 +2,41 @@ file (GLOB COMMON_SOURCE_FILES "common/*.cc")
file (GLOB SERVER_SOURCE_FILES "server/*.cc")
file (GLOB CLIENT_SOURCE_FILES "client/*.cc")
file (GLOB INCLUDE_FILES ${PROJECT_SOURCE_DIR}/include/pistache/*h)
set(SOURCE_FILES
${COMMON_SOURCE_FILES}
${SERVER_SOURCE_FILES}
${CLIENT_SOURCE_FILES}
${INCLUDE_FILES}
)
add_library(pistache ${SOURCE_FILES})
set_target_properties(pistache PROPERTIES
OUTPUT_NAME "pistache"
VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION}
)
add_library(net_static ${SOURCE_FILES})
target_link_libraries(net_static pthread)
install(TARGETS net_static DESTINATION lib)
target_include_directories(pistache PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
)
set(include_install_dir "include")
set(lib_install_dir "lib/")
set(bin_install_dir "bin/")
target_link_libraries(pistache pthread)
add_library(net SHARED ${SOURCE_FILES})
target_link_libraries(net pthread)
install(TARGETS net DESTINATION lib)
install(
TARGETS pistache
EXPORT ${targets_export_name}
ARCHIVE DESTINATION ${lib_install_dir}
LIBRARY DESTINATION ${lib_install_dir}
RUNTIME DESTINATION ${bin_install_dir}
INCLUDES DESTINATION ${include_install_dir})
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/pistache"
DESTINATION ${include_install_dir}
FILES_MATCHING PATTERN "*.*h")
......@@ -4,29 +4,32 @@
Implementation of the Http client
*/
#include "client.h"
#include "stream.h"
#include <algorithm>
#include <sys/sendfile.h>
#include <netdb.h>
using namespace Polling;
#include <pistache/client.h>
#include <pistache/stream.h>
namespace Net {
namespace Pistache {
using namespace Polling;
namespace Http {
namespace {
Net::Address httpAddr(const StringView& view) {
Address httpAddr(const StringView& view) {
auto str = view.toString();
auto pos = str.find(':');
if (pos == std::string::npos) {
return Net::Address(std::move(str), 80);
return Address(std::move(str), 80);
}
auto host = str.substr(0, pos);
auto port = std::stoi(str.substr(pos + 1));
return Net::Address(std::move(host), port);
return Address(std::move(host), port);
}
}
......@@ -68,8 +71,10 @@ namespace {
} while (0)
template<typename H, typename Stream, typename... Args>
typename std::enable_if<Header::IsHeader<H>::value, Stream&>::type
typename std::enable_if<Http::Header::IsHeader<H>::value, Stream&>::type
writeHeader(Stream& stream, Args&& ...args) {
using Http::crlf;
H header(std::forward<Args>(args)...);
stream << H::Name << ": ";
......@@ -80,7 +85,9 @@ namespace {
return stream;
}
bool writeHeaders(const Header::Collection& headers, DynamicStreamBuf& buf) {
bool writeHeaders(const Http::Header::Collection& headers, DynamicStreamBuf& buf) {
using Http::crlf;
std::ostream os(&buf);
for (const auto& header: headers.list()) {
......@@ -92,7 +99,9 @@ namespace {
return true;
}
bool writeCookies(const CookieJar& cookies, DynamicStreamBuf& buf) {
bool writeCookies(const Http::CookieJar& cookies, DynamicStreamBuf& buf) {
using Http::crlf;
std::ostream os(&buf);
for (const auto& cookie: cookies) {
OUT(os << "Cookie: ");
......@@ -105,6 +114,8 @@ namespace {
}
bool writeRequest(const Http::Request& request, DynamicStreamBuf &buf) {
using Http::crlf;
std::ostream os(&buf);
auto res = request.resource();
......@@ -125,10 +136,10 @@ namespace {
if (!writeCookies(request.cookies(), buf)) return false;
if (!writeHeaders(request.headers(), buf)) return false;
if (!writeHeader<Header::UserAgent>(os, UA)) return false;
if (!writeHeader<Header::Host>(os, host.toString())) return false;
if (!writeHeader<Http::Header::UserAgent>(os, UA)) return false;
if (!writeHeader<Http::Header::Host>(os, host.toString())) return false;
if (!body.empty()) {
if (!writeHeader<Header::ContentLength>(os, body.size())) return false;
if (!writeHeader<Http::Header::ContentLength>(os, body.size())) return false;
}
OUT(os << crlf);
......@@ -255,7 +266,7 @@ Transport::asyncSendRequestImpl(
}
else {
cleanUp();
req.reject(Net::Error::system("Could not send request"));
req.reject(Error::system("Could not send request"));
}
break;
}
......@@ -363,7 +374,7 @@ Transport::handleTimeout(const std::shared_ptr<Connection>& connection) {
}
void
Connection::connect(Net::Address addr)
Connection::connect(Address addr)
{
struct addrinfo hints;
struct addrinfo *addrs;
......@@ -474,7 +485,7 @@ Connection::handleError(const char* error) {
timerPool_.releaseTimer(req.timer);
}
req.reject(Net::Error(error));
req.reject(Error(error));
req.onDone();
}
......@@ -898,5 +909,4 @@ Client::processRequestQueue() {
}
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,13 +4,13 @@
Cookie implementation
*/
#include "cookie.h"
#include "stream.h"
#include <iterator>
#include <unordered_map>
namespace Net {
#include <pistache/cookie.h>
#include <pistache/stream.h>
namespace Pistache {
namespace Http {
namespace {
......@@ -226,5 +226,4 @@ CookieJar::has(const std::string& name) const {
}
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,13 +4,13 @@
Implementation of the description system
*/
#include "description.h"
#include "http_header.h"
#include <sstream>
#include <algorithm>
namespace Net {
#include <pistache/description.h>
#include <pistache/http_header.h>
namespace Pistache {
namespace Rest {
const char* schemeString(Scheme scheme) {
......@@ -447,5 +447,4 @@ Swagger::install(Rest::Router& router) {
} // namespace Rest
} // namespace Net
} // namespace Pistache
......@@ -9,20 +9,21 @@
#include <stdexcept>
#include <ctime>
#include <iomanip>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h"
#include "http.h"
#include "net.h"
#include "peer.h"
#include "transport.h"
using namespace std;
#include <pistache/common.h>
#include <pistache/http.h>
#include <pistache/net.h>
#include <pistache/peer.h>
#include <pistache/transport.h>
namespace Net {
using namespace std;
namespace Pistache {
namespace Http {
template<typename H, typename Stream, typename... Args>
......@@ -673,7 +674,7 @@ serveFile(ResponseWriter& response, const char* fileName, const Mime::MediaType&
/* @Improvement: maybe could we check for errno here and emit a different error
message
*/
throw HttpError(Net::Http::Code::Not_Found, "");
throw HttpError(Http::Code::Not_Found, "");
}
int res = ::fstat(fd, &sb);
......@@ -796,5 +797,4 @@ Handler::getParser(const std::shared_ptr<Tcp::Peer>& peer) const {
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,13 +4,13 @@
Implementation of http definitions
*/
#include "http_defs.h"
#include "common.h"
#include <iostream>
#include <iomanip>
namespace Net {
#include <pistache/http_defs.h>
#include <pistache/common.h>
namespace Pistache {
namespace Http {
namespace {
......@@ -189,5 +189,4 @@ HttpError::HttpError(int code, std::string reason)
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,21 +4,20 @@
Implementation of common HTTP headers described by the RFC
*/
#include "http_header.h"
#include "common.h"
#include "http.h"
#include "stream.h"
#include <stdexcept>
#include <iterator>
#include <cstring>
#include <iostream>
using namespace std;
#include <pistache/http_header.h>
#include <pistache/common.h>
#include <pistache/http.h>
#include <pistache/stream.h>
namespace Net {
using namespace std;
namespace Pistache {
namespace Http {
namespace Header {
const char* encodingString(Encoding encoding) {
......@@ -486,7 +485,5 @@ ContentType::write(std::ostream& os) const {
}
} // namespace Header
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,16 +4,15 @@
Headers registry
*/
#include "http_headers.h"
#include <unordered_map>
#include <iterator>
#include <stdexcept>
#include <iostream>
namespace Net {
#include <pistache/http_headers.h>
namespace Pistache {
namespace Http {
namespace Header {
namespace {
......@@ -190,7 +189,5 @@ Collection::getImpl(const std::string& name) const {
}
} // namespace Header
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,16 +4,15 @@
Implementaton of MIME Type parsing
*/
#include "mime.h"
#include "http.h"
#include <cstring>
using namespace std;
#include <pistache/mime.h>
#include <pistache/http.h>
namespace Net {
using namespace std;
namespace Pistache {
namespace Http {
namespace Mime {
std::string
......@@ -329,8 +328,5 @@ MediaType::isValid() const {
}
} // namespace Mime
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -3,19 +3,20 @@
*/
#include "net.h"
#include "common.h"
#include <stdexcept>
#include <limits>
#include <cstring>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream>
#include <pistache/net.h>
#include <pistache/common.h>
using namespace std;
namespace Net {
namespace Pistache {
Port::Port(uint16_t port)
: port(port)
......@@ -139,4 +140,4 @@ Error::system(const char* message) {
}
} // namespace Net
} // namespace Pistache
......@@ -3,18 +3,23 @@
*/
#include "os.h"
#include "common.h"
#include <unistd.h>
#include <fcntl.h>
#include <fstream>
#include <iterator>
#include <algorithm>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <pistache/os.h>
#include <pistache/common.h>
#include <pistache/io.h>
using namespace std;
namespace Pistache {
int hardware_concurrency() {
std::ifstream cpuinfo("/proc/cpuinfo");
if (cpuinfo) {
......@@ -289,3 +294,5 @@ NotifyFd::tryRead() const {
return true;
}
} // namespace Pistache
......@@ -3,15 +3,16 @@
*/
#include "peer.h"
#include "async.h"
#include "transport.h"
#include <iostream>
#include <stdexcept>
#include <sys/socket.h>
namespace Net {
#include <pistache/peer.h>
#include <pistache/async.h>
#include <pistache/transport.h>
namespace Pistache {
namespace Tcp {
using namespace std;
......@@ -104,5 +105,4 @@ Peer::transport() const {
}
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -4,8 +4,9 @@
Implementation of the Reactor
*/
#include "reactor.h"
#include <pistache/reactor.h>
namespace Pistache {
namespace Aio {
struct Reactor::Impl {
......@@ -599,3 +600,4 @@ AsyncContext::singleThreaded() {
}
} // namespace Aio
} // namespace Pistache
......@@ -3,14 +3,18 @@
*/
#include "stream.h"
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <pistache/stream.h>
namespace Pistache {
FileBuffer::FileBuffer(const char* fileName)
: fileName_(fileName)
{
......@@ -236,3 +240,5 @@ skip_whitespaces(StreamCursor& cursor) {
cursor.advance(1);
}
}
} // namespace Pistache
......@@ -4,11 +4,10 @@
TCP
*/
#include "tcp.h"
#include "peer.h"
namespace Net {
#include <pistache/tcp.h>
#include <pistache/peer.h>
namespace Pistache {
namespace Tcp {
Handler::Handler()
......@@ -32,5 +31,4 @@ Handler::onDisconnection(const std::shared_ptr<Tcp::Peer>& peer) {
}
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -4,10 +4,11 @@
Implementation of the timer pool
*/
#include "timer_pool.h"
#include <sys/timerfd.h>
namespace Net {
#include <pistache/timer_pool.h>
namespace Pistache {
void
TimerPool::Entry::initialize() {
......@@ -75,5 +76,4 @@ TimerPool::releaseTimer(const std::shared_ptr<Entry>& timer) {
timer->state.store(static_cast<uint32_t>(TimerPool::Entry::State::Idle));
}
} // namespace Net
} // namespace Pistache
#include "transport.h"
#include "peer.h"
#include "tcp.h"
#include "os.h"
/* traqnsport.cc
Mathieu Stefani, 02 July 2017
TCP transport handling
*/
#include <sys/sendfile.h>
#include <sys/timerfd.h>
using namespace Polling;
#include <pistache/transport.h>
#include <pistache/peer.h>
#include <pistache/tcp.h>
#include <pistache/os.h>
namespace Net {
namespace Pistache {
using namespace Polling;
namespace Tcp {
......@@ -209,7 +218,7 @@ Transport::asyncWriteImpl(
}
else {
cleanUp();
deferred.reject(Net::Error::system("Could not write data"));
deferred.reject(Pistache::Error::system("Could not write data"));
}
break;
}
......@@ -266,7 +275,7 @@ Transport::armTimerMsImpl(TimerEntry entry) {
int res = timerfd_settime(entry.fd, 0, &spec, 0);
if (res == -1) {
entry.deferred.reject(Net::Error::system("Could not set timer time"));
entry.deferred.reject(Pistache::Error::system("Could not set timer time"));
return;
}
......@@ -342,10 +351,10 @@ Transport::handleTimer(TimerEntry entry) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
return;
else
entry.deferred.reject(Net::Error::system("Could not read timerfd"));
entry.deferred.reject(Pistache::Error::system("Could not read timerfd"));
} else {
if (res != sizeof(numWakeups)) {
entry.deferred.reject(Net::Error("Read invalid number of bytes for timer fd: "
entry.deferred.reject(Pistache::Error("Read invalid number of bytes for timer fd: "
+ std::to_string(entry.fd)));
}
else {
......@@ -392,5 +401,4 @@ Transport::getPeer(Polling::Tag tag)
}
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -5,15 +5,13 @@
*/
#include "endpoint.h"
#include "tcp.h"
#include "peer.h"
namespace Net {
#include <pistache/endpoint.h>
#include <pistache/tcp.h>
#include <pistache/peer.h>
namespace Pistache {
namespace Http {
Endpoint::Options::Options()
: threads_(1)
{ }
......@@ -39,7 +37,7 @@ Endpoint::Options::backlog(int val) {
Endpoint::Endpoint()
{ }
Endpoint::Endpoint(const Net::Address& addr)
Endpoint::Endpoint(const Address& addr)
: listener(addr)
{ }
......@@ -92,5 +90,4 @@ Endpoint::options() {
}
} // namespace Http
} // namespace Net
} // namespace Pistache
......@@ -4,6 +4,9 @@
*/
#include <iostream>
#include <cassert>
#include <cstring>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
......@@ -15,18 +18,16 @@
#include <signal.h>
#include <sys/timerfd.h>
#include <sys/sendfile.h>
#include <cassert>
#include <cstring>
#include "listener.h"
#include "peer.h"
#include "common.h"
#include "os.h"
#include "transport.h"
using namespace std;
#include <pistache/listener.h>
#include <pistache/peer.h>
#include <pistache/common.h>
#include <pistache/os.h>
#include <pistache/transport.h>
namespace Net {
using namespace std;
namespace Pistache {
namespace Tcp {
namespace {
......@@ -329,5 +330,4 @@ Listener::dispatchPeer(const std::shared_ptr<Peer>& peer) {
}
} // namespace Tcp
} // namespace Net
} // namespace Pistache
......@@ -4,12 +4,12 @@
Rest routing implementation
*/
#include "router.h"
#include "description.h"
#include <algorithm>
namespace Net {
#include <pistache/router.h>
#include <pistache/description.h>
namespace Pistache {
namespace Rest {
Request::Request(
......@@ -352,7 +352,5 @@ void Options(Router& router, std::string resource, Route::Handler handler) {
}
} // namespace Routes
} // namespace Rest
} // namespace Net
} // namespace Pistache
......@@ -3,7 +3,7 @@ function(pistache_test test_name)
set(TEST_SOURCE ${test_name}.cc)
add_executable(${TEST_EXECUTABLE} ${TEST_SOURCE})
target_link_libraries(${TEST_EXECUTABLE} gtest gtest_main net_static)
target_link_libraries(${TEST_EXECUTABLE} gtest gtest_main pistache)
add_test(${test_name} ${TEST_EXECUTABLE})
endfunction()
......
#include "gtest/gtest.h"
#include "async.h"
#include <thread>
#include <algorithm>
#include <deque>
......@@ -7,6 +7,10 @@
#include <condition_variable>
#include <random>
#include <pistache/async.h>
using namespace Pistache;
Async::Promise<int> doAsync(int N)
{
Async::Promise<int> promise(
......
#include "gtest/gtest.h"
#include "cookie.h"
using namespace Net;
using namespace Net::Http;
#include <pistache/cookie.h>
using namespace Pistache;
using namespace Pistache::Http;
void parse(const char* str, std::function<void (const Cookie&)> testFunc)
{
......
#include "gtest/gtest.h"
#include "http_headers.h"
using namespace Net::Http;
#include <pistache/http_headers.h>
using namespace Pistache::Http;
TEST(headers_test, accept) {
Header::Accept a1;
......
#include "gtest/gtest.h"
#include "mime.h"
#include "http.h"
using namespace Net::Http;
using namespace Net::Http::Mime;
#include <pistache/mime.h>
#include <pistache/http.h>
using namespace Pistache::Http;
using namespace Pistache::Http::Mime;
TEST(mime_test, basic_test) {
MediaType m1(Type::Text, Subtype::Plain);
......
......@@ -6,10 +6,11 @@
#include "gtest/gtest.h"
#include "router.h"
#include <algorithm>
using namespace Net;
#include <pistache/router.h>
using namespace Pistache;
bool match(const Rest::Route& route, const std::string& req) {
return std::get<0>(route.match(req));
......@@ -75,8 +76,8 @@ bool matchSplat(
Rest::Route
makeRoute(std::string value) {
auto noop = [](const Net::Http::Request&, Net::Http::Response) { return Rest::Route::Result::Ok; };
return Rest::Route(value, Net::Http::Method::Get, noop);
auto noop = [](const Http::Request&, Http::Response) { return Rest::Route::Result::Ok; };
return Rest::Route(value, Http::Method::Get, noop);
}
TEST(router_test, test_fixed_routes) {
......
#include "gtest/gtest.h"
#include "typeid.h"
#include <pistache/typeid.h>
using namespace Pistache;
TEST(type_id_test, basic_test) {
ASSERT_EQ(TypeId::of<int>(), TypeId::of<int>());
......
#include "gtest/gtest.h"
#include "view.h"
#include <pistache/view.h>
using namespace Pistache;
template<typename T>
std::vector<T> make_vec(std::initializer_list<T> list) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment