crap_server 0.0.2.1 → 0.0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/crap_server.gemspec +4 -3
- data/lib/crap_server/application.rb +2 -2
- data/lib/crap_server/configure.rb +3 -0
- data/lib/crap_server/connection_instance.rb +9 -5
- data/lib/crap_server/version.rb +1 -1
- data/spec/application_spec.rb +58 -0
- data/spec/spec_helper.rb +12 -0
- metadata +24 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 636e155531fe01738c575fc3d23dcd24557cd866
|
4
|
+
data.tar.gz: eb2b425befbd907828b6bdf55d1981643ef4f05d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07230fa972fdf9f4b9fc5cf10043a0a4593fee1811012d9f1d93785dd585b82eb03bf02d7b225478bfb3b553286bfac0b54438ceb2f71f4effffb61d81e5c3fc
|
7
|
+
data.tar.gz: a3e470a6d2e4c3043b2c872da4e8cbfca3166e28f7795c8008d4cb50bf67b4ea6a8514e9b184c5e704cb534c02f2d4d2bb89fba4517daf008532ca938be50add
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# CrapServer
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/crap_server.svg)](http://badge.fury.io/rb/crap_server)
|
2
3
|
[![Code Climate](https://codeclimate.com/github/anga/crap_server/badges/gpa.svg)](https://codeclimate.com/github/anga/crap_server)
|
3
4
|
|
4
|
-
Really thin and non intuitive ruby server
|
5
|
+
Really thin and non intuitive ruby server. Made to be fast and ready for really heavy servers (not only http server).
|
5
6
|
|
6
7
|
# Another one?
|
7
8
|
|
data/crap_server.gemspec
CHANGED
@@ -6,10 +6,10 @@ require 'crap_server/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'crap_server'
|
8
8
|
spec.version = CrapServer::VERSION
|
9
|
-
spec.authors = ['Andres
|
9
|
+
spec.authors = ['Andres Jose Borek']
|
10
10
|
spec.email = ['andres.b.dev@gmail.com']
|
11
|
-
spec.summary = %q{Really thin a non intuitive ruby server
|
12
|
-
spec.description = %q{Really thin and non intuitive ruby server
|
11
|
+
spec.summary = %q{Really thin a non intuitive ruby server.}
|
12
|
+
spec.description = %q{Really thin and non intuitive ruby server. Made to be fast and ready for really heavy servers (not only http server).}
|
13
13
|
spec.homepage = 'https://rubygems.org/gems/crap_server'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 1.9.2'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
23
24
|
# celluloid is for future use. Right now is not used
|
24
25
|
# spec.add_dependency "celluloid", '~> 0.15.2'
|
25
26
|
end
|
@@ -185,7 +185,7 @@ module CrapServer
|
|
185
185
|
# Main configuration.
|
186
186
|
# See Crap::Configure
|
187
187
|
def config
|
188
|
-
@config
|
188
|
+
@config ||= CrapServer::Configure.new
|
189
189
|
end
|
190
190
|
|
191
191
|
def logger=(value)
|
@@ -195,7 +195,7 @@ module CrapServer
|
|
195
195
|
def logger
|
196
196
|
if not @logger
|
197
197
|
@logger = Logger.new(config.log_file)
|
198
|
-
@logger.level =
|
198
|
+
@logger.level = config.log_level
|
199
199
|
end
|
200
200
|
@logger
|
201
201
|
end
|
@@ -27,6 +27,8 @@ module CrapServer
|
|
27
27
|
attr_accessor :log_file
|
28
28
|
# The log level used
|
29
29
|
attr_accessor :log_level
|
30
|
+
# The timeout using when we use non-blocking method
|
31
|
+
attr_accessor :timeout
|
30
32
|
def initialize
|
31
33
|
@port = 7331
|
32
34
|
@manual_read = false
|
@@ -36,6 +38,7 @@ module CrapServer
|
|
36
38
|
@auto_close_connection = true
|
37
39
|
@log_file = STDOUT
|
38
40
|
@log_level = Logger::DEBUG
|
41
|
+
@timeout = nil # By default, no timeout. Used to allow persistent connections.
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -26,10 +26,14 @@ module CrapServer
|
|
26
26
|
|
27
27
|
# Write to the client the given string
|
28
28
|
def write(string)
|
29
|
-
|
30
|
-
@
|
31
|
-
|
32
|
-
@
|
29
|
+
begin
|
30
|
+
if @method == :normal or @method == :partial
|
31
|
+
@socket.write(string)
|
32
|
+
elsif @method == :non_blocking
|
33
|
+
@socket.write_nonblock(string)
|
34
|
+
end
|
35
|
+
rescue IO::WaitWritable, Errno::EINTR
|
36
|
+
IO.select(nil, [@socket], nil, config.timeout)
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -50,7 +54,7 @@ module CrapServer
|
|
50
54
|
@socket.read_nonblock(config.read_buffer_size)
|
51
55
|
end
|
52
56
|
rescue Errno::EAGAIN
|
53
|
-
IO.select([connection])
|
57
|
+
IO.select([connection],nil,nil, config.timeout)
|
54
58
|
retry
|
55
59
|
end
|
56
60
|
end
|
data/lib/crap_server/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe CrapServer::Application do
|
3
|
+
before do
|
4
|
+
# Reset to nil the configuration
|
5
|
+
CrapServer::Application.class_eval do
|
6
|
+
@config = nil
|
7
|
+
end
|
8
|
+
# Reset the logger to nil
|
9
|
+
CrapServer::Application.class_eval do
|
10
|
+
@logger = Dummy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
context 'run!' do
|
14
|
+
|
15
|
+
it 'should accept a block' do
|
16
|
+
expect(CrapServer::Application.method(:run!).parameters[-1][0]).to eq(:block)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'without loop' do
|
20
|
+
before do
|
21
|
+
# We don't want to block the specs because the sockets
|
22
|
+
allow(Socket).to receive(:accept_loop).and_return(nil)
|
23
|
+
allow(Socket).to receive(:new) do |*args|
|
24
|
+
Dummy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should bind IPv4 and IPv6' do
|
29
|
+
@v4 = false
|
30
|
+
@v6 = false
|
31
|
+
allow(Socket).to receive(:new) do |*args|
|
32
|
+
@v4 = true if args[0] == :INET and args[1] == :STREAM and args.size == 2
|
33
|
+
@v6 = true if args[0] == :INET and args[1] == :STREAM and args.size == 2
|
34
|
+
Dummy
|
35
|
+
end
|
36
|
+
CrapServer::Application.run! do
|
37
|
+
end
|
38
|
+
expect(@v4).to eq(true)
|
39
|
+
expect(@v6).to eq(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'if the user does not configure the app, should start the default configuration' do
|
43
|
+
expect(CrapServer::Configure).to receive(:new) do
|
44
|
+
Dummy
|
45
|
+
end
|
46
|
+
CrapServer::Application.run! do
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should bump to the maximum allowed opened files' do
|
51
|
+
expect(Process).to receive(:setrlimit).with(:NOFILE, Process.getrlimit(:NOFILE)[1])
|
52
|
+
CrapServer::Application.run! do
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crap_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Andres
|
7
|
+
- Andres Jose Borek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -24,8 +24,22 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
-
|
28
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: Really thin and non intuitive ruby server. Made to be fast and ready
|
42
|
+
for really heavy servers (not only http server).
|
29
43
|
email:
|
30
44
|
- andres.b.dev@gmail.com
|
31
45
|
executables: []
|
@@ -44,6 +58,8 @@ files:
|
|
44
58
|
- lib/crap_server/connection_instance.rb
|
45
59
|
- lib/crap_server/helpers/socket_reader.rb
|
46
60
|
- lib/crap_server/version.rb
|
61
|
+
- spec/application_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
47
63
|
homepage: https://rubygems.org/gems/crap_server
|
48
64
|
licenses:
|
49
65
|
- MIT
|
@@ -67,5 +83,7 @@ rubyforge_project:
|
|
67
83
|
rubygems_version: 2.2.2
|
68
84
|
signing_key:
|
69
85
|
specification_version: 4
|
70
|
-
summary: Really thin a non intuitive ruby server
|
71
|
-
test_files:
|
86
|
+
summary: Really thin a non intuitive ruby server.
|
87
|
+
test_files:
|
88
|
+
- spec/application_spec.rb
|
89
|
+
- spec/spec_helper.rb
|