Skip to content

Commit 21a41dd

Browse files
committed
📌 Nodepp | Bug Fixing | V1.3.1 📌
1 parent 2f39a65 commit 21a41dd

Some content is hidden

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

67 files changed

+1712
-920
lines changed

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ target_link_libraries( #[...]
4444

4545
- 📌: Include a **build-in JSON** parser / stringify system.
4646
- 📌: Include a **build-in RegExp** engine for processing text strings.
47-
- 📌: Include Support for **UTF** manipulation | **UTF8 - UTF16 - UTF32**
47+
- 📌: Include support for **UTF** manipulation | **UTF8 - UTF16 - UTF32**
4848
- 📌: Include a **build-in System** that make every object **Async Task** safety.
4949
- 📌: Include a **Smart Pointer** base **Garbage Collector** to avoid **Memory Leaks**.
5050
- 📌: Include support for **Reactive Programming** based on **Events** and **Observers**.
5151
- 📌: Include an **Event Loop** that can handle multiple events and tasks on a single thread.
5252
- 📌: Include support for **TCP | TLS | UDP | HTTP | WS** making it easy to create networked applications.
53-
- 📌: Include Support for **Poll | Epoll | Kqueue | WSAPoll** making it easy to handle multiple file descriptors.
53+
- 📌: Include support for **Poll | Epoll | Kqueue | WSAPoll** making it easy to handle multiple file descriptors.
54+
- 📌: Include support for **Worker isolated event-loop** making it easy to create distributed self-contained event-loops.
5455

5556
## Build & Run
5657
```bash
@@ -160,6 +161,47 @@ void onMain(){
160161
}
161162
```
162163

164+
### Worker Isolated Event-Loop
165+
```cpp
166+
#include <nodepp/nodepp.h>
167+
#include <nodepp/worker.h>
168+
#include <nodepp/os.h>
169+
170+
using namespace nodepp;
171+
172+
atomic_t<int> shared_variable = 100;
173+
174+
void local_main( int cpu_id ){
175+
176+
// this event-loop runs in it's own isolated worker-thread
177+
178+
process::add( coroutine::add( COROUTINE(){
179+
thread_local static int variable; // aka thread_safe variable;
180+
// this will create a static variable per thread
181+
static atomic_t<int> shared_variable;
182+
// this will create a shared global variable
183+
int local_variable;
184+
// this is a normal variable only exists in here
185+
coBegin
186+
187+
while( shared_variable-->0 ){
188+
console::log( cpu_id, "->", shared_variable.get() );
189+
coDelay(1000); }
190+
191+
coFinish
192+
}));
193+
194+
}
195+
196+
void onMain(){
197+
198+
for( auto x=os::cpus(); x-->0; ){ worker::add([=](){
199+
local_main( x ); process::wait();
200+
return -1; }); }
201+
202+
}
203+
```
204+
163205
### More Examples [here](https://nodeppofficial.github.io/nodepp-doc/guide.html)
164206
165207
## Installing Nodepp

examples/35-WS-Client.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,19 @@ using namespace nodepp;
88
void onMain() {
99

1010
auto client = ws::client( "ws://localhost:8000/" );
11-
auto cin = fs::std_input();
1211

1312
client.onConnect([=]( ws_t cli ){
1413

1514
console::log("connected", cli.get_peername() );
1615

17-
cli.onData([]( string_t chunk ){
18-
console::log("client:>",chunk);
16+
cli.onData([]( string_t data ){
17+
console::log( data );
1918
});
2019

21-
cin.onData([=]( string_t data ){
22-
cli.write( data );
23-
});
24-
2520
cli.onDrain([=](){
2621
console::log("closed");
27-
cin.close();
2822
});
2923

30-
stream::pipe( cin );
31-
3224
});
3325

3426
client.onError([=]( except_t err ){

examples/37-WSS-Client.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,19 @@ void onMain() {
1010
ssl_t ssl; //ssl_t ssl( "./ssl/cert.key", "./ssl/cert.crt" );
1111

1212
auto client = wss::client( "wss://localhost:8000/", &ssl );
13-
auto cin = fs::std_input();
1413

1514
client.onConnect([=]( wss_t cli ){
1615

1716
console::log("connected");
1817

19-
cli.onData([]( string_t chunk ){
20-
console::log("client:>",chunk);
18+
cli.onData([]( string_t data ){
19+
console::log( data );
2120
});
2221

23-
cin.onData([=]( string_t data ){
24-
cli.write( data );
25-
});
26-
2722
cli.onDrain([=](){
2823
console::log("closed");
29-
cin.close();
3024
});
3125

32-
stream::pipe( cin );
33-
3426
});
3527

3628
client.onError([=]( except_t err ){

examples/38-WS.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,17 @@ void server(){
2121

2222
server.onConnect([=]( ws_t cli ){
2323

24-
auto cin = fs::std_input();
2524
console::log("connected");
2625

27-
cin.onData([=]( string_t data ){
28-
cli.write( data );
29-
});
30-
3126
cli.onData([=]( string_t data ){
32-
console::log( "serv:", data );
27+
cli.write( "<: received" );
28+
console::log( data );
3329
});
3430

3531
cli.onDrain([=](){
3632
console::log("closed");
37-
cin.close();
3833
});
3934

40-
stream::pipe( cin );
41-
4235
});
4336

4437
server.listen( "localhost", 8000, [=]( socket_t server ){
@@ -56,8 +49,8 @@ void client() {
5649
auto cin = fs::std_input();
5750
console::log("connected");
5851

59-
cli.onData([]( string_t chunk ){
60-
console::log("cli:", chunk);
52+
cli.onData([]( string_t data ){
53+
console::log( data );
6154
});
6255

6356
cin.onData([=]( string_t data ){

examples/38-WSS.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,17 @@ void server(){
2323

2424
server.onConnect([=]( wss_t cli ){
2525

26-
auto cin = fs::std_input();
2726
console::log("connected");
2827

29-
cin.onData([=]( string_t data ){
30-
cli.write( data );
31-
});
32-
3328
cli.onData([=]( string_t data ){
34-
console::log( "serv:", data );
29+
cli.write( "<: received" );
30+
console::log( data );
3531
});
3632

3733
cli.onDrain([=](){
3834
console::log("closed");
39-
cin.close();
4035
});
4136

42-
stream::pipe( cin );
43-
4437
});
4538

4639
server.listen( "localhost", 8000, [=]( ssocket_t server ){
@@ -60,8 +53,8 @@ void client() {
6053
auto cin = fs::std_input();
6154
console::log("connected");
6255

63-
cli.onData([]( string_t chunk ){
64-
console::log("cli:", chunk);
56+
cli.onData([]( string_t data ){
57+
console::log( data );
6558
});
6659

6760
cin.onData([=]( string_t data ){

examples/45-TCPClient.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,16 @@ void onMain(){
1111
client.onOpen([=]( socket_t cli ){
1212

1313
console::log("connected", cli.get_peername() );
14-
auto cin = fs::std_input();
1514

1615
cli.onData([=]( string_t data ){
1716
console::log( data );
1817
});
1918

20-
cin.onData([=]( string_t data ){
21-
cli.write( data );
22-
});
23-
2419
cli.onClose.once([=](){
2520
console::log("closed");
26-
cin.close();
2721
});
2822

2923
stream::pipe( cli );
30-
stream::pipe( cin );
3124

3225
});
3326

examples/46-TCP.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@ void server(){
1111
server.onConnect([=]( socket_t cli ){
1212

1313
console::log("connected" );
14-
auto cin = fs::std_input();
1514

1615
cli.onData([=]( string_t data ){
16+
cli.write( "<: received" );
1717
console::log( data );
1818
});
1919

20-
cin.onData([=]( string_t data ){
21-
cli.write( data );
22-
});
23-
2420
cli.onDrain.once([=](){
2521
console::log("closed");
26-
cin.close();
2722
});
2823

2924
stream::pipe( cli );
30-
stream::pipe( cin );
3125

3226
});
3327

examples/46-TCPServer.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,16 @@ void onMain(){
1111
server.onConnect([=]( socket_t cli ){
1212

1313
console::log("connected", cli.get_peername() );
14-
auto cin = fs::std_input();
1514

1615
cli.onData([=]( string_t data ){
1716
console::log( data );
1817
});
1918

20-
cin.onData([=]( string_t data ){
21-
cli.write( data );
22-
});
23-
2419
cli.onDrain.once([=](){
2520
console::log("closed");
26-
cin.close();
2721
});
2822

2923
stream::pipe( cli );
30-
stream::pipe( cin );
3124

3225
});
3326

examples/47-UDPClient.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,16 @@ void onMain(){
1111
client.onConnect([=]( socket_t cli ){
1212

1313
console::log("connected", cli.get_peername() );
14-
auto cin = fs::std_input();
1514

1615
cli.onData([=]( string_t data ){
1716
console::log( data );
1817
});
1918

20-
cin.onData([=]( string_t data ){
21-
cli.write( data );
22-
});
23-
2419
cli.onDrain.once([=](){
2520
console::log("closed");
26-
cin.close();
2721
});
2822

2923
stream::pipe( cli );
30-
stream::pipe( cin );
3124

3225
});
3326

examples/48-UDP.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@ void server(){
1111
server.onConnect([=]( socket_t cli ){
1212

1313
console::log("connected" );
14-
auto cin = fs::std_input();
1514

1615
cli.onData([=]( string_t data ){
16+
cli.write( "<: received" );
1717
console::log( data );
1818
});
1919

20-
cin.onData([=]( string_t data ){
21-
cli.write( data );
22-
});
23-
2420
cli.onDrain.once([=](){
2521
console::log("closed");
26-
cin.close();
2722
});
2823

2924
stream::pipe( cli );
30-
stream::pipe( cin );
3125

3226
});
3327

0 commit comments

Comments
 (0)