Skip to content

Commit

Permalink
Rename Rev to Coolio in Ruby code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Arcieri committed Nov 6, 2010
1 parent 316b556 commit 9f1f374
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 271 deletions.
28 changes: 14 additions & 14 deletions lib/rev.rb → lib/cool.io.rb
Expand Up @@ -7,22 +7,22 @@
require 'iobuffer'
require "cool.io_ext"

# Legacy constant
Rev = Coolio

require "rev/loop"
require "rev/meta"
require "rev/io_watcher"
require "rev/timer_watcher"
require "rev/async_watcher"
require "rev/listener"
require "rev/io"
require "rev/dns_resolver"
require "rev/socket"
require "rev/server"
require "rev/http_client"
require "cool.io/loop"
require "cool.io/meta"
require "cool.io/io"
require "cool.io/iowatcher"
require "cool.io/timer_watcher"
require "cool.io/async_watcher"
require "cool.io/listener"
require "cool.io/dns_resolver"
require "cool.io/socket"
require "cool.io/server"
require "cool.io/http_client"

module Coolio
VERSION = File.read File.expand_path('../../VERSION', __FILE__)
def self.version; VERSION; end
end

# Legacy constant
Rev = Coolio
4 changes: 2 additions & 2 deletions lib/rev/async_watcher.rb → lib/cool.io/async_watcher.rb
@@ -1,10 +1,10 @@
#--
# Copyright (C)2007 Tony Arcieri
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

module Rev
module Coolio
# The AsyncWatcher lets you signal another thread to wake up. Its
# intended use is notifying another thread of events.
class AsyncWatcher < IOWatcher
Expand Down
7 changes: 4 additions & 3 deletions lib/rev/dns_resolver.rb → lib/cool.io/dns_resolver.rb
@@ -1,5 +1,5 @@
#--
# Copyright (C)2007 Tony Arcieri
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#
Expand All @@ -16,7 +16,8 @@
# http://gist.github.com/663299
#
#++
module Rev

module Coolio
# A non-blocking DNS resolver. It provides interfaces for querying both
# /etc/hosts and nameserves listed in /etc/resolv.conf, or nameservers of
# your choosing.
Expand Down Expand Up @@ -52,7 +53,7 @@ def self.hosts(host, hostfile = HOSTS)
hosts[host]
end

# Create a new Rev::Watcher descended object to resolve the
# Create a new Coolio::Watcher descended object to resolve the
# given hostname. If you so desire you can also specify a
# list of nameservers to query. By default the resolver will
# use nameservers listed in /etc/resolv.conf
Expand Down
43 changes: 21 additions & 22 deletions lib/rev/eventmachine.rb → lib/cool.io/eventmachine.rb
Expand Up @@ -4,6 +4,8 @@
# See file LICENSE for details
#++

require 'cool.io'

# EventMachine emulation for Cool.io:
#
# require 'coolio/eventmachine'
Expand All @@ -12,23 +14,20 @@
# Benefits: timers are more accurate using libev than using EM
# TODO: some things like connection timeouts aren't implemented yet
# DONE: timers and normal socket functions are implemented.

require 'rev'

module EventMachine
class << self
# Start the Reactor loop
def run
yield if block_given?
Rev::Loop.default.run
Coolio::Loop.default.run
end

# Stop the Reactor loop
def stop_event_loop
Rev::Loop.default.stop
Coolio::Loop.default.stop
end

class OneShotEMTimer < Rev::TimerWatcher
class OneShotEMTimer < Coolio::TimerWatcher
def setup(proc)
@proc = proc
end
Expand All @@ -38,7 +37,7 @@ def on_timer
end
end

# ltodo: use Rev's PeriodicTimer to wrap EM's two similar to it
# ltodo: use Coolio's PeriodicTimer to wrap EM's two similar to it
# todo: close all connections on 'stop', I believe

def add_timer(interval, proc = nil, &block)
Expand All @@ -47,7 +46,7 @@ def add_timer(interval, proc = nil, &block)
t.setup(block)

# fire 'er off ltodo: do we keep track of these timers in memory?
t.attach(Rev::Loop.default)
t.attach(Coolio::Loop.default)
t
end

Expand All @@ -72,7 +71,7 @@ def connect(addr, port, handler = Connection, *args, &block)

wrapped_child = CallsBackToEM.connect(addr, port, *args) # ltodo: args? what? they're used? also TODOC TODO FIX
conn = klass.new(wrapped_child) # ltodo [?] addr, port, *args)
wrapped_child.attach(Rev::Loop.default) # necessary
wrapped_child.attach(Coolio::Loop.default) # necessary
conn.heres_your_socket(wrapped_child)
wrapped_child.call_back_to_this(conn) # calls post_init for us
yield conn if block_given?
Expand All @@ -87,14 +86,14 @@ def start_server(addr, port, handler = Connection, *args, &block)
Class.new( Connection ) {handler and include handler}
end

