crap_server 0.0.2 → 0.0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/crap_server.gemspec +9 -8
- data/lib/crap_server/application.rb +29 -21
- data/lib/crap_server/configure.rb +1 -1
- data/lib/crap_server/connection_instance.rb +12 -7
- data/lib/crap_server/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fec671da6d4ad0911a4471409620d7fb6de1d25b
|
4
|
+
data.tar.gz: 18b77248eb31818771cf374ba71b6bac2d6db5c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0468c1a3e10ec024543ad56a5d8a948a0b6313e0d58e7a9e780d099787ccf1cbd33e10f771cf31b0c0fd08539df033cb837186556ed8d687d87fd3072ce37af7
|
7
|
+
data.tar.gz: 12fd50db239ae0fdc63ff31086baaeece7cfbb96798cc1c6b8b488069fc8a120a790b8eaf47b8d96977da42941117ffa9db04ae7487eaaeca23e9b5a9f5bb86e
|
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# CrapServer
|
2
|
+
[](https://codeclimate.com/github/anga/crap_server)
|
2
3
|
|
3
|
-
Really thin
|
4
|
+
Really thin and non intuitive ruby server and framework. Made to be fast and ready for really heavy servers (not only http server).
|
4
5
|
|
5
6
|
# Another one?
|
6
7
|
|
7
8
|
Yes. Why? because 2 main reasons. First, this is not a HTTP Web server, this is a generic server that can be used for any kind of TCP Socket server.
|
8
|
-
Second and most important, because
|
9
|
+
Second and most important, because is funny :)
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
@@ -49,11 +50,11 @@ ruby my_app.rb
|
|
49
50
|
|
50
51
|
# Production ready?
|
51
52
|
|
52
|
-
No. At the moment
|
53
|
+
No. At the moment it's only a thin server that abstract you from TCP sockets works.
|
53
54
|
|
54
55
|
## Contributing
|
55
56
|
|
56
|
-
1. Fork it ( https://github.com/
|
57
|
+
1. Fork it ( https://github.com/anga/crap_server/fork )
|
57
58
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
59
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
60
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/crap_server.gemspec
CHANGED
@@ -4,21 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'crap_server/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'crap_server'
|
8
8
|
spec.version = CrapServer::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Andres Joser Borek']
|
10
|
+
spec.email = ['andres.b.dev@gmail.com']
|
11
11
|
spec.summary = %q{Really thin a non intuitive ruby server and framework.}
|
12
|
-
spec.description = %q{Really thin
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
12
|
+
spec.description = %q{Really thin and non intuitive ruby server and framework. Made to be fast and ready for really heavy servers (not only http server).}
|
13
|
+
spec.homepage = 'https://rubygems.org/gems/crap_server'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.required_ruby_version = '>= 1.9.2'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
23
|
# celluloid is for future use. Right now is not used
|
23
24
|
# spec.add_dependency "celluloid", '~> 0.15.2'
|
24
25
|
end
|
@@ -25,31 +25,39 @@ module CrapServer
|
|
25
25
|
# Main method. This setup all the connections and make the logic of the app
|
26
26
|
def run!(&block)
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
begin
|
29
|
+
# Bup the maximum opened file to the maximum allowed by the system
|
30
|
+
Process.setrlimit(:NOFILE, Process.getrlimit(:NOFILE)[1])
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
# Start IPv4 and IPv6 connection for the current port
|
33
|
+
open_connections
|
33
34
|
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
# Some log info to the user :)
|
37
|
+
logger.info 'Initializing Crap Server'
|
38
|
+
logger.info "Listening 0.0.0.0:#{config.port}"
|
39
|
+
logger.debug "Maximum allowed waiting connections: #{Socket::SOMAXCONN}"
|
40
|
+
logger.debug "Maximum number of allowed connections: #{Process.getrlimit(:NOFILE)[1]}" # Same as maximum of opened files
|
41
|
+
logger.info ''
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
# The main loop. Listening IPv4 and IPv6 connections
|
44
|
+
Socket.accept_loop([socket_ipv4, socket_ipv6]) do |remote_socket, address_info|
|
45
|
+
connection_loop(remote_socket, address_info, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
close_connections
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
# If any kind of error happens, we MUST close the sockets
|
51
|
+
rescue => e
|
52
|
+
logger.error "Error: #{e.message}"
|
53
|
+
e.backtrace.each do |line|
|
54
|
+
logger.error line
|
55
|
+
end
|
56
|
+
close_connections
|
51
57
|
|
52
|
-
|
58
|
+
rescue Interrupt
|
59
|
+
close_connections
|
60
|
+
end
|
53
61
|
end
|
54
62
|
|
55
63
|
protected
|
@@ -94,6 +102,8 @@ module CrapServer
|
|
94
102
|
|
95
103
|
# Close all the sockets.
|
96
104
|
def close_connections
|
105
|
+
logger.debug 'Closing all connections.'
|
106
|
+
logger.debug 'Bye!'
|
97
107
|
# If any kind of error happens, we MUST close the sockets
|
98
108
|
if socket_ipv4
|
99
109
|
# Shuts down communication on all copies of the connection.
|
@@ -144,8 +154,6 @@ module CrapServer
|
|
144
154
|
raise ConnectionError.new "Unable to bind #{config.port} port."
|
145
155
|
end
|
146
156
|
|
147
|
-
puts "config: #{config.manual_read}"
|
148
|
-
|
149
157
|
socket_ipv4.listen(config.max_pending_connections)
|
150
158
|
# Tell to the Kernel that is ok to rebind the port if is in TIME_WAIT state (after close the connection
|
151
159
|
# and the Kernel wait for client acknowledgement)
|
@@ -32,7 +32,7 @@ module CrapServer
|
|
32
32
|
@manual_read = false
|
33
33
|
@read_buffer_size = 1024*16 # 16K for read buffer
|
34
34
|
@max_pending_connections = Socket::SOMAXCONN
|
35
|
-
@method = :
|
35
|
+
@method = :non_blocking
|
36
36
|
@auto_close_connection = true
|
37
37
|
@log_file = STDOUT
|
38
38
|
@log_level = Logger::DEBUG
|
@@ -40,13 +40,18 @@ module CrapServer
|
|
40
40
|
protected
|
41
41
|
# Read the data from the socket
|
42
42
|
def read_data
|
43
|
-
|
44
|
-
|
45
|
-
@
|
46
|
-
|
47
|
-
@
|
48
|
-
|
49
|
-
@
|
43
|
+
begin
|
44
|
+
# Read the data from the socket
|
45
|
+
if @method == :normal
|
46
|
+
@socket.read(config.read_buffer_size)
|
47
|
+
elsif @method == :partial
|
48
|
+
@socket.readpartial(config.read_buffer_size)
|
49
|
+
elsif @method == :non_blocking
|
50
|
+
@socket.read_nonblock(config.read_buffer_size)
|
51
|
+
end
|
52
|
+
rescue Errno::EAGAIN
|
53
|
+
IO.select([connection])
|
54
|
+
retry
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
data/lib/crap_server/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andres Joser Borek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
-
description: Really thin
|
27
|
+
description: Really thin and non intuitive ruby server and framework. Made to be fast
|
28
28
|
and ready for really heavy servers (not only http server).
|
29
29
|
email:
|
30
30
|
- andres.b.dev@gmail.com
|
@@ -44,7 +44,7 @@ files:
|
|
44
44
|
- lib/crap_server/connection_instance.rb
|
45
45
|
- lib/crap_server/helpers/socket_reader.rb
|
46
46
|
- lib/crap_server/version.rb
|
47
|
-
homepage:
|
47
|
+
homepage: https://rubygems.org/gems/crap_server
|
48
48
|
licenses:
|
49
49
|
- MIT
|
50
50
|
metadata: {}
|
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 1.9.2
|
60
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - ">="
|