Skip to content

Commit fe9c8e4

Browse files
committed
📌 Nodepp | Stable Release | V1.2.0 📌
1 parent 919dfb7 commit fe9c8e4

Some content is hidden

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

78 files changed

+2094
-1619
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ One of the standout features of Nodepp is its 100% asynchronous architecture, po
3636

3737
## Build & Run
3838
```bash
39-
🐧: g++ -o main main.cpp -I ./include ; ./main
40-
🪟: g++ -o main main.cpp -I ./include -lws2_32 ; ./main
39+
🐧: g++ -o main main.cpp -O3 -I ./include ; ./main
40+
🪟: g++ -o main main.cpp -O3 -I ./include -lws2_32 ; ./main
4141
```
4242

4343
## Test Unit
4444
```bash
45-
( cd ./test; g++ -o main main.cpp -I../include -lssl -lcrypto ; ./main )
45+
🐧: ( cd ./test; g++ -o main main.cpp -I../include -lssl -lcrypto -lpthread ; ./main )
46+
🪟: ( cd ./test; g++ -o main main.cpp -I../include -lssl -lcrypto -lws2_32 ; ./main )
4647
```
4748

4849
## Examples
@@ -61,6 +62,8 @@ void onMain() {
6162

6263
### HTTP Client
6364
```cpp
65+
//#pragma comment(lib, "Ws2_32.lib") msvc compiler
66+
6467
#include <nodepp/nodepp.h>
6568
#include <nodepp/http.h>
6669

@@ -90,6 +93,8 @@ void onMain(){
9093

9194
### HTTP Server
9295
```cpp
96+
//#pragma comment(lib, "Ws2_32.lib") msvc compiler
97+
9398
#include <nodepp/nodepp.h>
9499
#include <nodepp/http.h>
95100
#include <nodepp/date.h>
@@ -134,7 +139,6 @@ Check out some articles on [Medium](https://medium.com/@EDBCBlog)
134139
## Compatibility
135140
- 🔗: [NodePP for Window | Linux | Mac | Bsd ](https://github.com/NodeppOfficial/nodepp)
136141
- 🔗: [NodePP for Arduino](https://github.com/NodeppOfficial/nodepp-arduino)
137-
- 🔗: [Nodepp for ESP32](https://github.com/NodeppOfficial/nodepp-ESPXX)
138142
- 🔗: [Nodepp for WASM](https://github.com/NodeppOfficial/nodepp-wasm)
139143

140144
## Official Libraries for Nodepp

examples/35-WS-Client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ void onMain() {
1111
auto cin = fs::std_input();
1212

1313
client.onConnect([=]( ws_t cli ){
14-
15-
console::log("connected");
14+
15+
console::log("connected", cli.get_peername() );
1616

1717
cli.onData([]( string_t chunk ){
1818
console::log("client:>",chunk);

examples/36-WS-Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void onMain(){
2222

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

25-
console::log("connected");
25+
console::log("connected", cli.get_peername() );
2626

2727
cli.onData([=]( string_t data ){
2828
console::log( data );

examples/45-TCPClient.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,31 @@ using namespace nodepp;
66
void onMain(){
77

88
auto client = tcp::client();
9+
auto cin = fs::std_input();
910

1011
client.onOpen([=]( socket_t cli ){
12+
13+
console::log("connected", cli.get_peername() );
1114

1215
cli.onData([=]( string_t data ){
1316
console::log( data );
1417
});
1518

19+
cin.onData([=]( string_t data ){
20+
cli.write( data );
21+
});
22+
1623
cli.onClose.once([=](){
1724
console::log("closed");
1825
});
1926

20-
cli.write("Hello World!");
2127
stream::pipe( cli );
28+
stream::pipe( cin );
2229

2330
});
2431

2532
client.connect( "localhost", 8000, []( socket_t cli ){
26-
console::log("client connected to tcp://localhost:8000");
33+
console::log("-> tcp://localhost:8000");
2734
});
2835

2936
}

examples/46-TCPServer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,31 @@ using namespace nodepp;
66
void onMain(){
77

88
auto server = tcp::server();
9+
auto cin = fs::std_input();
910

1011
server.onConnect([=]( socket_t cli ){
1112

13+
console::log("connected", cli.get_peername() );
14+
1215
cli.onData([=]( string_t data ){
1316
console::log( data );
1417
});
1518

19+
cin.onData([=]( string_t data ){
20+
cli.write( data );
21+
});
22+
1623
cli.onClose.once([=](){
1724
console::log("closed");
1825
});
19-
26+
2027
stream::pipe( cli );
28+
stream::pipe( cin );
2129

2230
});
2331

2432
server.listen( "localhost", 8000, []( socket_t srv ){
25-
console::log("server started at tcp://localhost:8000");
33+
console::log("-> tcp://localhost:8000");
2634
});
2735

2836
}

examples/47-UDPClient.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,31 @@ using namespace nodepp;
66
void onMain(){
77

88
auto client = udp::client();
9+
auto cin = fs::std_input();
910

10-
client.onOpen([=]( socket_t cli ){
11+
client.onConnect([=]( socket_t cli ){
12+
13+
console::log("connected", cli.get_peername() );
1114

1215
cli.onData([=]( string_t data ){
1316
console::log( data );
1417
});
1518

19+
cin.onData([=]( string_t data ){
20+
cli.write( data );
21+
});
22+
1623
cli.onClose.once([=](){
1724
console::log("closed");
1825
});
1926

20-
cli.write("Hello World!");
2127
stream::pipe( cli );
28+
stream::pipe( cin );
2229

2330
});
2431

2532
client.connect( "localhost", 8000, []( socket_t cli ){
26-
console::log("client connected to udp://localhost:8000");
33+
console::log("-> udp://localhost:8000");
2734
});
2835

2936
}

examples/48-UDPServer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,31 @@ using namespace nodepp;
66
void onMain(){
77

88
auto server = udp::server();
9+
auto cin = fs::std_input();
910

1011
server.onConnect([=]( socket_t cli ){
1112

13+
console::log("connected", cli.get_peername() );
14+
1215
cli.onData([=]( string_t data ){
1316
console::log( data );
1417
});
1518

19+
cin.onData([=]( string_t data ){
20+
cli.write( data );
21+
});
22+
1623
cli.onClose.once([=](){
1724
console::log("closed");
1825
});
1926

2027
stream::pipe( cli );
28+
stream::pipe( cin );
2129

2230
});
2331

2432
server.listen( "localhost", 8000, []( socket_t srv ){
25-
console::log("server started at udp://localhost:8000");
33+
console::log("-> udp://localhost:8000");
2634
});
2735

2836
}

examples/49-TLSClient.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,31 @@ ssl_t ssl; // ( "./ssl/cert.key", "./ssl/cert.crt" );
88
void onMain(){
99

1010
auto client = tls::client( ssl );
11+
auto cin = fs::std_input();
1112

12-
client.onOpen([=]( ssocket_t cli ){
13+
client.onConnect([=]( ssocket_t cli ){
14+
15+
console::log("connected", cli.get_peername() );
1316

1417
cli.onData([=]( string_t data ){
1518
console::log( data );
1619
});
1720

21+
cin.onData([=]( string_t data ){
22+
cli.write( data );
23+
});
24+
1825
cli.onClose.once([=](){
1926
console::log("closed");
2027
});
2128

22-
cli.write("hola mundo");
2329
stream::pipe( cli );
30+
stream::pipe( cin );
2431

2532
});
2633

2734
client.connect( "localhost", 8000, []( socket_t cli ){
28-
console::log("client started at tls://localhost:8000");
35+
console::log("-> tls://localhost:8000");
2936
});
3037

3138
}

examples/50-TLSServer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ ssl_t ssl; // ( "./ssl/cert.key", "./ssl/cert.crt" );
88
void onMain(){
99

1010
auto server = tls::server( ssl );
11+
auto cin = fs::std_input();
1112

1213
server.onConnect([=]( ssocket_t cli ){
1314

14-
console::log("connected to:", cli.get_fd());
15+
console::log("connected", cli.get_peername() );
1516

1617
cli.onData([=]( string_t data ){
1718
console::log( data );
1819
});
1920

21+
cin.onData([=]( string_t data ){
22+
cli.write( data );
23+
});
24+
2025
cli.onClose.once([=](){
2126
console::log("closed");
2227
});
2328

2429
stream::pipe( cli );
30+
stream::pipe( cin );
2531

2632
});
2733

2834
server.listen( "localhost", 8000, []( ssocket_t ){
29-
console::log("server started at tls://localhost:8000");
35+
console::log("-> tls://localhost:8000");
3036
});
3137

3238
}

include/nodepp/any.h

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,29 @@ public: any_t() noexcept {};
2626

2727
/*─······································································─*/
2828

29-
uint type_size() const noexcept { return any_sz.null()?0: *any_sz; }
30-
ulong count() const noexcept { return any_ptr.count(); }
31-
bool empty() const noexcept { return any_ptr.null (); }
32-
bool has_value() const noexcept { return !any_ptr.null (); }
29+
ulong type_size() const noexcept { return empty() ?0 : any_ptr->size(); }
30+
ulong count() const noexcept { return any_ptr.count(); } /*--------*/
31+
bool empty() const noexcept { return any_ptr.null (); } /*--------*/
32+
bool has_value() const noexcept { return !any_ptr.null (); } /*--------*/
33+
void free() const noexcept { /*--*/ any_ptr.free (); } /*--------*/
3334

3435
/*─······································································─*/
3536

36-
void free() const noexcept { any_ptr.free(); }
37-
38-
/*─······································································─*/
39-
40-
void operator=( const char* f ) noexcept { set( string::to_string(f) ); }
41-
42-
template< class T >
43-
void operator=( const T& f ) noexcept { set( f ); }
44-
4537
template< class T >
4638
T as() const { return get<T>(); }
4739

4840
template< class T >
49-
void set( const T& f ) noexcept {
50-
any_sz = new uint(sizeof(T));
51-
any_ptr = new any_impl<T>(f);
52-
}
41+
void set( const T& f ) noexcept { any_ptr = new any_impl<T>(f); }
5342

5443
template< class T >
55-
T get() const {
56-
char any [ sizeof(T)/sizeof(char) ]; if( !has_value() )
57-
{ throw except_t("any_t is null"); }
58-
if( *any_sz != sizeof(any)*sizeof(char) )
59-
{ throw except_t("any_t incompatible sizetype"); }
60-
any_ptr->get((void*)&any); return *(T*)(any);
44+
T get() const { const ulong size = sizeof(T) / sizeof( char );
45+
46+
if( !has_value() ) /*----*/ { throw except_t("any_t is null"); } /*---------*/
47+
if( type_size()!=sizeof(T) ){ throw except_t("any_t incompatible sizetype"); }
48+
49+
char any [ size ]; any_ptr->get((void*)&any);
50+
return *(T*)(any); /*----------------------*/
51+
6152
}
6253

6354
/*─······································································─*/
@@ -70,8 +61,9 @@ public: any_t() noexcept {};
7061
class any_base {
7162
public:
7263
virtual ~any_base() noexcept {}
73-
virtual void get( void* /*unused*/ ) const noexcept {}
74-
virtual void set( void* /*unused*/ ) noexcept {}
64+
virtual void get( void* /*unused*/ ) const noexcept {}
65+
virtual void set( void* /*unused*/ ) /*-*/ noexcept {}
66+
virtual ulong size() /*------------*/ const noexcept = 0;
7567
};
7668

7769
/*─······································································─*/
@@ -80,16 +72,16 @@ public: any_t() noexcept {};
8072
class any_impl : public any_base {
8173
public:
8274
any_impl( const T& f ) noexcept : any( f ) {}
83-
virtual void get( void* argc ) const noexcept { memcpy( argc, (void*)&any, sizeof(T) ); }
84-
virtual void set( void* argc ) noexcept { memcpy( (void*)&any, argc, sizeof(T) ); }
75+
virtual ulong size() /*------*/ const noexcept { return sizeof(T); } /*-----------------*/
76+
virtual void get( void* argc ) const noexcept { memcpy( argc, (void*)&any, sizeof(T) ); }
77+
virtual void set( void* argc ) /*-*/ noexcept { memcpy( (void*)&any, argc, sizeof(T) ); }
8578
private:
8679
T any;
8780
};
8881

8982
/*─······································································─*/
9083

9184
ptr_t<any_base> any_ptr;
92-
ptr_t<uint> any_sz;
9385

9486
};}
9587

0 commit comments

Comments
 (0)