LoginSignup
1
1

More than 5 years have passed since last update.

nginx-link-functionモジュールをC言語以外でも利用可能な説を検証!

Posted at

nginx-link-functionは、nginxの設定ファイルに共有ライブラリのパスと関数名を設定しておくと、
設定に応じて関数をコールしてくれる素敵なnginxのモジュールです。

C/C++でできるなら、Rustでもできんじゃね?と思ったので試してみました。

RustとC/C++

  1. crate-typeをdylibに設定すると、.soファイルを作成することが可能
  2. bindgenを利用すると、ヘッダーファイルからRustのコードを生成できる。
    (生成されるコードはちょっと辛い・・・)
  3. unsafeを使うとポインタが使える

上記の理由から、RustはC/C++との連携をしやすい言語かなと思っています。

Docker

nginxとnginx-link-functionはREADME.mdの通り。
Rustはrustupを入れて、インストールしました。

$ git clone https://github.com/akatsuki-chan/nginx-rust-function.git
$ cd nginx-rust-function
$ docker build  -t nginx-link-function .
$ docker run --rm -p 8888:8888 -ti nginx-link-function
$ curl http://127.0.0.1:8888/testCFunGreeting

まとめ

Rustとbindgenを使って、nginx-link-functionを利用することができました。

他にも共有メモリ機能や.soファイルのダウンロード(?)機能なんかあるらしいので、
ベンチマークとったりDBに接続したり遊んでみようかと思います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1