bossan 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ require 'bossan'
2
+ require 'pp'
3
+
4
+ class MyApp
5
+ def call env
6
+ body = ['hi!']
7
+ # pp env
8
+ [
9
+ 200, # Status code
10
+ { 'Content-Type' => 'text/html',
11
+ 'Content-Length' => body.join.size.to_s,
12
+ }, # Reponse headers
13
+ body # Body of the response
14
+ ]
15
+ end
16
+ end
17
+
18
+ # Rack::Handler::Bossan.run MyApp.new
19
+ run MyApp.new
@@ -102,6 +102,8 @@ static VALUE i_keys;
102
102
  static VALUE i_call;
103
103
  static VALUE i_new;
104
104
  static VALUE i_key;
105
+ static VALUE i_each;
106
+ static VALUE i_close;
105
107
 
106
108
  static char *server_name = "127.0.0.1";
107
109
  static short server_port = 8000;
@@ -668,11 +670,21 @@ close_response(client_t *client)
668
670
  client->response_closed = 1;
669
671
  }
670
672
 
673
+ static VALUE
674
+ collect_body(VALUE i, VALUE str, int argc, VALUE *argv)
675
+ {
676
+ if(argc < 1) {
677
+ return Qnil;
678
+ }
679
+ rb_str_concat(str, argv[0]);
680
+ return Qnil;
681
+ }
682
+
671
683
  static inline int
672
684
  processs_write(client_t *client)
673
685
  {
674
686
  VALUE iterator = NULL;
675
- VALUE arr;
687
+ VALUE v_body;
676
688
  VALUE item;
677
689
  char *buf;
678
690
  ssize_t buflen;
@@ -687,37 +699,34 @@ processs_write(client_t *client)
687
699
  return -1;
688
700
  }
689
701
 
690
- arr = rb_ary_entry(iterator, 2);
702
+ v_body = rb_ary_entry(iterator, 2);
691
703
 
692
- if (TYPE(arr) != T_ARRAY){
704
+ if(!rb_respond_to(v_body, i_each)){
693
705
  return -1;
694
706
  }
695
707
 
696
- int hlen = RARRAY_LEN(arr);
708
+ VALUE v_body_str = rb_str_new2("");
709
+ rb_block_call(v_body, i_each, 0, NULL, collect_body, v_body_str);
710
+ if(rb_respond_to(v_body, i_close)) {
711
+ rb_funcall(v_body, i_close, 0);
712
+ }
697
713
 
698
- for(int i=0; i<hlen;i++){
699
- item = rb_ary_entry(arr, i);
700
- if(TYPE(item) != T_STRING) {
701
- return -1;
702
- }
714
+ buf = StringValuePtr(v_body_str);
715
+ buflen = RSTRING_LEN(v_body_str);
703
716
 
704
- buf = StringValuePtr(item);
705
- buflen = RSTRING_LEN(item);
706
- //write
707
- bucket = new_write_bucket(client->fd, 1);
708
- set2bucket(bucket, buf, buflen);
709
- ret = writev_bucket(bucket);
710
- if(ret <= 0){
711
- return ret;
712
- }
713
- //mark
714
- client->write_bytes += buflen;
715
- //check write_bytes/content_length
716
- if(client->content_length_set){
717
- if(client->content_length <= client->write_bytes){
718
- // all done
719
- break;
720
- }
717
+ bucket = new_write_bucket(client->fd, 1);
718
+ set2bucket(bucket, buf, buflen);
719
+ ret = writev_bucket(bucket);
720
+ if(ret <= 0){
721
+ return ret;
722
+ }
723
+ //mark
724
+ client->write_bytes += buflen;
725
+ //check write_bytes/content_length
726
+ if(client->content_length_set){
727
+ if(client->content_length <= client->write_bytes){
728
+ // all done
729
+ /* break; */
721
730
  }
722
731
  }
723
732
  close_response(client);
@@ -1521,9 +1530,10 @@ process_rack_app(client_t *cli)
1521
1530
 
1522
1531
  VALUE* response_ary = RARRAY_PTR(cli->response);
1523
1532
 
1524
- if (TYPE(response_ary[0])!=T_FIXNUM ||
1525
- TYPE(response_ary[1])!=T_HASH ||
1526
- TYPE(response_ary[2])!=T_ARRAY){
1533
+ /* rb_p(cli->response); */
1534
+
1535
+ if (TYPE(response_ary[0]) != T_FIXNUM ||
1536
+ TYPE(response_ary[1]) != T_HASH) {
1527
1537
  return 0;
1528
1538
  }
1529
1539
 
@@ -1988,6 +1998,8 @@ Init_bossan_ext(void)
1988
1998
  rb_gc_register_address(&i_call);
1989
1999
  rb_gc_register_address(&i_new);
1990
2000
  rb_gc_register_address(&i_key);
2001
+ rb_gc_register_address(&i_each);
2002
+ rb_gc_register_address(&i_close);
1991
2003
 
1992
2004
  rb_gc_register_address(&rack_app); //rack app
1993
2005
 
@@ -1995,6 +2007,8 @@ Init_bossan_ext(void)
1995
2007
  i_call = rb_intern("call");
1996
2008
  i_keys = rb_intern("keys");
1997
2009
  i_key = rb_intern("key?");
2010
+ i_each = rb_intern("each");
2011
+ i_close = rb_intern("close");
1998
2012
 
1999
2013
  server = rb_define_module("Bossan");
2000
2014
  rb_gc_register_address(&server);
@@ -1,3 +1,3 @@
1
1
  module Bossan
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'rack/handler'
2
3
  require 'bossan'
3
4
 
@@ -6,7 +7,7 @@ module Rack
6
7
  module Bossan
7
8
  DEFAULT_OPTIONS = {
8
9
  :Host => '127.0.0.1',
9
- :Port => 8080,
10
+ :Port => 8000,
10
11
  # :Verbose => false
11
12
  }
12
13
 
@@ -20,7 +21,7 @@ module Rack
20
21
  def self.valid_options
21
22
  {
22
23
  "Host=HOST" => "Hostname to listen on (default: localhost)",
23
- "Port=PORT" => "Port to listen on (default: 8080)",
24
+ "Port=PORT" => "Port to listen on (default: 8000)",
24
25
  }
25
26
  end
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bossan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: high performance asynchronous rack web server
15
15
  email:
@@ -25,6 +25,7 @@ files:
25
25
  - README.md
26
26
  - Rakefile
27
27
  - bossan.gemspec
28
+ - examples/config.ru
28
29
  - examples/hello.rb
29
30
  - examples/sinatra_app.rb
30
31
  - examples/views/index.haml
@@ -66,3 +67,4 @@ signing_key:
66
67
  specification_version: 3
67
68
  summary: high performance asynchronous rack web server
68
69
  test_files: []
70
+ has_rdoc: