Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython-lwan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryton Lacquement
cython-lwan
Commits
f470aa1f
Commit
f470aa1f
authored
Jul 05, 2018
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove interface.c
parent
e4e99ed0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
47 deletions
+41
-47
interface.c
interface.c
+0
-33
lwan_wrapper.pyx
lwan_wrapper.pyx
+40
-13
setup.py
setup.py
+1
-1
No files found.
interface.c
deleted
100644 → 0
View file @
e4e99ed0
#include <lwan/lwan.h>
extern
int
handle_root
(
struct
lwan_request
*
request
,
struct
lwan_response
*
response
);
extern
int
handle_fibonacci
(
struct
lwan_request
*
request
,
struct
lwan_response
*
response
);
LWAN_HANDLER
(
root
)
{
return
handle_root
(
request
,
response
);
}
LWAN_HANDLER
(
fibonacci
)
{
return
handle_fibonacci
(
request
,
response
);
}
static
int
listen_and_serve
(
void
)
{
const
struct
lwan_url_map
default_map
[]
=
{
{
.
prefix
=
"/"
,
.
handler
=
LWAN_HANDLER_REF
(
root
)
},
{
.
prefix
=
"/fibonacci"
,
.
handler
=
LWAN_HANDLER_REF
(
fibonacci
)
},
{
.
prefix
=
NULL
}
};
struct
lwan
l
;
lwan_init
(
&
l
);
lwan_set_url_map
(
&
l
,
default_map
);
lwan_main_loop
(
&
l
);
lwan_shutdown
(
&
l
);
return
0
;
}
lwan_wrapper.pyx
View file @
f470aa1f
from
libc.string
cimport
strlen
from
libc.stdlib
cimport
calloc
,
free
cdef
extern
from
"lwan/lwan.h"
nogil
:
struct
lwan
:
pass
cdef
extern
from
"lwan/lwan.h"
:
struct
lwan_request
:
pass
struct
lwan_response
:
char
*
mime_type
lwan_strbuf
*
buffer
enum
lwan_http_status
:
HTTP_OK
struct
lwan_url_map
:
lwan_http_status
(
*
handler
)(
lwan_request
*
request
,
lwan_response
*
response
,
void
*
data
)
char
*
prefix
void
lwan_init
(
lwan
*
l
)
void
lwan_set_url_map
(
lwan
*
l
,
lwan_url_map
*
map
)
void
lwan_main_loop
(
lwan
*
l
)
void
lwan_shutdown
(
lwan
*
l
)
cdef
extern
from
"lwan/lwan-strbuf.h"
:
struct
lwan_strbuf
:
pass
bint
lwan_strbuf_set_static
(
lwan_strbuf
*
s1
,
const
char
*
s2
,
size_t
sz
)
nogil
bint
lwan_strbuf_printf
(
lwan_strbuf
*
s
,
const
char
*
fmt
,
...)
nogil
cdef
extern
from
"interface.c"
:
int
listen_and_serve
()
nogil
def
run
():
with
nogil
:
listen_and_serve
()
bint
lwan_strbuf_set_static
(
lwan_strbuf
*
s1
,
const
char
*
s2
,
size_t
sz
)
bint
lwan_strbuf_printf
(
lwan_strbuf
*
s
,
const
char
*
fmt
,
...)
cdef
public
int
handle_root
(
lwan_request
*
request
,
lwan_response
*
response
)
nogil
:
cdef
lwan_http_status
handle_root
(
lwan_request
*
request
,
lwan_response
*
response
,
void
*
data
)
nogil
:
cdef
char
*
message
=
"Hello, World!"
response
.
mime_type
=
"text/plain"
...
...
@@ -41,9 +47,30 @@ cdef unsigned int fibonacci(unsigned int n) nogil:
return
a
cdef
public
int
handle_fibonacci
(
lwan_request
*
request
,
lwan_response
*
response
)
nogil
:
cdef
lwan_http_status
handle_fibonacci
(
lwan_request
*
request
,
lwan_response
*
response
,
void
*
data
)
nogil
:
response
.
mime_type
=
"text/plain"
lwan_strbuf_printf
(
response
.
buffer
,
"Fibonacci(10^6) = %u (with overflow)
\
n
"
,
fibonacci
(
1000000
))
return
HTTP_OK
def
run
():
cdef
:
lwan
l
lwan_url_map
*
default_map
=
<
lwan_url_map
*>
calloc
(
3
,
sizeof
(
lwan_url_map
))
default_map
[
0
].
prefix
=
"/"
default_map
[
0
].
handler
=
handle_root
default_map
[
1
].
prefix
=
"/fibonacci"
default_map
[
1
].
handler
=
handle_fibonacci
default_map
[
2
].
prefix
=
NULL
with
nogil
:
lwan_init
(
&
l
)
lwan_set_url_map
(
&
l
,
default_map
)
lwan_main_loop
(
&
l
)
lwan_shutdown
(
&
l
)
free
(
default_map
)
setup.py
View file @
f470aa1f
...
...
@@ -5,7 +5,7 @@ from Cython.Build import cythonize
setup
(
ext_modules
=
cythonize
([
Extension
(
"lwan"
,
sources
=
[
"lwan_wrapper.pyx"
,
"interface.c"
],
sources
=
[
"lwan_wrapper.pyx"
],
libraries
=
[
"lwan"
],
)
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment