Giter VIP home page Giter VIP logo

node.native's People

Contributors

bluehaunter avatar d5 avatar dennycd avatar divanvisagie avatar jtomschroeder avatar kennethho avatar takano32 avatar tojocky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node.native's Issues

Segmentation fault in http_parser_execute

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).

Build System

Was thinking this could be a more platform friendly project if we made use of gyp

CMakeLists in node.native + seperate project?

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?

SEGV on multiple semi-parallel clients.

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*)>
...

SIGSEGV on MinGW

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

Keep-Alive support

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.

Guide for newbie?

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.

roadmap and next milestones

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 ? ;)

returning reference to local temporary object

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

Include in multiple files of a large application

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 ofnative::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.

R.I.P

... one of the best http libraries for c++

node.native CMakeLists.txt replacement for its Makefile?

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

Dead repo?

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.

Is this project dead?

Last commit was 4 months ago and Readme mentions that it is under heavy development?

compiler error under mac os x

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

Segmentation fault when concurrent requests arrives.

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 ).

how to produce the error :

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

full Stack trace from gdb :

(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,

compiling on osx lion

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

URL routing?

How do I work with URL routing in node.native?

E.g.: I want to expose /foo/ and /bar/ to echo different things.

Compiling error on Lion

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 can't compile node.native

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 tonative::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 tonative::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 tonative::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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.