From: "Iñaki Baz Castillo" <ibc@aliax.net>
To: ruby.posix.mq@librelist.com
Subject: POSIX_MQ and EventMachine integration
Date: Tue, 21 Dec 2010 12:00:58 +0100 [thread overview]
Message-ID: <AANLkTin-ThduWrGd8ANXO=Q1WKL_Hz2BeEhGSJ7WXUbH@mail.gmail.com> (raw)
In-Reply-To: <AANLkTin-ThduWrGd8ANXO=Q1WKL_Hz2BeEhGSJ7WXUbH@mail.gmail.com>
Hi, as POSIX_MQ provides #to_io method (IO selectable) it's possible
to integrate it within EventMachine. I paste a working code:
--------------------
require "posix_mq"
require "eventmachine"
module PosixMQ_EM
def initialize
@data = ""
end
def notify_readable
begin
MQ.receive @data
receive_message @data
rescue Errno::EAGAIN
$stderr.puts "ERROR: attemp to read from an empty queue"
end
end
def receive_message(msg)
puts "INFO: received msg: '#{msg}'"
end
end
EM.run do
MQ = POSIX_MQ.new "/some_mq, IO::RDONLY | IO::NONBLOCK
EM.watch(MQ.to_io, PosixMQ_EM) do |conn|
conn.notify_readable = true
end
end
--------------------
It seems to work correctly. Just a question: does the usage of #to_io
decrease performance? any suggestion to improve the above code?
Thanks a lot.
--
Iñaki Baz Castillo
<ibc@aliax.net>
next parent reply other threads:[~2010-12-21 11:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-21 11:00 Iñaki Baz Castillo [this message]
2010-12-22 19:36 ` POSIX_MQ and EventMachine integration Eric Wong
2010-12-23 0:51 ` Iñaki Baz Castillo
2010-12-23 3:52 ` Eric Wong
2010-12-23 15:35 ` Iñaki Baz Castillo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/ruby_posix_mq/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTin-ThduWrGd8ANXO=Q1WKL_Hz2BeEhGSJ7WXUbH@mail.gmail.com' \
--to=ibc@aliax.net \
--cc=ruby.posix.mq@librelist.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/ruby_posix_mq.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).