<commit_before>h1. Rev

Rev is an event library for Ruby, built on the libev event library which 
provides a cross-platform interface to high performance system calls .  This 
includes the epoll system call for Linux, the kqueue system call for BSDs and 
OS X, and the completion ports interface for Solaris.

Rev also binds asynchronous wrappers to Ruby's core socket classes so you can
use them in conjunction with Rev to build asynchronous event-driven 
applications.

You can include Rev in your programs with:

 <pre><code>require 'rubygems'
 require 'rev'</code></pre>

For more information, consult the RubyForge page:

http://rev.rubyforge.org

http://rubyforge.org/projects/rev

Questions?  Sign up for the mailing list at:

http://rubyforge.org/mailman/listinfo/rev-talk

The latest development code is available via github at:

git://github.com/tarcieri/rev.git

h2. Anatomy

Rev builds on two core classes which bind to the libev API:

* Rev::Loop - This class represents an event loop which uses underlying high
  performance system calls to wait for events.

* Rev::Watcher - This is the base class for event observers.  Once you attach
  an event observer to a loop and start running it, you will begin receiving
  callbacks to particlar methods when events occur.

h2. Watchers

There are presently two types of watchers:

* Rev::IOWatcher - This class waits for an IO object to become readable,
  writable, or both.

* Rev::TimerWatcher - This class waits for a specified duration then fires
  an event.  You can also configure it to fire an event at specified intervals.

h2. Using Watchers

Watchers have five important methods:

* attach(loop) - This binds a watcher to the specified event loop.  If the
  watcher is already bound to a loop it will be detached first, then attached
  to the new one.

* detach - This completely unbinds a watcher from an event loop.

* disable - This stops the watcher from receiving events but does not unbind
  it from the loop.  If you are trying to toggle a watcher on and off, it's
  best to use this method (and enable) as it performs better than completely
  removing the watcher from the event loop.

* enable - This re-enables a watcher which has been disabled in the past.
  The watcher must still be bound to an event loop.

* evloop - This returns the Rev::Loop object which the watcher is currently
  bound to.

h2. Asynchronous Wrappers

Several classes which provide asynchronous event-driven wrappers for Ruby's
core socket classes are also provided.  Among these are:

* Rev::TCPSocket - A buffered wrapper to core Ruby's Socket class for use with
  TCP sockets.  You can asynchronously create outgoing TCP connections using 
  its Rev::TCPSocket.connect method.  Rev::TCPSocket provides write buffering
  to ensure that writing never blocks, and has asynchronous callbacks for
  several events, including when the connection is opened (or failed), when
  data is received, when the write buffer has been written out completely,
  and when the connection closes.

* Rev::TCPServer - A wrapper for TCPServer which creates new instances of
  Rev::TCPSocket (or any subclass you wish to provide) whenever an incoming
  connection is received.

* Rev::HttpClient - An HTTP/1.1 client with support for chunked encoding
  and streaming response processing through asynchronous callbacks.

h2. Example Program

Below is an example of how to write an echo server:

  <pre><code>require 'rev'
  HOST = 'localhost'
  PORT = 4321

  class EchoServerConnection < Rev::TCPSocket
    def on_connect
      puts "#{remote_addr}:#{remote_port} connected"
    end

    def on_close
      puts "#{remote_addr}:#{remote_port} disconnected"
    end

    def on_read(data)
      write data
    end
  end

  server = Rev::TCPServer.new(HOST, PORT, EchoServerConnection)
  server.attach(Rev::Loop.default)

  puts "Echo server listening on #{HOST}:#{PORT}"
  Rev::Loop.default.run</code></pre>

Here a new observer type (EchoServerConnection) is made by subclassing an
existing one and adding new implementations to existing event handlers.

A new event loop is created, and a new Rev::TCPServer (whose base class is
Rev::Watcher) is created and attached to the event loop.<commit_msg>Try removing <code> in README I guess?<commit_after>h1. Rev