server = Rev::TCPServer.new(addr, port, CallsBackToEM, *args) do |wrapped_child|
server = Coolio::TCPServer.new(addr, port, CallsBackToEM, *args) do |wrapped_child|
conn = klass.new(wrapped_child)
conn.heres_your_socket(wrapped_child) # ideally NOT have this :)
wrapped_child.call_back_to_this(conn)
block.call(conn) if block
end

server.attach(Rev::Loop.default)
server.attach(Coolio::Loop.default)
end

def stop_server(server)
Expand All @@ -103,7 +102,7 @@ def stop_server(server)

# Set the maximum number of descriptors available to this process
def set_descriptor_table_size(nfds)
Rev::Utils.maxfds = nfds
Coolio::Utils.maxfds = nfds
end

# Compatibility noop. Handled automatically by libev
Expand All @@ -113,8 +112,8 @@ def epoll; end
def kqueue; end
end

class CallsBackToEM < Rev::TCPSocket
class ConnectTimer < Rev::TimerWatcher
class CallsBackToEM < Coolio::TCPSocket
class ConnectTimer < Coolio::TimerWatcher
attr_accessor :parent
def on_timer
@parent.connection_has_timed_out
Expand Down Expand Up @@ -178,7 +177,7 @@ def self.connect(*args)
# the connect timer currently kills TCPServer classes. I'm not sure why.
#@connection_timer = ConnectTimer.new(14) # needs to be at least higher than 12 :)
#@connection_timer.parent = a
#@connection_timer.attach(Rev::Loop.default)
#@connection_timer.attach(Coolio::Loop.default)
a
end
end
Expand All @@ -203,29 +202,29 @@ def unbind; end

# Callback fired when data is received
# def receive_data(data); end
def heres_your_socket(instantiated_rev_socket)
instantiated_rev_socket.call_back_to_this self
@wrapped_rev = instantiated_rev_socket
def heres_your_socket(instantiated_coolio_socket)
instantiated_coolio_socket.call_back_to_this self
@wrapped_coolio = instantiated_coolio_socket
end

# Send data to the current connection -- called by them
def send_data(data)
@wrapped_rev.write data
@wrapped_coolio.write data
end

# Close the connection, optionally after writing
def close_connection(after_writing = false)
return close_connection_after_writing if after_writing
@wrapped_rev.close
@wrapped_coolio.close
end

# Close the connection after all data has been written
def close_connection_after_writing
@wrapped_rev.output_buffer_size.zero? ? @wrapped_rev.close : @wrapped_rev.should_close_after_writing
@wrapped_coolio.output_buffer_size.zero? ? @wrapped_coolio.close : @wrapped_coolio.should_close_after_writing
end

def get_peername
family, port, host_name, host_ip = @wrapped_rev.peeraddr
family, port, host_name, host_ip = @wrapped_coolio.peeraddr
Socket.pack_sockaddr_in(port, host_ip) # pack it up :)
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/rev/http_client.rb → lib/cool.io/http_client.rb
@@ -1,13 +1,13 @@
#--
# Copyright (C)2007 Tony Arcieri
# Copyright (C)2007-10 Tony Arcieri
# Includes portions originally Copyright (C)2005 Zed Shaw
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

require File.dirname(__FILE__) + '/../http11_client'
require 'http11_client'

module Rev
module Coolio
# A simple hash is returned for each request made by HttpClient with
# the headers that were given by the server for that request.
class HttpResponseHeader < Hash
Expand Down Expand Up @@ -110,15 +110,15 @@ def encode_cookies(cookies)
end
end

# HTTP client class implemented as a subclass of Rev::TCPSocket. Encodes
# HTTP client class implemented as a subclass of Coolio::TCPSocket. Encodes
# requests and allows streaming consumption of the response. Response is
# parsed with a Ragel-generated whitelist parser which supports chunked
# HTTP encoding.
#
# == Example
#
# loop = Rev::Loop.default
# client = Rev::HttpClient.connect("www.google.com").attach
# loop = Coolio::Loop.default
# client = Coolio::HttpClient.connect("www.google.com").attach
# client.get('/search', query: {q: 'foobar'})
# loop.run
#
Expand Down Expand Up @@ -209,7 +209,7 @@ def on_error(reason)
#########

#
# Rev callbacks
# Coolio callbacks
#

def on_connect
Expand Down Expand Up @@ -244,7 +244,7 @@ def send_request_header
head['content-length'] ||= body ? body.length : 0

