forked from mirrors/kore
Add C++ example.
This commit is contained in:
parent
3a904cdde3
commit
0da755a9fb
|
@ -0,0 +1,5 @@
|
|||
*.o
|
||||
.objs
|
||||
cpp.so
|
||||
assets.h
|
||||
cert
|
|
@ -0,0 +1,20 @@
|
|||
Kore example showing how to use C++ support!
|
||||
|
||||
All functions accessible to kore must have their prototypes wrapped with the extern keyword like so:
|
||||
```
|
||||
extern “C” {
|
||||
int pageA(struct http_request *);
|
||||
int pageB(struct http_request *);
|
||||
int validatorA(struct http_request *, char *);
|
||||
}
|
||||
```
|
||||
|
||||
You will also need to compile kore with the KORE_CPP_SUPPORT environment variable enabled:
|
||||
```
|
||||
# env KORE_CPP_SUPPORT=1 make
|
||||
```
|
||||
|
||||
Run:
|
||||
```
|
||||
# kore run
|
||||
```
|
|
@ -0,0 +1,11 @@
|
|||
# Placeholder configuration
|
||||
|
||||
bind 127.0.0.1 8888
|
||||
load ./cpp.so
|
||||
ssl_dhparam dh2048.pem
|
||||
|
||||
domain 127.0.0.1 {
|
||||
certfile cert/server.crt
|
||||
certkey cert/server.key
|
||||
static / page
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
-----BEGIN DH PARAMETERS-----
|
||||
MIIBCAKCAQEAn4f4Qn5SudFjEYPWTbUaOTLUH85YWmmPFW1+b5bRa9ygr+1wfamv
|
||||
VKVT7jO8c4msSNikUf6eEfoH0H4VTCaj+Habwu+Sj+I416r3mliMD4SjNsUJrBrY
|
||||
Y0QV3ZUgZz4A8ARk/WwQcRl8+ZXJz34IaLwAcpyNhoV46iHVxW0ty8ND0U4DIku/
|
||||
PNayKimu4BXWXk4RfwNVP59t8DQKqjshZ4fDnbotskmSZ+e+FHrd+Kvrq/WButvV
|
||||
Bzy9fYgnUlJ82g/bziCI83R2xAdtH014fR63MpElkqdNeChb94pPbEdFlNUvYIBN
|
||||
xx2vTUQMqRbB4UdG2zuzzr5j98HDdblQ+wIBAg==
|
||||
-----END DH PARAMETERS-----
|
|
@ -0,0 +1,17 @@
|
|||
#include <kore/kore.h>
|
||||
#include <kore/http.h>
|
||||
|
||||
#include "example_class.h"
|
||||
|
||||
extern "C" {
|
||||
int page(struct http_request *);
|
||||
}
|
||||
|
||||
int
|
||||
page(struct http_request *req)
|
||||
{
|
||||
example_class example;
|
||||
const char* str = example.a();
|
||||
http_response(req, 200, static_cast<void*>(const_cast<char*>(str)), strlen(str));
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// example_class.cpp
|
||||
//
|
||||
//
|
||||
// Created by Geenz on 4/1/15.
|
||||
//
|
||||
//
|
||||
|
||||
#include "example_class.h"
|
||||
|
||||
example_class::example_class() {
|
||||
|
||||
}
|
||||
|
||||
example_class::~example_class() {
|
||||
|
||||
}
|
||||
|
||||
const char* example_class::a() {
|
||||
return "Hello world!";
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// example_class.h
|
||||
//
|
||||
//
|
||||
// Created by Geenz on 4/1/15.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef ____example_class__
|
||||
#define ____example_class__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class example_class {
|
||||
|
||||
public:
|
||||
example_class();
|
||||
~example_class();
|
||||
|
||||
const char* a();
|
||||
};
|
||||
|
||||
#endif /* defined(____example_class__) */
|
Loading…
Reference in New Issue