Skip to content

Commit a2c4b1f

Browse files
committed
Nodepp V1.4.0_1
1 parent 5876f03 commit a2c4b1f

52 files changed

Lines changed: 1019 additions & 866 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/0-stl_interop.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/event.h>
3+
4+
#include <string>
5+
#include <queue>
6+
#include <vector>
7+
#include <functional>
8+
9+
using namespace nodepp;
10+
11+
void onMain(){
12+
13+
ptr_t<int> ptr ( 0UL, 10 ); // as value
14+
// ptr_t<int> ptr ( 1UL, 10 ); // as buffer
15+
16+
std::function<void(int)> clb ([=]( int value ){
17+
console::log( value, *ptr );
18+
});
19+
20+
event_t<int> ev; ev.once( clb );
21+
ev.emit( 100 );
22+
23+
std::string str = "hello world";
24+
console::log( ">>", str );
25+
26+
std::vector<int> arr ({ 10, 20, 30, 40, 50 });
27+
console::log( ">>", array_t<int>( arr ).join() );
28+
29+
std::queue<int> st ({ 10, 20, 30, 40 });
30+
queue_t<int> que ( st );
31+
que.map([=]( int value ){ console::log( "<>", value ); });
32+
33+
}

examples/15-TCP.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/tcp.h>
34
#include <nodepp/fs.h>
45

@@ -74,9 +75,12 @@ void client(){
7475

7576
void onMain() {
7677

77-
if( process::env::get("mode")=="client" )
78-
{ client(); } else { server(); }
78+
worker::add( coroutine::add( COROUTINE(){
79+
coBegin /*--*/ ; server();
80+
process::wait(); coFinish }));
7981

80-
}
82+
worker::add( coroutine::add( COROUTINE(){
83+
coBegin /*--*/ ; client();
84+
process::wait(); coFinish }));
8185

82-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
86+
}

examples/15-TLS.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/tls.h>
34
#include <nodepp/fs.h>
45

@@ -76,9 +77,12 @@ void client(){
7677

7778
void onMain() {
7879

79-
if( process::env::get("mode")=="client" )
80-
{ client(); } else { server(); }
80+
worker::add( coroutine::add( COROUTINE(){
81+
coBegin /*--*/ ; server();
82+
process::wait(); coFinish }));
8183

82-
}
84+
worker::add( coroutine::add( COROUTINE(){
85+
coBegin /*--*/ ; client();
86+
process::wait(); coFinish }));
8387

84-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
88+
}

examples/15-UDP.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/udp.h>
34
#include <nodepp/fs.h>
45

@@ -77,9 +78,12 @@ void client(){
7778

7879
void onMain() {
7980

80-
if( process::env::get("mode")=="client" )
81-
{ client(); } else { server(); }
81+
worker::add( coroutine::add( COROUTINE(){
82+
coBegin /*--*/ ; server();
83+
process::wait(); coFinish }));
8284

83-
}
85+
worker::add( coroutine::add( COROUTINE(){
86+
coBegin /*--*/ ; client();
87+
process::wait(); coFinish }));
8488

85-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
89+
}

examples/15-WS.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/timer.h>
34
#include <nodepp/http.h>
45
#include <nodepp/path.h>
@@ -78,9 +79,12 @@ void client() {
7879

7980
void onMain() {
8081

81-
if( process::env::get("mode")=="client" )
82-
{ client(); } else { server(); }
82+
worker::add( coroutine::add( COROUTINE(){
83+
coBegin /*--*/ ; server();
84+
process::wait(); coFinish }));
8385

84-
}
86+
worker::add( coroutine::add( COROUTINE(){
87+
coBegin /*--*/ ; client();
88+
process::wait(); coFinish }));
8589

86-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
90+
}

examples/15-WSS.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/timer.h>
34
#include <nodepp/https.h>
45
#include <nodepp/path.h>
@@ -82,9 +83,12 @@ void client() {
8283

8384
void onMain() {
8485

85-
if( process::env::get("mode")=="client" )
86-
{ client(); } else { server(); }
86+
worker::add( coroutine::add( COROUTINE(){
87+
coBegin /*--*/ ; server();
88+
process::wait(); coFinish }));
8789

88-
}
90+
worker::add( coroutine::add( COROUTINE(){
91+
coBegin /*--*/ ; client();
92+
process::wait(); coFinish }));
8993

90-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
94+
}

examples/5-URL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ using namespace nodepp;
99

1010
void onMain(){
1111

12-
string_t uri = "http://becerra:enmanuel@www.google.com/path/to/file#done?var1=10&var2=50&var3=100&var4=hello_world!";
12+
string_t uri = "http://becerra:enmanuel@[www.google.com]:8000/path/to/file#done?var1=10&var2=50&var3=100&var4=hello_world!";
1313
auto ppt = url::parse( uri );
1414

1515
console::log( "hostname:", ppt.hostname );
1616
console::log( "protocol:", ppt.protocol );
1717
console::log( "pathname:", ppt.pathname );
18+
console::log( "rawname:" , ppt.rawname );
19+
console::log( "family:", ppt.family );
1820
console::log( "search:", ppt.search );
1921
console::log( "origin:", ppt.origin );
2022
console::log( "port:", ppt.port );

examples/7-worker-channel.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/7-worker-isolated-http-server.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
using namespace nodepp;
88

99
mutex_t mutx;
10-
invoke_t invk;
1110

12-
void isolated_event_loop( uint cpu_id, string_t addr ){ worker::add([=](){
11+
void isolated_event_loop( uint cpu_id ){ worker::add([=](){
1312
// this worker runs it's own event loop in parallel
1413

1514
auto server = http::server([=]( http_t cli ){
@@ -23,8 +22,6 @@ void isolated_event_loop( uint cpu_id, string_t addr ){ worker::add([=](){
2322
<h3> load balanced nodepp server </h3>
2423
));
2524

26-
invk.emit( addr, cpu_id );
27-
2825
});
2926

3027
server.listen( "localhost", 8000, [=]( socket_t ){
@@ -37,12 +34,8 @@ return -1; }); }
3734

3835
void onMain(){
3936

40-
auto addr = invk.add([=]( any_t value ){ mutx.lock([&](){
41-
console::log( "->", value.as<int>() );
42-
}); return 1; });
43-
4437
for( auto x=os::cpus(); x-->0; ){
45-
isolated_event_loop( x, addr );
38+
isolated_event_loop( x );
4639
}
4740

4841
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include <nodepp/nodepp.h>
22
#include <nodepp/timer.h>
3-
#include <nodepp/wait.h>
3+
#include <nodepp/listener.h>
44

55
using namespace nodepp;
66

77
void onMain(){
88

9-
wait_t<string_t> ev;
9+
listener_t<string_t> ev;
1010

1111
ev.on("1",[](){ console::log(" World 1 "); });
1212
ev.on("2",[](){ console::log(" World 2 "); });

0 commit comments

Comments
 (0)