Rev is an event library for Ruby, built on the libev event library which 
provides a cross-platform interface to high performance system calls .  This 
includes the epoll system call for Linux, the kqueue system call for BSDs and 
OS X, and the completion ports interface for Solaris.

Rev also binds asynchronous wrappers to Ruby's core socket classes so you can
use them in conjunction with Rev to build asynchronous event-driven 
applications.

You can include Rev in your programs with:

 <pre>require 'rubygems'
 require 'rev'</pre>

For more information, consult the RubyForge page:

http://rev.rubyforge.org

http://rubyforge.org/projects/rev

Questions?  Sign up for the mailing list at:

http://rubyforge.org/mailman/listinfo/rev-talk

The latest development code is available via github at:

git://github.com/tarcieri/rev.git

h2. Anatomy

Rev builds on two core classes which bind to the libev API:

* Rev::Loop - This class represents an event loop which uses underlying high
  performance system calls to wait for events.

* Rev::Watcher - This is the base class for event observers.  Once you attach
  an event observer to a loop and start running it, you will begin receiving
  callbacks to particlar methods when events occur.

h2. Watchers

There are presently two types of watchers:

* Rev::IOWatcher - This class waits for an IO object to become readable,
  writable, or both.

* Rev::TimerWatcher - This class waits for a specified duration then fires
  an event.  You can also configure it to fire an event at specified intervals.

h2. Using Watchers

Watchers have five important methods:

* attach(loop) - This binds a watcher to the specified event loop.  If the
  watcher is already bound to a loop it will be detached first, then attached
  to the new one.

* detach - This completely unbinds a watcher from an event loop.

* disable - This stops the watcher from receiving events but does not unbind
  it from the loop.  If you are trying to toggle a watcher on and off, it's
  best to use this method (and enable) as it performs better than completely
  removing the watcher from the event loop.

* enable - This re-enables a watcher which has been disabled in the past.
  The watcher must still be bound to an event loop.

* evloop - This returns the Rev::Loop object which the watcher is currently
  bound to.

h2. Asynchronous Wrappers

Several classes which provide asynchronous event-driven wrappers for Ruby's
core socket classes are also provided.  Among these are:

* Rev::TCPSocket - A buffered wrapper to core Ruby's Socket class for use with
  TCP sockets.  You can asynchronously create outgoing TCP connections using 
  its Rev::TCPSocket.connect method.  Rev::TCPSocket provides write buffering
  to ensure that writing never blocks, and has asynchronous callbacks for
  several events, including when the connection is opened (or failed), when
  data is received, when the write buffer has been written out completely,
  and when the connection closes.

* Rev::TCPServer - A wrapper for TCPServer which creates new instances of
  Rev::TCPSocket (or any subclass you wish to provide) whenever an incoming
  connection is received.

* Rev::HttpClient - An HTTP/1.1 client with support for chunked encoding
  and streaming response processing through asynchronous callbacks.

h2. Example Program

Below is an example of how to write an echo server:

  <pre>require 'rev'
  HOST = 'localhost'
  PORT = 4321

  class EchoServerConnection < Rev::TCPSocket
    def on_connect
      puts "#{remote_addr}:#{remote_port} connected"
    end

    def on_close
      puts "#{remote_addr}:#{remote_port} disconnected"
    end

    def on_read(data)
      write data
    end
  end

  server = Rev::TCPServer.new(HOST, PORT, EchoServerConnection)
  server.attach(Rev::Loop.default)

  puts "Echo server listening on #{HOST}:#{PORT}"
  Rev::Loop.default.run</pre>

Here a new observer type (EchoServerConnection) is made by subclassing an
existing one and adding new implementations to existing event handlers.

A new event loop is created, and a new Rev::TCPServer (whose base class is
Rev::Watcher) is created and attached to the event loop.
{'fraction_non_alphanumeric': 0.055430800141827205, 'fraction_numerical': 0.0028365441437182364, 'mean_word_length': 3.963049853372434, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '566350', 'n_tokens_mistral': 2346, 'n_tokens_neox': 2257, 'n_words': 1169}