[#306796] Hash#select returns an array but Hash#reject returns a hash... — "Srijayanth Sridhar" <srijayanth@...>

Hello,

21 messages 2008/07/01
[#306820] Re: Hash#select returns an array but Hash#reject returns a hash... — Dave Bass <davebass@...> 2008/07/01

Srijayanth Sridhar wrote:

[#306822] Re: Hash#select returns an array but Hash#reject returns a hash... — "Srijayanth Sridhar" <srijayanth@...> 2008/07/01

irb(main):001:0> a=Hash.new

[#306825] Re: Hash#select returns an array but Hash#reject returns a hash... — Pe, Botp <botp@...> 2008/07/01

From: Srijayanth Sridhar [mailto:srijayanth@gmail.com]=20

[#306835] Re: Hash#select returns an array but Hash#reject returns a hash... — "Srijayanth Sridhar" <srijayanth@...> 2008/07/01

>

[#306838] Re: Hash#select returns an array but Hash#reject returns a hash... — "David A. Black" <dblack@...> 2008/07/01

Hi --

[#306849] Re: Hash#select returns an array but Hash#reject returns a hash... — "Rick DeNatale" <rick.denatale@...> 2008/07/01

On Tue, Jul 1, 2008 at 8:48 AM, David A. Black <dblack@rubypal.com> wrote:

[#306809] Dynamic Variables — Marc Heiler <shevegen@...>

Is there any way in ruby to create dynamic variables?

13 messages 2008/07/01

[#306908] threadify-0.0.1 — ara howard <ara.t.howard@...>

19 messages 2008/07/01

[#306924] workarounds for ruby 1.8.6 segmentations faults — liquid_rails <cheri.anaclerio@...>

Hi,

12 messages 2008/07/01

[#307014] Ranges and Enumerable problems — "Glen Holcomb" <damnbigman@...>

Okay so when I play with "!".."~" wrong things happen.

24 messages 2008/07/02
[#307018] Re: Ranges and Enumerable problems — "Robert Klemme" <shortcutter@...> 2008/07/02

2008/7/2 Glen Holcomb <damnbigman@gmail.com>:

[#307021] Re: Ranges and Enumerable problems — "Glen Holcomb" <damnbigman@...> 2008/07/02

On Wed, Jul 2, 2008 at 9:12 AM, Robert Klemme <shortcutter@googlemail.com>

[#307030] Re: Ranges and Enumerable problems — "Adam Shelly" <adam.shelly@...> 2008/07/02

On 7/2/08, Glen Holcomb <damnbigman@gmail.com> wrote:

[#307035] Re: Ranges and Enumerable problems — "Robert Dober" <robert.dober@...> 2008/07/02

On Wed, Jul 2, 2008 at 7:13 PM, Adam Shelly <adam.shelly@gmail.com> wrote:

[#307037] Re: Ranges and Enumerable problems — "Adam Shelly" <adam.shelly@...> 2008/07/02

On 7/2/08, Robert Dober <robert.dober@gmail.com> wrote:

[#307042] Re: Ranges and Enumerable problems — Robert Klemme <shortcutter@...> 2008/07/02

On 02.07.2008 19:48, Adam Shelly wrote:

[#307050] Re: Ranges and Enumerable problems — "Rick DeNatale" <rick.denatale@...> 2008/07/02

On Wed, Jul 2, 2008 at 2:27 PM, Robert Klemme <shortcutter@googlemail.com>

[#307053] Re: Ranges and Enumerable problems — "Todd Benson" <caduceass@...> 2008/07/02

On Wed, Jul 2, 2008 at 3:50 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:

[#307070] Install/Enable openssl for ruby 1.8.6? — Jason Bornhoft <jbornhoft@...>

I was trying to install Redmine on rails 2.0.2 (this is not a rails

12 messages 2008/07/03

[#307080] thoughts on a more generic Array#partition function — "Rudi Cilibrasi" <cilibrar@...>

An experiment in a more generic partition function. The current

16 messages 2008/07/03
[#307083] Re: thoughts on a more generic Array#partition function — Pe, Botp <botp@...> 2008/07/03

From: Rudi Cilibrasi [mailto:cilibrar@gmail.com]=20

[#307088] Re: thoughts on a more generic Array#partition function — "Rudi Cilibrasi" <cilibrar@...> 2008/07/03

Hi Botp,

[#307095] Re: thoughts on a more generic Array#partition function — Pe, Botp <botp@...> 2008/07/03

From: Rudi Cilibrasi [mailto:cilibrar@gmail.com]=20

[#307136] Re: thoughts on a more generic Array#partition function — "Rick DeNatale" <rick.denatale@...> 2008/07/03

On Thu, Jul 3, 2008 at 12:53 AM, Pe=F1a, Botp <botp@delmonte-phil.com> wrot=

[#307101] Slide Show (S9) Gem Now Includes S5 Support (Including Built-In Gradient Themes) — "Gerald Bauer" <geraldbauer2007@...>

Hello,

21 messages 2008/07/03

[#307153] pseudo-randomize an array in a consistent order — Max Williams <toastkid.williams@...>

Does anyone know how to pseudo-randomize an array (eg with a seed) so

24 messages 2008/07/03

[#307246] Getting Folder Size — Clement Ow <clement.ow@...>

When I use File.size("C:/ruby"), all it returns is 0.

15 messages 2008/07/04

[#307284] from ruby/RoR to Java (framework unknown) :( — S2 <x@...>

My company today decided to ditch ruby development and to develop new web

35 messages 2008/07/04

[#307302] Does Ruby have any advantage over Python to create semantic applications? — Costan <CMValma@...>

Hi all,

10 messages 2008/07/04

[#307414] implementing a simple and efficient index system — Janus Bor <janus@...>

Hello everyone,

18 messages 2008/07/06
[#307415] Re: implementing a simple and efficient index system — phlip <phlip2005@...> 2008/07/06

Janus Bor wrote:

[#307585] Threads: Different behavior under Linux and Windows — Armin Armbruster <aarmbruster@...>

Hi,

13 messages 2008/07/08

[#307654] How to delete a file in Win XP — MAwiniarski <MAwiniarski@...>

Greetings,

18 messages 2008/07/09

[#307667] Thread-safe priority queue? — "Sean O'Halpin" <sean.ohalpin@...>

Hi,

13 messages 2008/07/09

[#307804] Why Ruby interpreter is writed in c (not in c++)? — "Ranieri Teixeira" <ranieri.tx@...>

Hi,

27 messages 2008/07/11
[#307807] Re: Why Ruby interpreter is writed in c (not in c++)? — phlip <phlip2005@...> 2008/07/11

Ranieri Teixeira wrote:

[#307853] Symbolify (#169) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

78 messages 2008/07/11
[#307863] Re: [QUIZ] Symbolify (#169) — "ara.t.howard" <ara.t.howard@...> 2008/07/11

[#307870] Re: [QUIZ] Symbolify (#169) — "Alex LeDonne" <aledonne.listmail@...> 2008/07/11

On Fri, Jul 11, 2008 at 12:12 PM, ara.t.howard <ara.t.howard@gmail.com> wrote:

[#307874] Re: [QUIZ] Symbolify (#169) — "ara.t.howard" <ara.t.howard@...> 2008/07/11

[#307879] Re: [QUIZ] Symbolify (#169) — Dana Merrick <dmerrick@...> 2008/07/11

ara.t.howard wrote:

[#307882] Re: [QUIZ] Symbolify (#169) — "ara.t.howard" <ara.t.howard@...> 2008/07/11

[#307883] Re: [QUIZ] Symbolify (#169) — James Gray <james@...> 2008/07/11

On Jul 11, 2008, at 12:16 PM, ara.t.howard wrote:

[#307933] can ruby replace bash scripts for linux script — "Greg Hauptmann" <greg.hauptmann.ruby@...>

hi,

14 messages 2008/07/12

[#307962] Can't install gems after a new ubuntu install — Max Williams <toastkid.williams@...>

Sorry if this is the wrong forum...

15 messages 2008/07/12

[#307973] regular expressions help — Vivek <krishna.vivek@...>

Hi,

17 messages 2008/07/12

[#308154] Text Editor — Jacob Grover <jacob.grover@...>

Hello, I've been wondering for a long time if there's an Internet text

14 messages 2008/07/14

[#308240] Is it possible to dynamically extend Test::Unit test cases? — "David Mitchell" <monch1962@...>

Hello list,

10 messages 2008/07/15

[#308264] Array.drop doesn't work — Li Chen <chen_li3@...>

Hi all,

14 messages 2008/07/15
[#308265] Re: Array.drop doesn't work — Frederick Cheung <frederick.cheung@...> 2008/07/15

[#308370] The next number that is not in an array — Tim Conner <crofty_james@...>

I want to increment the current value of a variable to the next number

28 messages 2008/07/16
[#308381] Re: The next number that is not in an array — "David A. Black" <dblack@...> 2008/07/16

Hi --

[#308409] So who's coming to RubyFringe? — Oliver Saunders <oliver.saunders@...>

...I am! Hope you meet some of you guys over here.

11 messages 2008/07/17

[#308509] Records and Arrays (#170) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

13 messages 2008/07/18

[#308525] Multiple GEM repositories — Rob Mauchel <rmauchel@...>

I have a Ruby script which runs fine on my own machine that I'd like to

14 messages 2008/07/18

[#308642] Does "rescue" wihtour argument handle any kind of Exception or not? — Iñaki Baz Castillo <ibc@...>

Hi, I read in this article:

17 messages 2008/07/20
[#308643] Re: Does "rescue" wihtour argument handle any kind of Exception or not? — Stefano Crocco <stefano.crocco@...> 2008/07/20

On Sunday 20 July 2008, I=C3=B1aki Baz Castillo wrote:

[#308645] Re: Does "rescue" wihtour argument handle any kind of Exception or not? — Phlip <phlip2005@...> 2008/07/20

Stefano Crocco wrote:

[#308698] rdoc 2.1.0 Released — Eric Hodel <drbrain@...7.net>

rdoc version 2.1.0 has been released!

25 messages 2008/07/21
[#308723] Re: [ANN] rdoc 2.1.0 Released — Joel VanderWerf <vjoel@...> 2008/07/21

Eric Hodel wrote:

[#308750] Re: [ANN] rdoc 2.1.0 Released — Marcin Raczkowski <mailing.mr@...> 2008/07/21

I started playing with new release and frameless template doesn't work.

[#308759] Re: [ANN] rdoc 2.1.0 Released — Eric Hodel <drbrain@...7.net> 2008/07/22

On Jul 21, 2008, at 14:05 PM, Marcin Raczkowski wrote:

[#308790] Re: [ANN] rdoc 2.1.0 Released — Marcin Raczkowski <mailing.mr@...> 2008/07/22

Eric Hodel wrote:

[#308853] Re: [ANN] rdoc 2.1.0 Released — Eric Hodel <drbrain@...7.net> 2008/07/22

[#308699] protected members or explicit abstract classes? — aidy <aidy.lewis@...>

Hi,

12 messages 2008/07/21

[#308736] read CSV file using csv library — Li Chen <chen_li3@...>

Hi all,

19 messages 2008/07/21
[#308774] Re: read CSV file using csv library — "kranthi reddy" <kranthicu@...> 2008/07/22

Hey you can use faster csv instead using the standard csv ruby library.

[#308817] Re: read CSV file using csv library — Li Chen <chen_li3@...> 2008/07/22

kranthi reddy wrote:

[#308821] Re: read CSV file using csv library — "kranthi reddy" <kranthicu@...> 2008/07/22

Hi,

[#347910] Re: read CSV file using csv library — Frank Guerino <frank.guerino@...> 2009/10/07

kranthi reddy wrote:

[#347914] Re: read CSV file using csv library — Marvin Gülker <sutniuq@...> 2009/10/07

Frank Guerino wrote:

[#308761] bj and rails 2.1 - can't get bj to run jobs — dusty <dusty.doris@...>

I have been trying to setup bj with rails 2.1.0 and am having some

13 messages 2008/07/22

[#308831] simple module for "count my instances" behaviour — Julien Thewys <jt@...>

I want to make a simple module that makes its including classes

11 messages 2008/07/22

[#308847] how to capitalize a number of characters in a word — Cheyne Li <happy.go.lucky.clr@...>

Hi, there

13 messages 2008/07/22

[#308884] Is there a simple way to find a method definition? — Ruby Freak <twscannell@...>

Hi,

12 messages 2008/07/23

[#308909] circular 'require' — Shadowfirebird <shadowfirebird@...>

Hi,

29 messages 2008/07/23
[#308911] Re: circular 'require' — Stefano Crocco <stefano.crocco@...> 2008/07/23

On Wednesday 23 July 2008, Shadowfirebird wrote:

[#308919] Re: circular 'require' — Calamitas <calamitates@...> 2008/07/23

On Wed, Jul 23, 2008 at 12:18 PM, Stefano Crocco

[#308935] Re: circular 'require' — "Michael T. Richter" <ttmrichter@...> 2008/07/23

On Wed, 2008-07-23 at 20:39 +0900, Calamitas wrote:

[#308940] Re: circular 'require' — Shadowfirebird <shadowfirebird@...> 2008/07/23

I found a very easy way around it. This is what bothers me. If it's

[#308943] Re: circular 'require' — "Michael T. Richter" <ttmrichter@...> 2008/07/23

On Wed, 2008-07-23 at 22:48 +0900, Shadowfirebird wrote:

[#308944] Re: circular 'require' — Shadowfirebird <shadowfirebird@...> 2008/07/23

Yes, I can see now that in your example no order of loading will allow

[#308951] Of GUIs threads and scheduling woes — "Glen Holcomb" <damnbigman@...>

I have a small GUI app that I have written the purposes for it's creation

12 messages 2008/07/23

[#309006] differnce between .nil? , .empty?, .blank? — Sijo Kg <sijo@...>

Hi

11 messages 2008/07/24

[#309074] Simultaneously URL call, is it possible? — Toki Toki <toki84@...>

Hi to all!

22 messages 2008/07/24
[#309080] Re: Simultaneously URL call, is it possible? — matu <m@...> 2008/07/24

Toki Toki wrote:

[#309083] Re: Simultaneously URL call, is it possible? — Toki Toki <toki84@...> 2008/07/24

matu wrote:

[#309089] inline comments in future release? — Mike Schwab <mike.schwab@...>

Are inline comments a potential feature of Ruby 2.0?

25 messages 2008/07/24
[#309101] Re: inline comments in future release? — Tim Hunter <TimHunter@...> 2008/07/24

Mike Schwab wrote:

[#309111] Re: inline comments in future release? — Mike Schwab <mike.schwab@...> 2008/07/25

> If you have so much code on one line that you feel the need for inline

[#309112] Re: inline comments in future release? — "Michael W. Ryder" <_mwryder@...> 2008/07/25

Mike Schwab wrote:

[#309113] Re: inline comments in future release? — Peña, Botp <botp@...> 2008/07/25

RnJvbTogTWljaGFlbCBXLiBSeWRlciBbbWFpbHRvOl9td3J5ZGVyQHdvcmxkbmV0LmF0dC5uZXRd

[#309165] weird backsplash behaviour inside single quotes — "Michal Suchanek" <hramrach@...>

Hello

13 messages 2008/07/25
[#309170] Re: weird backsplash behaviour inside single quotes — "Todd Benson" <caduceass@...> 2008/07/25

On Fri, Jul 25, 2008 at 8:34 AM, Michal Suchanek <hramrach@centrum.cz> wrote:

[#309171] Re: weird backsplash behaviour inside single quotes — "Todd Benson" <caduceass@...> 2008/07/25

On Fri, Jul 25, 2008 at 9:33 AM, Todd Benson <caduceass@gmail.com> wrote:

[#309173] Interesting Array Initialization Typo — Maciej Tomaka <lunatyq@...>

When initializing for example : [ [1, 2], [2, 3], [3, 2] ]

12 messages 2008/07/25

[#309194] hexdump (#171) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

13 messages 2008/07/25

[#309273] Faster Marshaling? — Greg Willits <lists@...>

Exploring options... wondering if there's anything that can replace

13 messages 2008/07/27

[#309278] deaf grandma. — Houston Barnett-gearhart <americanpragmatic@...>

i picked up ruby 2 days ago & have been bustlin' chris pine's "learn to

25 messages 2008/07/27
[#309282] Re: deaf grandma. — "Martin DeMello" <martindemello@...> 2008/07/27

On Sat, Jul 26, 2008 at 8:31 PM, Houston Barnett-gearhart

[#309322] Re: deaf grandma. — houston barnett-gearhart <americanpragmatic@...> 2008/07/27

thank you, martin, for your reply. i took your advice & wrote an

[#309341] Re: deaf grandma. — "Martin DeMello" <martindemello@...> 2008/07/28

On Sun, Jul 27, 2008 at 2:32 PM, houston barnett-gearhart

[#309343] Re: deaf grandma. — houston barnett-gearhart <americanpragmatic@...> 2008/07/28

Martin, is there any way I can get in touch with you outside of the

[#309391] Re: deaf grandma. — "Martin DeMello" <martindemello@...> 2008/07/28

On Sun, Jul 27, 2008 at 11:51 PM, houston barnett-gearhart

[#309407] Re: deaf grandma. — houston barnett-gearhart <americanpragmatic@...> 2008/07/28

I don't know why this is so hard for me to get my head around, but

[#309387] Win32ole equivalent for Mac OS X — Nathan Loyer <4namlet@...>

Is there an equivalent library for the Win32ole library on the PC? I

12 messages 2008/07/28

[#309441] Concurrent Ruby? — Kyle Murphy <kmurph79@...>

Apologies if this is a really stupid question, I am new to programming,

14 messages 2008/07/29

[#309442] and and or in case — Pe, Botp <botp@...>

Hi All, apologies in advanced if this has been discussed already

12 messages 2008/07/29

[#309472] libxml: is it possible not to use doctype declaration? — "ruud grosmann" <r.grosmann@...>

hi all,

17 messages 2008/07/29
[#309477] Re: libxml: is it possible not to use doctype declaration? — Phlip <phlip2005@...> 2008/07/29

ruud grosmann wrote:

[#309478] Re: libxml: is it possible not to use doctype declaration? — "ruud grosmann" <r.grosmann@...> 2008/07/29

hi Phlip,

[#309488] Re: libxml: is it possible not to use doctype declaration? — Phlip <phlip2005@...> 2008/07/29

ruud grosmann wrote:

[#309572] Re: How to do methodsoverloading in — Jeff Moore <jcmoore@...>

Sunny Bogawat wrote:

12 messages 2008/07/30

[#309589] Suggestions for improving a trivial tag parser — "Gregory Brown" <gregory.t.brown@...>

Hi folks,

11 messages 2008/07/30
[#309593] Re: Suggestions for improving a trivial tag parser — "Robert Dober" <robert.dober@...> 2008/07/30

What about

[#309627] gc doesn't collect? — Roger Pack <rogerpack2005@...>

Any ideas why:

13 messages 2008/07/31

[#309646] super with block — Lou Zell <lzell11@...>

Hi all,

17 messages 2008/07/31
[#309647] Re: super with block — "Jes俍 Gabriel y Gal疣" <jgabrielygalan@...> 2008/07/31

On Thu, Jul 31, 2008 at 11:06 AM, Lou Zell <lzell11@gmail.com> wrote:

[#309692] Re: super with block — Lou Zell <lzell11@...> 2008/07/31

> Hi,

[#309650] Help me with this Numerology code please... — Web Reservoir <webreservoir@...>

Hi,

18 messages 2008/07/31

[#309653] Cool Projects — Alasdair Bell <alasdair@...>

So, anyone working on something awesome?

31 messages 2008/07/31

[#309676] How to get special directories? — Niklas Baumstark <niklas.baumstark@...>

hi all,

18 messages 2008/07/31

[#309739] RubyGems - update made a mess - help needed with Windows — Becca Girl <cschall@...>

I just did a system update of RubyGems and it just broke my rake test. I

16 messages 2008/07/31

[ANN] Packet - 0.1.7, Ruby Library for EventDriven Network programming

From: hemant <gethemant@...>
Date: 2008-07-13 14:39:06 UTC
List: ruby-talk #308038
Hi,

I am proud to release 0.1.7 version of Packet.

Packet is a pure ruby library for writing network applications in Ruby.
It follows Evented Model of network programming and implements almost all the
features provided by EventMachine.

It also provides real easy to user UNIX workers for concurrent programming.

Changes since 0.1.5:

* Uses fork and exec, rather than just fork.
* Fixed bugs with large packet transfer.
* Improved performance
* Tons of other fixes.



Its best to have some examples going:

== Examples
=== A Simple Echo Server:
require "rubygems"
require "packet"

class Foo
  def receive_data p_data
    send_data(p_data)
  end

  def post_init
    puts "Client connected"
  end

  def connection_completed
    puts "Whoa man"
  end

  def unbind
    puts "Client Disconnected"
  end
end

Packet::Reactor.run do |t_reactor|
  t_reactor.start_server("localhost",11006,Foo)
end

Those new to network programming with events and callbacks, will note that,
each time a new client connects an instance of class Foo is instantiated.
When client writes some data to the socket, receive_data method is invoked.

Although Packet implements an API similar to EventMachine, but it differs
slightly because of the fact that, for a packet app, there can be more than one
reactor loop running and hence, we don't use Packet.start_server(...).

=== A Simple Http Client
class WikiHandler
  def receive_data p_data
    p p_data
  end

  def post_init
  end

  def unbind
  end

  def connection_completed
    send_data("GET / \r\n")
  end
end

Packet::Reactor.run do |t_reactor|
  t_reactor.connect("en.wikipedia.org",80,WikiHandler)
end

=== Using Callbacks and Deferables
 Documentation to come.

=== Using Workers
  Packet enables you to write simple workers, which will run in
  different process and gives you nice
  evented handle for concurrent execution of various tasks.

  When, you are writing a scalable networking application
  using Event Model of network programming,
  sometimes when processing of certain events take time,
  your event loop is stuck there. With green
  threads, you don't really have a way of paralleling
  your request processing. Packet library, allows
  you to write simple workers, for executing long
  running tasks. You can pass data and callbacks as an
  argument.

  When you are going to use workers in
  your application, you need to define
  constant WORKER_ROOT,
  which is the directory location, where
  your workers are located. All the workers defined in that directory
  will be automatically, picked and forked in a
  new process when your packet app starts. So, a typical
  packet_app, that wants to use workers, will look like this:

  packet_app_root
    |
    |__  lib
    |
    |___ worker
    |
    |___ config
    |
    |___ log

  You would define WORKER_ROOT = PACKET_APP_ROOT/worker

  All the workers must inherit class Packet::Worker, and hence a
  general skeleton of worker will look like:

    class FooWorker < Packet::Worker
      set_worker_name :foo_worker #=> This is necessary.
      def receive_data p_data
      end

      def connection_completed
      end

      def unbind
      end

      def post_init
      end
    end

  All the forked workers are connected to master via
  UNIX sockets, and hence messages passed to workers from master
  will be available in receive_data method. Also,
  when you are passing messages to workers, or worker is passing
  message to master ( in a nutshell, all the internal
  communication between workers and master ) directly takes
  place using ruby objects. All the passed ruby objects are
  dumped and marshalled across unix sockets in a non blocking
  manner. BinParser class parses dumped binary objects and
  makes sure, packets received at other end are complete.
  Usually, you wouldn't need to worry about this little detail.

  Packet provides various ways of interacting with
  workers. Usually, when a worker is instantiated, a proxy for
  that worker will also be instantiated at master
  process. Packet automatically provides a worker proxy(See meta_pimp.rb)
  for you, but  if you need to multiplex/demultiplex
  requests based on certain criteria, you may as well define your
  own worker proxies. Code, would like something like this:

    class FooWorker < Packet::Worker
      set_worker_proxy :foo_handler
    end

  When you define, :foo_handler as a proxy for
  this worker, packet is gonna search for FooHandler class and
  instantiate it when the worker gets started. All
  the worker proxies must inherit from Packet::Pimp.
  Have a look at, Packet::MetaPimp,
  which acts as a meta pimp for all the workers,
  which don't have a explicit worker proxy defined.

=== A complete Case :

    Just for kicks, lets write a sample server,
    which evals whatever clients send to it. But, assuming this 'eval' of
    client data can be potentially time/cpu
    consuming ( not to mention dangerous too ), we are gonna ask our
eval_worker, to
    perform eval and return the result to master process, which in
    turn returns the result to happy client.

    # APP_ROOT/bin/eval_server.rb
    EVAL_APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__) + "/.."))
    ["bin","worker","lib"].each { |x| $LOAD_PATH.unshift(EVAL_APP_ROOT
+ "/#{x}")}
    WORKER_ROOT = EVAL_APP_ROOT + "/worker"

    require "packet"
    class EvalServer
      def receive_data p_data
        ask_worker(:eval_worker,:data => p_data, :type => :request)
      end

      # will be called, when any worker sends data back to master process
      # it should be noted that, you may have several instances of
eval_server in
      # your master, for each connected client, but worker_receive
will be always
      # be invoked for the instance, which originally made the request.
      # If you need fine control, over this behaviour, you can
implement a worker proxy
      # on the lines of meta_pimp class. This API will change in
future perhaps, as i
      # expect, better ideas to come.
      def worker_receive p_data
        send_data "#{p_data[:data]}\n"
      end

      def show_result p_data
        send_data("#{p_data[:response]}\n")
      end

      def connection_completed
      end

      def post_init
      end

      def wow
        puts "Wow"
      end
    end

    Packet::Reactor.run do |t_reactor|
      t_reactor.start_server("localhost", 11006,EvalServer) do |instance|
        instance.wow
      end
    end

   # APP_ROOT/worker/eval_worker.rb
     class EvalWorker < Packet::Worker
     set_worker_name :eval_worker
     def worker_init
       p "Starting no proxy worker"
     end

     def receive_data data_obj
       eval_data = eval(data_obj[:data])
       data_obj[:data] = eval_data
       data_obj[:type] = :response
       send_data(data_obj)
     end
   end

=== Disable auto loading of certain workers:
  Sometimes, you would need to start a
  worker at runtime and don't want this pre-forking mechanism.
  Packet, allows this. You just need to define
  "set_no_auto_load true" in your worker class and worker
  will not be automatically forked. Although name is a bit misleading perhaps.

  Now, at runtime, you can call start_worker(:foo_worker, options)
  to start a worker as usual. It should
  be noted that, forking a worker, which is already
  forked can be disastrous, since worker names are being
  used as unique keys that represent a worker.

== Code repo:
   http://github.com/gnufied/packet/tree/master


== Credits
  Francis for awesome EventMachine lib, which has constantly acted as
an inspiration.
  Ezra, for being a early user and porting mongrel to run on top of packet





-- 
Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org

In This Thread

Prev Next