Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ミドルウェアにmrubyを組み込む方法 / How to Embed mruby into M...
Search
Kentaro Kuribayashi
July 28, 2017
Technology
3
2.8k
ミドルウェアにmrubyを組み込む方法 / How to Embed mruby into Middlewares Written in C
真夏の技術部&BPR室 TechMTG #3(ペパボ社内勉強会)
Kentaro Kuribayashi
July 28, 2017
Tweet
Share
More Decks by Kentaro Kuribayashi
See All by Kentaro Kuribayashi
Bidirectional Quadratic Voting Leveraging Issue-Based Matching
kentaro
2
350
大高生へのメッセージ(令和6年度「大高未来塾」) / Messages to Current Students
kentaro
0
250
「始め方」の始め方 / How to Start Starting Things
kentaro
5
860
Dynamic IoT Applications and Isomorphic IoT Systems Using WebAssembly
kentaro
1
1.3k
わたしがこのところハマっている「ライセンスフリー無線」のご紹介 / An Invitation to License-Free Radio
kentaro
1
510
先行きの見えなさを楽しさに変える ーVUCA時代のキャリア論と絶対他力主義ー / How to develop your career in the VUCA era
kentaro
7
5.4k
組織の生産性を高める意思決定の構造と方法 / How to do make decision rapidly and effectively
kentaro
41
22k
キャリアを時間・空間軸で考える / Thinking about your career from both time and space viewpoints
kentaro
15
16k
WEB+DB PRESSで特集記事を書く方法 / How to Become an Author of WEB+DB PRESS
kentaro
7
1.5k
Other Decks in Technology
See All in Technology
メールヘッダーを見てみよう
hinono
0
150
あなたの知らないクラフトビールの世界
miura55
0
170
企業テックブログにおける執筆ネタの考え方・見つけ方・広げ方 / How to Think of, Find, and Expand Writing Topics for Corporate Tech Blogs
honyanya
0
340
DevSecOps入門:Security Development Lifecycleによる開発プロセスのセキュリティ強化
yuriemori
0
170
My small contributions - Fujiwara Tech Conference 2025
ijin
0
1.6k
今から、 今だからこそ始める Terraform で Azure 管理 / Managing Azure with Terraform: The Perfect Time to Start
nnstt1
0
270
実践!生成AIのビジネス活用 / How to utilize Generative AI in your own business
gakumura
1
170
サーバレスの未来〜The Key to Simplifying Everything〜
kawaji_scratch
2
300
横断SREの立ち上げと、AWSセキュリティへの取り組みの軌跡
rvirus0817
3
2.9k
Amazon Route 53, 待ちに待った TLSAレコードのサポート開始
kenichinakamura
0
200
Skip Skip Run Run Run ♫
temoki
0
190
HCP Terraformで実現するPlatform Engineering/nikkei-tech-talk-29
nikkei_engineer_recruiting
0
190
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
Done Done
chrislema
182
16k
Rails Girls Zürich Keynote
gr2m
94
13k
Automating Front-end Workflow
addyosmani
1366
200k
Being A Developer After 40
akosma
89
590k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Why Our Code Smells
bkeepers
PRO
335
57k
Producing Creativity
orderedlist
PRO
343
39k
Docker and Python
trallard
43
3.2k
How GitHub (no longer) Works
holman
312
140k
Writing Fast Ruby
sferik
628
61k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
Transcript
ʙγϯϓϧͳαʔόͷ֦ுΛࡐʹઆ໌͠·͢ʙ ܀ྛ݈ଠ(.01FQBCP *OD ਅՆͷٕज़෦#13ࣨ5FDI.5(ʢࣾษڧձʣ ϛυϧΣΞʹmrubyΛΈࠐΉํ๏
(.0ϖύϘגࣜձࣾ ܀ྛ݈ଠ@kentaro औక$50 https://kentarok.org
ຊτʔΫʹΑͬͯಘΒΕΔ͜ͱ w$ͷϓϩάϥϜʹNSVCZΛΈࠐΈɺNSVCZͷεΫϦ ϓτΛ࣮ߦ͢Δํ๏͕Θ͔Γ·͢ wطଘͷϛυϧΣΞʹɺNSVCZΛΈࠐΜͰ֦ுͰ͖ ΔΑ͏ʹͳΓ·͢ wͭ·ΓɺOHY@NSVCZͷΑ͏ͳͷΛ࡞ΕΔΑ͏ʹͳ Δͱ͍͏͜ͱͰ͢Ͷʂʢݪཧతʹʣ
࣍ ֦ு͢ΔϛυϧΣΞ NSVCZΈࠐΈͷखॱ ͓ΘΓʹ
֦ு͢ΔϛυϧΣΞ
FDIPαʔόΛ֦ு͍͖ͯ͠·͢
FDIPαʔόɺΫϥΠΞϯτͷ3VCZͰͷྫ αʔό ΫϥΠΞϯτ
FDIPαʔόɺΫϥΠΞϯτΛ࣮ߦ ೖྗ͞ΕͨจࣈྻΛ ͦͷ··ฦ͚ͩ͢ͷ αʔόɻ
ͳͥFDIPαʔό͔ʁ w࣮ࡍɺ$Ͱॻ͍ͨFDIPαʔόΛ֦ு͠·͢ w͜ͷFDIPαʔόΛɺͨͱ͑OHJOYͷΑ͏ͳϛυϧΣ Ξͩͱࢥ͍ͬͯͩ͘͞ɻݪཧతʹɺಉ͡Α͏ͳΓ ํͰ֦ுͰ͖·͢ w͍͖ͳΓେ͖ͳϛυϧΣΞʹऔΓΜͰͭΒ͍˞ ͷͰɺ؆୯ͳͷΛྫʹ͡Ί͍͖ͯ·͠ΐ͏ ˞$ݴޠͱNSVCZͷࣝʹՃ͑ͯɺରͱͳΔϛυϧΣΞΛ֦ு͢ΔϊϋΔඞཁ͕͋Δ͔Βɻ
NSVCZΛΈࠐΜͩFDIPαʔό ೖྗ͞ΕͨจࣈྻΛ NSVCZͷίʔυͱ͠ ͯධՁ͠ɺ݁ՌΛฦ ͢αʔό
֦ுͨ͠FDIPαʔόͷಛ w༩͑ΒΕͨจࣈྻΛɺNSVCZͷίʔυͱͯ͠ධՁ͢Δ wNSVCZͷίʔυΛ࣮ߦͨ݁͠ՌͷܕΛผͯ͠ɺద ͳจࣈྻΛฦ͢ wFDIPαʔόͷߏମʢ(em * ܕʣͷఏڙ͢Δϝϯό ؔʹNSVCZίʔυ͔Β৮ΕΒΕΔ
NSVCZΈࠐΈͷखॱ
ΈࠐΈͷखॱ ೖྗ͞ΕͨจࣈྻΛNSVCZͷίʔυͱͯ͠ධՁ͢Δ NSVCZͷίʔυͱΈࠐΈରͷϛυϧΣΞͱͷ ؒͰɺΛదͳܕʹม͢Δ NSVCZͷίʔυத͔ΒϛυϧΣΞͷίʔυʹ৮Ε ͍ͨ߹ɺΫϥεͱϝιουΛ࡞͢Δ
MJCNSVCZΛϛυϧΣΞʹΈࠐΉ
ೖྗ͞ΕͨจࣈྻΛ NSVCZͷίʔυͱͯ͠ධՁ͢Δ
ೖྗΛNSVCZͷίʔυͱ࣮ͯ͠ߦ
͔͜͜ΒͲ͏ͬͯઌʹਐΉ͔ʁ
NSVCZͱϛυϧΣΞͷؒͰ ͷܕมΛ͢Δ
ϛυϧΣΞˠNSVCZˠϛυϧΣΞ NSVCZͷ ੈք ϛυϧΣΞͷ ੈք ϛυϧΣΞͷ ੈք (char * ܕͰ
ίʔυΛ͢˞ mrb_valueܕ ͔Βదͳܕม ˞ࠓճͦ͏͍ͯ͠Δ͚ͩͰɺ࣮ࡍʹͦͷଞʹϑΝΠϧΛΘͨ͢ͱ͔͍Ζ͍Ζํ๏͕͋Γ·͢ɻ
mruby_valueܕ͔Βͷܕม ࣮ࡍͷܕΛ ఆ͢Δ ܕ͝ͱʹ ม͍ͯ͘͠
લϖʔδͷิ wࠓճͷྫ؆୯ͳFDIPαʔόͳͷͰɺͲͷܕͰ͋ͬ ͯͯ͢(char * ܕʹม͍ͯ͠·͢ wͨͩ͠ɺݩͷܕ͕Θ͔ΔΑ͏ɺNSVCZίʔυͰͷ ܕ໊Λࣔ͢จࣈྻΛՃ͍ͯ͠·͢ɻ wҰൠతʹɺΈࠐΈରͷϛυϧΣΞ͕ظ͢Δ ܕʹม͍͖ͯ͠·͢
NSVCZίʔυͷத͔Β ϛυϧΣΞͷதʹ৮Δ
FDIPαʔόͷίΞߏମ typedef struct em_t { int reply_count; // ϦΫΤετͷฦ৴ճ char
*reply_prefix; // ϓϩϯϓτͷจࣈྻ mrb_state *mrb; } em; Emߏମͷఆٛ
NSVCZͷίʔυ͔ΒϛυϧΣΞʹ৮Δ NSVCZ͔Β Emߏମͷ ίʔυΛݺͿ Χϯτ͕ ͞Ε͍ͯΔ NSVCZ͔Β Emߏମͷ ίʔυΛݺͿ
ϓϩϯϓτͷ จࣈ͕มԽ
NSVCZʹΫϥεͱϝιουΛຒΊࠐΉ EmΫϥεΛ ࡞Δ EmΫϥεʹ ϝιουΛ࡞Δ
mrb_valueܕ ͔Βదͳܕม NSVCZˠϛυϧΣΞˠNSVCZ ϛυϧΣΞͷ ੈք NSVCZͷ ੈք NSVCZͷ ੈք mrb_valueܕ
ม ͖ͬ͞ͱٯͩͶ
ϝιουΛఆٛ͢Δ Em ߏମΛ औΓग़͢ Em ߏମͷ ϝϯόΛมߋ
ϙΠϯτmrb_stateͷudϝϯό mrb_value em_mrb_method_set_reply_prefix(mrb_state *mrb, mrb_value self); ϝιουఆٛͷγάωνϟҎԼͷ௨ΓͳͷͰɺ em->mrb->ud = self;
// udϝϯό(void *)ܕ // ……snip…… em *obj = (em *)mrb->ud; // ͳͷͰɺऔΓग़͢ͱ͖ʹΩϟετ͢Δ ͋ͱͰ͏ͨΊʹmrb->udʹEmߏମΛೖΕ͓ͯ͘
MJCNSVCZΛ ϛυϧΣΞʹΈࠐΉ
MJCNSVCZΛΈࠐΉ $ gcc src/em.c src/em_server.c \ -Iinclude -Ivendor/mruby/include \ -Lvendor/mruby/build/host/lib
-lmruby \ -o build/echo-mruby ҎԼͷΑ͏ʹϏϧυͯ͠ɺMJCNSVCZΛΈࠐΉ $ git clone
[email protected]
:mruby/mruby.git vendor/mruby $ cd vendor/mruby && rake all NSVCZΛ͖ͬͯͯϏϧυ͢Δ
ͬͱ͍͍ํ๏ˣΛࢀরͷ͜ͱ http://hb.matsumoto-r.jp/entry/2015/02/07/011237
͓ΘΓʹ
͋ͱˣΛΈͯͬͨΒ࡞ΕΔ https://github.com/kentaro/echo-mruby
͓ΘΓʹ w͍͖ͳΓ͍ͭ͝ϛυϧΣΞΛ֦ு͠Α͏ͱ͢Δͱɺ NSVCZͱؔͳ͍ͱ͜ΖͰΘ͔Βͳ͘ͳΔͷͰɺ؆୯ ͳྫͰΈࠐΈΛߦͬͯΈ·ͨ͠ w͓͍ͷϛυϧΣΞͷ֦ுੑʹࠔͬͨΒɺNSVCZΛ ΈࠐΉ͜ͱͰָ͕Ͱ͖ͳ͍͔ߟ͑ͯΈ·͠ΐ͏ w͋ͱɺ͍͍ײ͡ʹόʔϯʂͱΑΖ͘͠
NSVCZΔͷʹϖύϘΊͪΌ࠷ߴ ΤϥʔͰϋϚͬͯࢮΜͰ͚ͨͲɺ @matsumotory @udzura ͷ໊྆ʹฉ͍ͨΒ͙͢ղܾ͠ ͨ