[go: nahoru, domu]

Skip to content

Commit

Permalink
Use embed_mruby_code.pl for channel and task and apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
naritta committed Nov 14, 2017
1 parent 63b9d27 commit e813f5d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/handler/mruby/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void h2o_mruby_channel_init_context(h2o_mruby_shared_context_t *shared_ctx)
{
mrb_state *mrb = shared_ctx->mrb;

h2o_mruby_eval_expr(mrb, H2O_MRUBY_CODE_CHAHNNEL);
h2o_mruby_eval_expr(mrb, H2O_MRUBY_CODE_CHANNEL);
h2o_mruby_assert(mrb);

struct RClass *module, *klass;
Expand Down
68 changes: 34 additions & 34 deletions lib/handler/mruby/embedded.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
" $__TOP_SELF__.eval(__h2o_conf[:code], nil, __h2o_conf[:file], __h2o_conf[:line])\n" \
"end\n" \
"module Kernel\n" \
"def task(&block)\n" \
" f = Fiber.new do\n" \
" block.call\n" \
" # For when it's called in h2o_mruby_run_fiber and return output,\n" \
" # or block doesn't have asynchronous callback\n" \
" Fiber.yield([0, nil, nil])\n" \
" end\n" \
" fiber_res = f.resume()\n" \
" # In case having no asynchronous callback function\n" \
" if fiber_res[0] == 0\n" \
" return\n" \
" end\n" \
" receiver = fiber_res[1]\n" \
" klass = fiber_res[2][0]\n" \
" # This should be called only one time.\n" \
" # After that, the fiber is called in mruby_run_fiber and it register receiver in it.\n" \
" klass.register_receiver(receiver, klass)\n" \
" end\n" \
" def task(&block)\n" \
" f = Fiber.new do\n" \
" block.call\n" \
" # For when it's called in h2o_mruby_run_fiber and return output,\n" \
" # or block doesn't have asynchronous callback\n" \
" Fiber.yield([0, nil, nil])\n" \
" end\n" \
" fiber_res = f.resume()\n" \
" # In case having no asynchronous callback function\n" \
" if fiber_res[0] == 0\n" \
" return\n" \
" end\n" \
" receiver = fiber_res[1]\n" \
" klass = fiber_res[2][0]\n" \
" # This should be called only one time.\n" \
" # After that, the fiber is called in mruby_run_fiber and it register receiver in it.\n" \
" klass.register_receiver(receiver, klass)\n" \
" end\n" \
" def _h2o_define_callback(name, id)\n" \
" Kernel.define_method(name) do |*args|\n" \
" ret = Fiber.yield([ id, _h2o_create_resumer(), args ])\n" \
Expand Down Expand Up @@ -158,24 +158,24 @@
" end\n" \
"end\n"

/* lib/handler/mruby/embedded/chunked.rb */
#define H2O_MRUBY_CODE_CHAHNNEL \
"module H2O\n" \
" class Channel\n" \
" def _init()\n" \
" @queue = []\n" \
" end\n" \
" def push(o)\n" \
" @queue << o\n" \
/* lib/handler/mruby/embedded/channel.rb */
#define H2O_MRUBY_CODE_CHANNEL \
"module H2O\n" \
" class Channel\n" \
" def _init()\n" \
" @queue = []\n" \
" end\n" \
" def push(o)\n" \
" @queue << o\n" \
" self._notify\n" \
" end\n" \
" def shift\n" \
" while true\n" \
" if !@queue.empty?\n" \
" return @queue.shift\n" \
" end\n" \
" _h2o__channel_wait(self)\n" \
" end\n" \
" def shift\n" \
" while true\n" \
" if !@queue.empty?\n" \
" return @queue.shift\n" \
" end\n" \
" _h2o__channel_wait(self)\n" \
" end\n" \
" end\n" \
" end\n" \
"end\n"
39 changes: 39 additions & 0 deletions lib/handler/mruby/embedded/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2017 Ritta Narita
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

module H2O
class Channel
def _init()
@queue = []
end
def push(o)
@queue << o
self._notify
end
def shift
while true
if !@queue.empty?
return @queue.shift
end
_h2o__channel_wait(self)
end
end
end
end
3 changes: 2 additions & 1 deletion misc/regen.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ tokens:
lib/handler/mruby/embedded.c.h: misc/embed_mruby_code.pl \
lib/handler/mruby/embedded/core.rb \
lib/handler/mruby/embedded/http_request.rb \
lib/handler/mruby/embedded/chunked.rb
lib/handler/mruby/embedded/chunked.rb \
lib/handler/mruby/embedded/channel.rb
misc/embed_mruby_code.pl $^ > $@
clang-format -i $@

Expand Down

0 comments on commit e813f5d

Please sign in to comment.