Fixed multi threading + https in HTTPServerSimple.

This commit is contained in:
Relintai 2023-02-19 16:04:08 +01:00
parent e5f31bde7d
commit ddcf36addd
2 changed files with 26 additions and 3 deletions

View File

@ -57,7 +57,22 @@ void HTTPServerConnection::update() {
ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create());
peer = ssl;
ssl->set_blocking_handshake_enabled(false);
if (ssl->accept_stream(tcp, key, _http_server->cert) != OK) {
Ref<CryptoKey> key = Ref<CryptoKey>(CryptoKey::create());
Error err = key->load(_http_server->_ssl_key_file);
if (err != OK) {
close();
ERR_FAIL_COND(err != OK);
}
Ref<X509Certificate> cert = Ref<X509Certificate>(X509Certificate::create());
err = cert->load(_http_server->_ssl_cert_file);
if (err != OK) {
close();
ERR_FAIL_COND(err != OK);
}
if (ssl->accept_stream(tcp, key, cert) != OK) {
close();
return;
}
@ -342,6 +357,8 @@ void HTTPServerSimple::stop() {
Error HTTPServerSimple::listen(int p_port, IP_Address p_address, bool p_use_ssl, String p_ssl_key, String p_ssl_cert) {
use_ssl = p_use_ssl;
_ssl_key_file = p_ssl_key;
_ssl_cert_file = p_ssl_cert;
if (use_ssl) {
Ref<Crypto> crypto = Crypto::create();
@ -532,6 +549,9 @@ void HTTPServerSimple::_set_internal_certs(Ref<Crypto> p_crypto) {
cert = p_crypto->generate_self_signed_certificate(key, "CN=pandemonium-debug.local,O=A Game Dev,C=XXA", "20140101000000", "20340101000000");
cert->save(crt_path);
}
_ssl_key_file = key_path;
_ssl_cert_file = crt_path;
}
void HTTPServerSimple::_wake_workers() {

View File

@ -29,15 +29,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/containers/list.h"
#include "core/containers/vector.h"
#include "core/io/image_loader.h"
#include "core/io/json.h"
#include "core/io/stream_peer_ssl.h"
#include "core/io/tcp_server.h"
#include "core/io/zip_io.h"
#include "core/containers/list.h"
#include "core/os/rw_lock.h"
#include "core/os/semaphore.h"
#include "core/containers/vector.h"
#include "core/config/project_settings.h"
@ -105,6 +105,9 @@ public:
bool _use_worker_threads;
int _thread_count;
String _ssl_key_file;
String _ssl_cert_file;
private:
Ref<TCP_Server> server;