Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Last active September 13, 2015 07:50
Show Gist options
  • Save kjunichi/7345ce715e4c19628065 to your computer and use it in GitHub Desktop.
Save kjunichi/7345ce715e4c19628065 to your computer and use it in GitHub Desktop.

当日作業

libh2oでmrubyハンドラを動かすには

register_handler

mrubyのハンドラー

h2o_mruby_register_configurator

h2o_globalconf_t

h2o_config_register_path

pt '_register('|grep mruby
h2o_mruby_register(h2o_pathconf_t *pathconf, h2o_mruby_config_vars_t *config)

h2o_mruby_config_vars_t

h2o_configurator_command_t

h2o_mruby_compile_code

examples/h2o_mruby/hello.rb

self.vars->source self.vars->source.base

on_config_mruby_handler_file

gcc -I libressl-build/include  -I ../deps/mruby/include/  -I ../include/ -luv ./libh2o.a -L libressl-build/lib -lcrypto -lssl simple.c
gcc -I libressl-build/include  -I ../deps/mruby/include/  -I ../include/ -luv ./libh2o.a -L libressl-build/lib -lcrypto -lssl mruby/host/lib/libmruby.a CMakeFiles/h2o.dir/lib/handler/mruby.c.o simple.c

libh2oを動かす

exmaple/libh2o/simple.cを元にする。

buildディレクトリでのsimple.cのビルドコマンド

gcc -I libressl-build/include  -I ../include/ -luv ./libh2o.a -L libressl-build/lib -lcrypto -lssl simple.c
#define USE_HTTPS 1
Undefined symbols for architecture x86_64:
  "_h2o_ssl_register_alpn_protocols", referenced from:
      _setup_ssl in simple-7f5e31.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 #if H2O_USE_ALPN
//
 void h2o_ssl_register_alpn_protocols(SSL_CTX *ctx, const h2o_iovec_t *protocols)
{
     SSL_CTX_set_alpn_select_cb(ctx, on_alpn_select, (void *)protocols);
}

#endif
simple.c:222:37: error: use of undeclared identifier 'on_alpn_select'
    SSL_CTX_set_alpn_select_cb(ctx, on_alpn_select, (void *)protocols);
                                    ^
1 error generated.
static int on_alpn_select(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *_in, unsigned int inlen,
                          void *_protocols)
{
    const h2o_iovec_t *protocols = _protocols;
    size_t i;

    for (i = 0; protocols[i].len != 0; ++i) {
        const unsigned char *in = _in, *in_end = in + inlen;
        while (in != in_end) {
            size_t cand_len = *in++;
            if (in_end - in < cand_len) {
                /* broken request */
                return SSL_TLSEXT_ERR_NOACK;
            }
            if (cand_len == protocols[i].len && memcmp(in, protocols[i].base, cand_len) == 0) {
                goto Found;
            }
            in += cand_len;
        }
    }
    /* not found */
    return SSL_TLSEXT_ERR_NOACK;

Found:
    *out = (const unsigned char *)protocols[i].base;
    *outlen = (unsigned char)protocols[i].len;
    return SSL_TLSEXT_ERR_OK;
}
./a.out 
an error occurred while trying to load server certificate file:examples/h2o/server.crt
cp -r ../examples .
    SSL_CTX_set_options(accept_ctx.ssl_ctx, SSL_OP_NO_SSLv2);
setup_ecc_key(accept_ctx.ssl_ctx); // 追加

候補

  • node-http2モジュールでElectronでサーバープッシュに対応
  • libh2oを使ってrust,goでhttp2サーバー
  • mruby-http2のメモリ増加問題

サーバーサイド

libh2oをmrubyを有効にして使う

  • libuvとcgoが相性悪いかも、その場合はevloop版へ
  • mrmagickを使えるようにする
  • レスポンスにtext/html以外のバイナリを指定し、バイナリを返す

フロントエンド

Electronでhttp2を使う

平文からDOMにする必要あり DOMをDOMとしてレンダリングさせない、HTML-GLでWebGLとしてレンダリングさせる。 styleタグはhtml-glタグに入れられないかも、リンクを辿って、styleタグに展開する必要があるかも

資料

場所

株式会社インターネットイニシアティブ 本社 中会議室 東京都千代田区富士見2-10-2 飯田橋グラン・ブルーム

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment