Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
547 lines (331 sloc) 13.5 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Class: Accept</title>
<link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
<script src="./js/jquery.js" type="text/javascript"
charset="utf-8"></script>
<script src="./js/thickbox-compressed.js" type="text/javascript"
charset="utf-8"></script>
<script src="./js/quicksearch.js" type="text/javascript"
charset="utf-8"></script>
<script src="./js/darkfish.js" type="text/javascript"
charset="utf-8"></script>
</head>
<body class="class">
<div id="metadata">
<div id="home-metadata">
<div id="home-section" class="section">
<h3 class="section-header">
<a href="./index.html">Home</a>
<a href="./index.html#classes">Classes</a>
<a href="./index.html#methods">Methods</a>
</h3>
</div>
</div>
<div id="file-metadata">
<div id="file-list-section" class="section">
<h3 class="section-header">In Files</h3>
<div class="section-body">
<ul>
<li><a href="./spec/accept_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
class="thickbox" title="spec/accept.rb">spec/accept.rb</a></li>
</ul>
</div>
</div>
</div>
<div id="class-metadata">
<!-- Parent Class -->
<div id="parent-class-section" class="section">
<h3 class="section-header">Parent</h3>
<p class="link"><a href="Object.html">Object</a></p>
</div>
<!-- Namespace Contents -->
<!-- Method Quickref -->
<div id="method-list-section" class="section">
<h3 class="section-header">Methods</h3>
<ul class="link-list">
<li><a href="#method-c-new">::new</a></li>
<li><a href="#method-i-clear">#clear</a></li>
<li><a href="#method-i-close">#close</a></li>
<li><a href="#method-i-handle_input">#handle_input</a></li>
<li><a href="#method-i-input_history">#input_history</a></li>
<li><a href="#method-i-parse_input">#parse_input</a></li>
<li><a href="#method-i-wait">#wait</a></li>
</ul>
</div>
<!-- Included Modules -->
</div>
<div id="project-metadata">
<div id="fileindex-section" class="section project-section">
<h3 class="section-header">Files</h3>
<ul>
<li class="file"><a href="./Gemfile.html">Gemfile</a></li>
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
<li class="file"><a href="./Rakefile.html">Rakefile</a></li>
</ul>
</div>
<div id="classindex-section" class="section project-section">
<h3 class="section-header">Class/Module Index
<span class="search-toggle"><img src="./images/find.png"
height="16" width="16" alt="[+]"
title="show/hide quicksearch" /></span></h3>
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
<fieldset>
<legend>Quicksearch</legend>
<input type="text" name="quicksearch" value=""
class="quicksearch-field" />
</fieldset>
</form>
<ul class="link-list">
<li><a href="./KM.html">KM</a></li>
<li><a href="./KM/IdentError.html">KM::IdentError</a></li>
<li><a href="./KM/InitError.html">KM::InitError</a></li>
<li><a href="./KM/SaaS.html">KM::SaaS</a></li>
<li><a href="./Accept.html">Accept</a></li>
<li><a href="./Hash.html">Hash</a></li>
<li><a href="./Helper.html">Helper</a></li>
<li><a href="./KMError.html">KMError</a></li>
<li><a href="./Object.html">Object</a></li>
<li><a href="./String.html">String</a></li>
</ul>
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
</div>
</div>
</div>
<div id="documentation">
<h1 class="class">Accept</h1>
<div id="description">
<p>a library to accept connections as a server, and send back what it received
on request.</p>
</div>
<!-- Constants -->
<div id="constants-list" class="section">
<h3 class="section-header">Constants</h3>
<dl>
<dt><a name="URI_REXEGP">URI_REXEGP</a></dt>
<dd class="description"></dd>
</dl>
</div>
<!-- Attributes -->
<div id="attribute-method-details" class="method-section section">
<h3 class="section-header">Attributes</h3>
<div id="server-attribute-method" class="method-detail">
<a name="server"></a>
<a name="server="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">server</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
</div>
</div>
<div id="session-attribute-method" class="method-detail">
<a name="session"></a>
<a name="session="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">session</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
</div>
</div>
<div id="opts-attribute-method" class="method-detail">
<a name="opts"></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">opts</span><span
class="attribute-access-type">[R]</span>
</div>
<div class="method-description">
</div>
</div>
</div>
<!-- Methods -->
<div id="public-class-method-details" class="method-section section">
<h3 class="section-header">Public Class Methods</h3>
<div id="new-method" class="method-detail ">
<a name="method-c-new"></a>
<div class="method-heading">
<span class="method-name">new</span><span
class="method-args">(args = {})</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code"
id="new-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 14</span>
def initialize(args = {})
opts = { :port =&gt; 9292, :debug =&gt; false }
opts.update(args)
puts &quot;Starting up server on port #{opts[:port]} ...&quot;
<span class="ruby-ivar">@opts</span> = opts
<span class="ruby-ivar">@server</span> = <span class="ruby-constant">TCPServer</span>.new(opts[:port])
@@input_history = []
<span class="ruby-ivar">@handle</span> = <span class="ruby-constant">Thread</span>.start do
while (<span class="ruby-ivar">@session</span> = server.accept)
<span class="ruby-constant">Thread</span>.start do
<span class="ruby-comment"># puts &quot;log: Connection from #{session.peeraddr[2]} at #{session.peeraddr[3]}&quot;</span>
<span class="ruby-comment"># session.puts &quot;Server: Connection from #{session.peeraddr[2]}\n&quot;</span>
handle_input
session.close
end
end
end
end</pre>
</div>
</div>
</div>
</div>
<div id="public-instance-method-details" class="method-section section">
<h3 class="section-header">Public Instance Methods</h3>
<div id="clear-method" class="method-detail ">
<a name="method-i-clear"></a>
<div class="method-heading">
<span class="method-name">clear</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>clear history</p>
<div class="method-source-code"
id="clear-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 80</span>
def clear
@@input_history.clear
end</pre>
</div>
</div>
</div>
<div id="close-method" class="method-detail ">
<a name="method-i-close"></a>
<div class="method-heading">
<span class="method-name">close</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code"
id="close-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 75</span>
def close
session = nil
server.close
end</pre>
</div>
</div>
</div>
<div id="handle_input-method" class="method-detail ">
<a name="method-i-handle_input"></a>
<div class="method-heading">
<span class="method-name">handle_input</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code"
id="handle_input-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 40</span>
def handle_input
input = session.gets
if input
puts &quot;received: #{input.inspect}&quot; if opts[:debug]
case input
when <span class="ruby-regexp">/clear/</span>
clear
when <span class="ruby-regexp">/history/</span>
session.puts input_history.to_json
when <span class="ruby-regexp">/exit/</span>
begin
close
rescue <span class="ruby-constant">Exception</span>
end
return
when <span class="ruby-regexp">/^\s*(GET|POST|PUT|DELETE)\s+([^ ]*)\s+(.*)$/</span>
@@input_history &lt;&lt; parse_input(input)
else
@@input_history &lt;&lt; input.chomp
end
end
end</pre>
</div>
</div>
</div>
<div id="input_history-method" class="method-detail ">
<a name="method-i-input_history"></a>
<div class="method-heading">
<span class="method-name">input_history</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code"
id="input_history-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 33</span>
def input_history
@@input_history
end</pre>
</div>
</div>
</div>
<div id="parse_input-method" class="method-detail ">
<a name="method-i-parse_input"></a>
<div class="method-heading">
<span class="method-name">parse_input</span><span
class="method-args">(input)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code"
id="parse_input-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 62</span>
def parse_input(input)
data = {}
data[:raw] = input.chomp
(method,uri,http) = input.scan(<span class="ruby-regexp">/^\s*(\w+)\s+([^ ]*)\s+(.*)$/</span>).flatten
data[:method] = method
data[:http] = http.chomp
data[:uri] = uri
u = <span class="ruby-constant">URI</span>(uri)
data[:path] = u.path
data[:query] = <span class="ruby-constant">CGI</span>.parse(u.query)
return data
end</pre>
</div>
</div>
</div>
<div id="wait-method" class="method-detail ">
<a name="method-i-wait"></a>
<div class="method-heading">
<span class="method-name">wait</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code"
id="wait-source">
<pre>
<span class="ruby-comment"># File spec/accept.rb, line 36</span>
def wait
<span class="ruby-ivar">@handle</span>.join
end</pre>
</div>
</div>
</div>
</div>
</div>
<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
Rdoc Generator</a> 2</small>.</p>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.