More new ideas

This commit is contained in:
Alex Hultman
2018-06-18 21:36:27 +02:00
parent 460b9d6afc
commit ce15f4f87f
3 changed files with 56 additions and 26 deletions
+4 -21
View File
@@ -1,23 +1,11 @@
// uWS.h
#include "Hub.h"
#include <iostream>
#include <string.h>
int main() {
std::cout << "HttpSocket size: " << sizeof(HttpSocket) << std::endl;
// defaultHub is per thread ready for action
// uWS::defaultHub().onHttpRequest().listen().isListening().run();
Hub h;
h.onHttpConnection([](HttpSocket *s) {
std::cout << "HTTP connection" << std::endl;
});
// req = ?, res = HttpSocket
// should be s, req, nothing more or less!
h.onHttpRequest([](HttpSocket *s, auto req, char *data, unsigned int length) {
// either use this, or use onHttpRoute but not both
uWS::defaultHub.onHttpRequest([](HttpSocket *s, HttpRequest *req) {
// an http socket can BOTH send buffered data AND have one stream in and one stream out!
@@ -41,12 +29,7 @@ int main() {
/*s->stream(largeHttpBufSize, [](int offset) {
return std::make_pair(largeHttpBuf + offset, largeHttpBufSize - offset);
});*/
});
}).listen("localhost", 3000, 0).run();
h.onHttpDisconnection([](HttpSocket *s) {
std::cout << "HTTP disconnection" << std::endl;
});
h.listen(nullptr, 3000, 0);
h.run();
// todo: important swapping to SSL should be .secureListen(same interfaces) and work out of the box!
}