http: init_module() to init openssl once

pull/1487/head^2
Alexander Medvednikov 2019-08-06 14:02:51 +02:00
parent eece058f18
commit 8b75f2125a
2 changed files with 12 additions and 6 deletions

View File

@ -388,8 +388,19 @@ void init_consts();')
cgen.lines.set(defs_pos, dd)// TODO `def.str()` doesn't compile cgen.lines.set(defs_pos, dd)// TODO `def.str()` doesn't compile
// if v.build_mode in [.default, .embed_vlib] { // if v.build_mode in [.default, .embed_vlib] {
if v.pref.build_mode == .default_mode || v.pref.build_mode == .embed_vlib { if v.pref.build_mode == .default_mode || v.pref.build_mode == .embed_vlib {
mut consts_init_body := cgen.consts_init.join_lines()
for imp in v.table.imports {
if imp == 'http' {
consts_init_body += '\n http__init_module();'
}
}
// vlib can't have `init_consts()` // vlib can't have `init_consts()`
cgen.genln('void init_consts() { \n#ifdef _WIN32\n _setmode(_fileno(stdout), _O_U8TEXT); \nSetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_PROCESSED_OUTPUT | 0x0004); // ENABLE_VIRTUAL_TERMINAL_PROCESSING\n#endif\n g_str_buf=malloc(1000); ${cgen.consts_init.join_lines()} }') cgen.genln('void init_consts() {
#ifdef _WIN32\n _setmode(_fileno(stdout), _O_U8TEXT);
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_PROCESSED_OUTPUT | 0x0004);
// ENABLE_VIRTUAL_TERMINAL_PROCESSING\n#endif\n g_str_buf=malloc(1000);
$consts_init_body
}')
// _STR function can't be defined in vlib // _STR function can't be defined in vlib
cgen.genln(' cgen.genln('
string _STR(const char *fmt, ...) { string _STR(const char *fmt, ...) {

View File

@ -16,17 +16,12 @@ struct C.SSL {
} }
fn init_module() { fn init_module() {
init_openssl()
}
fn init_openssl() {
C.SSL_library_init() C.SSL_library_init()
//C.SSL_load_error_strings() //C.SSL_load_error_strings()
//C.OPENSSL_config(0) //C.OPENSSL_config(0)
} }
fn ssl_do(method, host_name, path string) string { fn ssl_do(method, host_name, path string) string {
init_openssl()
ssl_method := C.SSLv23_method() ssl_method := C.SSLv23_method()
if isnil(method) { if isnil(method) {
} }