-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Websocket support using mod_websocket.c
- Loading branch information
1 parent
de2dda1
commit c5e2136
Showing
8 changed files
with
425 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Mac", | ||
"includePath": [ | ||
"/usr/include", | ||
"/usr/local/include", | ||
"${workspaceRoot}" | ||
], | ||
"defines": [], | ||
"intelliSenseMode": "clang-x64", | ||
"browse": { | ||
"path": [ | ||
"/usr/include", | ||
"/usr/local/include", | ||
"${workspaceRoot}" | ||
], | ||
"limitSymbolsToIncludedHeaders": true, | ||
"databaseFilename": "" | ||
}, | ||
"macFrameworkPath": [ | ||
"/System/Library/Frameworks", | ||
"/Library/Frameworks" | ||
] | ||
}, | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"/usr/include/x86_64-linux-gnu/c++/5", | ||
"/usr/include/c++/5", | ||
"/usr/local/include", | ||
"/usr/lib/clang/3.8.0/include", | ||
"/usr/include/x86_64-linux-gnu", | ||
"/usr/include", | ||
"${workspaceRoot}", | ||
"${workspaceRoot}/../apache-websocket/", | ||
"/usr/include/apache2", | ||
"/usr/include/apr-1.0" | ||
], | ||
"defines": [], | ||
"intelliSenseMode": "clang-x64", | ||
"browse": { | ||
"path": [ | ||
"/usr/include/x86_64-linux-gnu/c++/5", | ||
"/usr/include/c++/5", | ||
"/usr/local/include", | ||
"/usr/lib/clang/3.8.0/include", | ||
"/usr/include/x86_64-linux-gnu", | ||
"/usr/include", | ||
"${workspaceRoot}" | ||
], | ||
"limitSymbolsToIncludedHeaders": true, | ||
"databaseFilename": "" | ||
} | ||
}, | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", | ||
"${workspaceRoot}" | ||
], | ||
"defines": [ | ||
"_DEBUG", | ||
"UNICODE" | ||
], | ||
"intelliSenseMode": "msvc-x64", | ||
"browse": { | ||
"path": [ | ||
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", | ||
"${workspaceRoot}" | ||
], | ||
"limitSymbolsToIncludedHeaders": true, | ||
"databaseFilename": "" | ||
} | ||
} | ||
], | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"thread": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,59 @@ | ||
#pragma once | ||
#include "handler.grpc.pb.h" | ||
extern "C" { | ||
#include "httpd.h" | ||
#include "http_log.h" | ||
#include "http_protocol.h" | ||
#include "apr_strings.h" | ||
} | ||
#include "config.h" | ||
extern int handle_request(request_rec* r, const grpcbackend_config_t* config); | ||
#include "websocket_plugin.h" | ||
#include <thread> | ||
#include <atomic> | ||
template<typename T> | ||
class pool_class { | ||
static apr_status_t cleanup(void* ptr) { | ||
if(ptr != nullptr) { | ||
T* instance = (T*)ptr; | ||
instance->~T(); | ||
} | ||
return APR_SUCCESS; | ||
} | ||
apr_pool_t* _pool; | ||
public: | ||
template<typename... Args> | ||
static T* create(apr_pool_t* pool, Args&&... args) { | ||
auto* mem = apr_palloc(pool, sizeof(T)); | ||
new(mem) T(std::forward<Args>(args)...); | ||
apr_pool_cleanup_register(pool, mem, cleanup, apr_pool_cleanup_null) ; | ||
return (T*)mem; | ||
} | ||
|
||
virtual ~pool_class() { | ||
} | ||
}; | ||
|
||
class http_handler: public pool_class<http_handler> { | ||
request_rec* r; | ||
const grpcbackend_config_t* config; | ||
public: | ||
http_handler(request_rec* r); | ||
const grpcbackend_config_t* get_config() const { return config; } | ||
int handle_request(); | ||
}; | ||
|
||
class websocket_handler: public pool_class<websocket_handler> { | ||
std::thread _recv_thread; | ||
std::atomic<bool> _recv_shutdown; | ||
const WebSocketServer* _server; | ||
std::unique_ptr<::thalhammer::http::Handler::Stub> _stub; | ||
::grpc::ClientContext _call_context; | ||
std::unique_ptr<::grpc::ClientReaderWriterInterface<::thalhammer::http::HandleWebSocketRequest, ::thalhammer::http::HandleWebSocketResponse>> _stream; | ||
protected: | ||
void send(int type, const uint8_t* buffer, size_t buffer_size); | ||
public: | ||
websocket_handler(const WebSocketServer* server); | ||
virtual ~websocket_handler(); | ||
void on_message(int type, const uint8_t* buffer, size_t buffer_size); | ||
void on_disconnect(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.