# Set the User-Agent if it hasn't been specified
head['user-agent'] ||= "Rev #{Rev::VERSION}"
head['user-agent'] ||= "Coolio #{Coolio::VERSION}"

# Default to Connection: close
head['connection'] ||= 'close'
Expand Down Expand Up @@ -292,7 +292,7 @@ def parse_header(header)

begin
@parser_nbytes = @parser.execute(header, @data.to_str, @parser_nbytes)
rescue Rev::HttpClientParserError
rescue Coolio::HttpClientParserError
on_error "invalid HTTP format, parsing fails"
@state = :invalid
end
Expand Down
18 changes: 9 additions & 9 deletions lib/rev/io.rb → lib/cool.io/io.rb
@@ -1,17 +1,17 @@
#--
# Copyright (C)2007 Tony Arcieri
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

module Rev
# A buffered I/O class witch fits into the Rev Watcher framework.
module Coolio
# A buffered I/O class witch fits into the Coolio Watcher framework.
# It provides both an observer which reads data as it's received
# from the wire and a buffered write watcher which stores data and writes
# it out each time the socket becomes writable.
#
# This class is primarily meant as a base class for other streams
# which need non-blocking writing, and is used to implement Rev's
# which need non-blocking writing, and is used to implement Coolio's
# Socket class and its associated subclasses.
class IO
extend Meta
Expand Down Expand Up @@ -159,16 +159,16 @@ def detach_write_watcher
@_write_watcher.detach if @_write_watcher and @_write_watcher.attached?
end

# Internal class implementing watchers used by Rev::IO
# Internal class implementing watchers used by Coolio::IO
class Watcher < IOWatcher
def initialize(ruby_io, rev_io, flags)
@rev_io = rev_io
def initialize(ruby_io, coolio_io, flags)
@coolio_io = coolio_io
super(ruby_io, flags)
end

# Configure IOWatcher event callbacks to call the method passed to #initialize
def on_readable; @rev_io.__send__(:on_readable); end
def on_writable; @rev_io.__send__(:on_writable); end
def on_readable; @coolio_io.__send__(:on_readable); end
def on_writable; @coolio_io.__send__(:on_writable); end
end
end
end
4 changes: 2 additions & 2 deletions lib/rev/io_watcher.rb → lib/cool.io/iowatcher.rb
@@ -1,10 +1,10 @@
#--
# Copyright (C)2007 Tony Arcieri
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

module Rev
module Coolio
class IOWatcher
# The actual implementation of this class resides in the C extension
# Here we metaprogram proper event_callbacks for the callback methods
Expand Down
14 changes: 7 additions & 7 deletions lib/rev/listener.rb → lib/cool.io/listener.rb
@@ -1,12 +1,12 @@
#--
# Copyright (C)2007 Tony Arcieri
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

require 'socket'

module Rev
module Coolio
# Listeners wait for incoming connections. When a listener receives a
# connection it fires the on_connection event with the newly accepted
# socket as a parameter.
Expand Down Expand Up @@ -35,7 +35,7 @@ def on_connection(socket); end
protected
#########

# Rev callback for handling new connections
# Coolio callback for handling new connections
def on_readable
begin
on_connection @listen_socket.accept_nonblock
Expand All @@ -56,14 +56,14 @@ def on_readable
class TCPListener < Listener
DEFAULT_BACKLOG = 1024

# Create a new Rev::TCPListener on the specified address and port.
# Create a new Coolio::TCPListener on the specified address and port.
# Accepts the following options:
#
# :backlog - Max size of the pending connection queue (default 1024)
# :reverse_lookup - Retain BasicSocket's reverse DNS functionality (default false)
#
# If the specified address is an TCPServer object, it will ignore
# the port and :backlog option and create a new Rev::TCPListener out
# the port and :backlog option and create a new Coolio::TCPListener out
# of the existing TCPServer object.
def initialize(addr, port = nil, options = {})
BasicSocket.do_not_reverse_lookup = true unless options[:reverse_lookup]
Expand All @@ -81,11 +81,11 @@ def initialize(addr, port = nil, options = {})
end

class UNIXListener < Listener
# Create a new Rev::UNIXListener
# Create a new Coolio::UNIXListener
#
# Accepts the same arguments as UNIXServer.new
# Optionally, it can also take anyn existing UNIXServer object
# and create a Rev::UNIXListener out of it.
# and create a Coolio::UNIXListener out of it.
def initialize(*args)
super(::UNIXServer === args.first ? args.first : ::UNIXServer.new(*args))
end
Expand Down

0 comments on commit 9f1f374

Please sign in to comment.