d5 / node.native Goto Github PK
View Code? Open in Web Editor NEWC++11 port for the Node: native performance and modern simplicity.
License: MIT License
C++11 port for the Node: native performance and modern simplicity.
License: MIT License
I used the master branch.
Compile went without problems with g++ 4.7.3:
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.3-4' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Debian 4.7.3-4)
I started the webserver with:
gdb webserver
And called multiple clients:
for run in {1..300} ; do
./webclient&
done
And it crashed. Looks like there is a uv_handle missing...
Program received signal SIGSEGV, Segmentation fault.
0x00000000004069d9 in native::base::stream::write(char const*, int, std::function<void (native::error)>) (this=0x642650, buf=0x642588 "HTTP/1.1 200 OK\r\nContent-Length: 8\r\nContent-Type: text/plain\r\n\r\nC++ FTW\n", len=72, callback=...) at ./native/stream.h:75
75 callbacks::store(get()->data, native::internal::uv_cid_write, callback);
(gdb) disassemble
Dump of assembler code for function native::base::stream::write(char const_, int, std::function<void (native::error)>):
...
0x00000000004069d4 <+50>: callq 0x409536 native::base::handle::get<uv_handle_s()>
=> 0x00000000004069d9 <+55>: mov 0x8(%rax),%rax
0x00000000004069dd <+59>: mov -0x50(%rbp),%rdx
0x00000000004069e1 <+63>: mov $0x0,%ecx
0x00000000004069e6 <+68>: mov $0x3,%esi
0x00000000004069eb <+73>: mov %rax,%rdi
0x00000000004069ee <+76>: callq 0x40969b <native::callbacks::store<std::function<void (native::error)> >(void_, int, std::function<void (native::error)> const&, void*)>
...
what's the meaning of this project?
Was thinking this could be a more platform friendly project if we made use of gyp
I managed to crash the process by using a couple of methods.
First method: sending an incomplete request. Proof of concept script:
#!/usr/bin/env python
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 1337))
s.send("GET / HTTP/1.0\r\n")
s.close()
This is what gdb says:
Starting program: /home/saltwater/node.native/webserver
[Thread debugging using libthread_db enabled]
Server running at http://0.0.0.0:1337/
Program received signal SIGSEGV, Segmentation fault.
0x0000000000434454 in http_parser_execute ()
(gdb) info registers
rax 0x16 22
rbx 0x6507a0 6621088
rcx 0xffffffffffffffff -1
rdx 0x0 0
rsi 0xfffffffffffffffe -2
rdi 0x2a 42
rbp 0x0 0x0
rsp 0x7fffffffe5e0 0x7fffffffe5e0
r8 0x0 0
r9 0x438d70 4427120
r10 0xffffffffffffffff -1
r11 0xffffffffffffffff -1
r12 0xffffffff 4294967295
r13 0x0 0
r14 0x0 0
r15 0x0 0
rip 0x434454 0x434454 <http_parser_execute+180>
eflags 0x10287 [ CF PF SF IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
The second method: hammering the server with lots of requests at high concurrency. Proof of concept:
ab -k -n 1000000 -c 1000 http://127.0.0.1:1337/
The gdb output looks again familiar:
Starting program: /home/saltwater/node.native/webserver
[Thread debugging using libthread_db enabled]
Server running at http://0.0.0.0:1337/
Program received signal SIGSEGV, Segmentation fault.
0x0000000000434454 in http_parser_execute ()
(gdb) info registers
rax 0xfffffffd 4294967293
rbx 0x7a1ae0 8002272
rcx 0xffffffffffffffff -1
rdx 0x0 0
rsi 0xfffffffffffffffe -2
rdi 0x11 17
rbp 0x0 0x0
rsp 0x7fffffffe5e0 0x7fffffffe5e0
r8 0x0 0
r9 0x438d70 4427120
r10 0xffffffffffffffff -1
r11 0xffffffffffffffff -1
r12 0xffffffff 4294967295
r13 0x0 0
r14 0x0 0
r15 0x0 0
rip 0x434454 0x434454 <http_parser_execute+180>
eflags 0x10293 [ CF AF SF IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
Things that looks suspicious: the r12 register that holds the 2^32-1 value, and in the second case, the rax register that goes close to that value, therefore it may look like some sort of overflow.
The system is an Ubuntu 11.10 amd64 (running as chroot under 10.04).
http://socket.io/ port server for node.native
wanna create a thread to discuss the next milestones of node.native. I think there's a lot of potentials in the project, but maybe we shall setup some goals to move the project further forward ? @d5 @divanvisagie any plans in mind ? ;)
there are places in the code that returns a reference to a parameter variable that has optional default values. This would potentially cause a crash if the caller does not supply the parameter.
http.h: line 263
const std::string& get_header(const std::string& key, const std::string& default_value=std::string()) const
Is there currently a way to serve static files via http::response?
How do I setup a separate project that works with node.native (from git, not from install library locations)?
Here is what I have tried:
git clone https://github.com/d5/node.native.git
mkdir routing_tests && cd $_
Then I created main.cpp and CMakeLists.txt:
project(routing_tests)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
include_directories(../node.native/ ../node.native/native)
include_directories(../node.native/libuv ../node.native/libuv/include ../node.native/http-parser)
But unfortunately I get these errors: Qt Creator screenshot
How do I fix this? - Also, are you planning on moving from vanilla Makefiles to CMake?
I have tried to update the libuv and found out that just now there was a major change in libuv.
I want to implement Keep-Alive support in node.native.
I can easily enough set a response to tell the client that the connection should be kept alive.
What I'm having a problem with is executing a callback when a second request comes from the client on the kept-alive connection.
In node.js and luvit, they have an on:data callback. I can't find this event in libuv, so I'm really asking you all if you know if node.js/luvit implement additional events beyond those which libuv provides.
I am on the v0.1.0 branch, I am on a 10.7 and have gcc 4.6.3
installed.
When I make i get the following error:
c++ -std=gnu++0x -Iext/libuv/include -Iext/http-parser -
D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -o echo echo.cpp native.a -
lm -lpthread
Undefined symbols for architecture x86_64:
"_AbsoluteToNanoseconds", referenced from:
_uv_hrtime in native.a(darwin.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [echo] Error 1
I have compiled libuv
exported paths as described
but seems Xcode 4.2.1 does not have gnu++0x support inbuilt
how can I install on OSX Lion
it seems not have way to get uploaded content.
with a single connection and many requests, there is no problem.
but I send multiply requests concurrently, segmentation fault occurs ( line 336 in http.h ).
ab -k -n 50000 -c 100 -t 20 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
apr_socket_recv: Connection reset by peer (104)
Total of 14 requests completed
(gdb) bt full
#0 0x00000000004089a7 in native::http::client_context::~client_context()::{lambda()#1}::operator()() const () at ./native/http.h:336
std::__ioinit = {static _S_refcount = <optimized out>,
static _S_synced_with_stdio = <optimized out>}
#1 0x000000000040c473 in std::_Function_handler<void (), native::http::client_context::~client_context()::{lambda()#1}>::_M_invoke(std::_Any_data const&) (
__functor=...) at /usr/include/c++/4.8/functional:2071
No locals.
#2 0x000000000040d112 in std::function<void ()>::operator()() const (
this=0x642750) at /usr/include/c++/4.8/functional:2464
No locals.
#3 0x000000000040b60a in native::internal::callback_object<std::function<void ()> >::invoke<>() (this=0x642740) at ./native/callback.h:46
No locals.
#4 0x00000000004098ef in native::callbacks::invoke<std::function<void ()>>(void*, int) (target=0x642550, cid=0) at ./native/callback.h:84
__PRETTY_FUNCTION__ = "static typename std::result_of<_Functor(_ArgTypes ...)>::type native::callbacks::invoke(void*, int, A&& ...) [with callback_t = std::function<void()>; A = {}; typename std::result_of<_Functor(_ArgType"...
x = 0x642740
#5 0x00000000004067db in native::base::handle::close(std::function<void ()>)::{lambda(uv_handle_s_)#1}::operator()(uv_handle_s_) const (__closure=0x0,
How do I work with URL routing in node.native?
E.g.: I want to expose /foo/ and /bar/ to echo different things.
Recently i tried to include the native.h in multiple files in my project. It seems tha guard headers didnt their job, resulting compiling errors like below:
hlrfrwdr/httpserver.o: In function native::base::_delete_handle(uv_handle_s*)': /opt/node.native/./native/handle.h:71: multiple definition of
native::base::_delete_handle(uv_handle_s*)'
/tmp/cctxhz6O.o:/opt/node.native/./native/handle.h:71: first defined here
I managed to solve these errors by myself by defining such plain functions as inline functions in order to be able to include the native, many times in the same project (since the guard headers -ifndef etc arent enough).
My question is: this is the correct way for solving this? And if true, it would be perfect if you define these as inline these functions also in node.native project here in github.
I see a lot of backed up pull requests , whats happening ? this is a great concept, if its too much for you to manage please pass it on to someone that can.
Hello everyone!!
I was trying to compile the project but it shows an error that i don't know how to solve. This is the error:
dani@dani-portatil:~/Documentos/node.native$ make
g++ -std=gnu++0x -g -O0 -Ilibuv/include -Ihttp-parser -I. -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -o webclient webclient.cpp libuv/libuv.a http-parser/http_parser.o -lrt -lm -lpthread
/tmp/ccouJW7h.o: In function native::base::handle::close(std::function<void ()>)::{lambda(uv_handle_s*)#1}::operator void (*)(uv_handle_s*)() const': /home/dani/Documentos/node.native/./native/handle.h:57: undefined reference to
native::base::handle::close(std::function<void ()>)::{lambda(uv_handle_s_)#1}::FUN(uv_handle_s)'
/tmp/ccouJW7h.o: In function native::base::stream::write(std::string const&, std::function<void (native::error)>)::{lambda(uv_write_s*, int)#1}::operator void (*)(uv_write_s*, int)() const': /home/dani/Documentos/node.native/./native/stream.h:89: undefined reference to
native::base::stream::write(std::string const&, std::function<void (native::error)>)::{lambda(uv_write_s_, int)#1}::FUN(uv_write_s, int)'
/tmp/ccouJW7h.o: In function native::net::tcp::connect(std::string const&, int, std::function<void (native::error)>)::{lambda(uv_connect_s*, int)#1}::operator void (*)(uv_connect_s*, int)() const': /home/dani/Documentos/node.native/./native/tcp.h:58: undefined reference to
native::net::tcp::connect(std::string const&, int, std::function<void (native::error)>)::{lambda(uv_connect_s_, int)#1}::FUN(uv_connect_s, int)'
collect2: error: ld returned 1 exit status
make: *** [webclient] Error 1
what is happening?
Thanks in advance.
Daniel.
There seems to be a compiler error I encountered under mac os x mountain lion.
./native/stream.h:79:60: error: non-constant-expression cannot be narrowed from type 'int' to 'size_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]
uv_buf_t bufs[] = { uv_buf_t { const_cast<char*>(buf), len } };
I believe this is something specific to the clang compiler. It seems adding static_const(len) would force an explicit type conversion and get rid of the error.
I am using the master branch code
Last commit was 4 months ago and Readme mentions that it is under heavy development?
Hello,
I have no idea how to use node.native for web development.
Is there any documentation or guide for templating, URL routing, forms, localization, etc?
Thank you very much.
for some reason stat, fstat are commented out.
The closest I've gotten is the header output (https://github.com/SamuelMarks/node.native/blob/master/routes.h#L54):
$ http localhost:8080/headers
HTTP/1.1 200 OK
Content-Length: 141
Content-Type: application/json
{
"headers": [
{
"Accept": "*/*"
},
{
"Accept-Encoding": "gzip, deflate, compress"
},
{
"Host": "localhost:8080"
},
{
"User-Agent": "HTTPie/0.8.0"
}
]
}
How do I get the HTTP verb?
I tried to use the webcient and webserver and the client correctly got the message:
HTTP/1.1 200 OK
Content-Length: 8
Content-Type: text/plain
C++ FTW
But the server immediately SIGSEGVs on native::http::client_context::~client_context()
here is the full stack trace:
(gdb) bt
#0 0x004306be in native::http::client_context::~client_context()::{lambda()#1}::operator()() const () at ./native/http.h:335
#1 0x0042d79d in std::_Function_handler<void (), native::http::client_context::~client_context()::{lambda()#1}>::_M_invoke(std::_Any_data const&) (__functor=...)
at c:/mingw/bin/../lib/gcc/mingw32/4.6.2/include/c++/functional:1778
#2 0x0042b9fc in std::function<void ()>::operator()() const (this=0x7b2d68) at c:/mingw/bin/../lib/gcc/mingw32/4.6.2/include/c++/functional:2161
#3 0x0042a7a8 in native::internal::callback_object<std::function<void ()> >::invoke<>() (this=0x7b2d60) at ./native/callback.h:46
#4 0x0042b243 in native::callbacks::invoke<std::function<void ()>>(void*, int) (target=0x7b59a8, cid=0) at ./native/callback.h:84
#5 0x0042ff4c in native::base::handle::close(std::function<void ()>)::{lambda(uv_handle_s_)#1}::operator()(uv_handle_s_) const (this=0x0, h=0x7b5918) at ./native/handle.h:55
#6 0x0042ff81 in native::base::handle::close(std::function<void ()>)::{lambda(uv_handle_s_)#1}::FUN(uv_handle_s) (h=0x7b5918) at ./native/handle.h:57
#7 0x00404d5c in uv_tcp_endgame (loop=0x446040, handle=0x7b5918) at src/win/tcp.c:213
#8 0x0040412b in uv_process_endgames (loop=0x446040) at src/win/handle.c:184
#9 0x00403114 in uv_run (loop=0x446040) at src/win/core.c:262
#10 0x0040145b in native::run () at ./native/loop.h:94
#11 0x0040287b in _fu0___ZSt4cout () at webserver.cpp:14
... one of the best http libraries for c++
libuv is a great abstraction layer replacement for libevent; with a major feature being interoperability. Is there a reason we are using vanilla Makefiles?
I.e.: can we migrate from our vanilla Makefile to CMakeLists?
Thanks for your consideration
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.