[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] socket_sendfile

Eric Hodel

3/24/2006 1:52:00 AM

= socket_sendfile

Rubyforge Project:

http://rubyforge.org/project...

Documentation:

http://dev.robotcoop.com/Libraries/socket...

== About

Socket#sendfile implements sendfile(2) for sending files without
copying data
to the process. See the sendfile(2) manual page for more details.

Note that your system must support the sendfile(2) system call the
same way
FreeBSD does for Socket#sendfile to work.

== Installing socket_sendfile

First you need an OS that supports sendfile() the way FreeBSD does.

Then install the gem:

$ sudo gem install socket_sendfile

== Using socket_sendfile

require 'rubygems'
require 'socket'
require 'socket_sendfile'

socket = TCPSocket.open host, port

File.open 'myfile' do |fp|
socket.sendfile fp
end

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...




12 Answers

Stephen Bannasch

3/24/2006 2:29:00 AM

0

[partially answering my own question ...]

The reason that builder can't create xml elements with "-" chars in
the element is because strings with "-" chars are not legal Ruby
symbols. Builder uses method_missing to create the xml element markup
and so it seems Ruby's parser chokes when it tries to convert the
string into a symbol.

I've got a workaround below but it is more general than I want (it
replaces all "_" chars with "-"). I left some code commented out that
I was trying too get working but didn't. It's a bit confusing to
debug because the inheritance chain (XmlMarkup < XmlBase <
BlankSlate) end up hiding all the normal methods -- I'm a bit
surprised that my code works at all.

Anyway, I'm just learning Ruby and figuring out just what is going on
here is fun. If anybody has suggestions I'd appreciate it.

Thanks

#!/usr/bin/env ruby
# file: jnlpmarkup.rb

# extends Builder::XmlMarkup for creating XML markup for jnlp documents.
# Some jnlp elements have a "-" char in the element name. Builder doesn't
# accept this character. So this class postprocesses the result and replaces
# proxy jnlp element names such as "<application_desc>" with
"<application-desc>"
#
# because I can't get what I intended to work right now this just
# replaces all "_" chars with '-' chars

require 'builder/xmlmarkup'

module Builder

class JnlpMarkup < XmlMarkup

@@jnlp_in = %w{application_desc applet_desc component_desc
installer_desc offline_allowed related_content all_permissions
j2ee_application_client_permissions ext_download}
@@jnlp_out = %w{application-desc applet-desc component-desc
installer-desc offline-allowed related-content all-permissions
j2ee-application-client-permissions ext-download}

def method_missing(sym, *args, &block)
super.gsub(/_/, '-')

# various things that didn't work below:
# x = super
# x = x.gsub(/application_desc/, 'application-desc')
# x = x.gsub(/applet_desc/, 'applet_desc')
# x = x.gsub(/#{@@jnlp_in[i]}/, @@jnlp_out[i])
# @@jnlp_in.each_index do |i| x = x.gsub(/#{@@jnlp_in[i]}/,
@@jnlp_out[i]) end
end
end
end



--
- Stephen Bannasch
Concord Consortium, http://www.c...


Ara.T.Howard

3/24/2006 3:24:00 AM

0

Eric Hodel

3/24/2006 6:59:00 AM

0


If that doesn't work try an fstat on the fd and set the count to
stat.st_size. Rumor has it that Linux might require an explicit count.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...


Eric Hodel

3/24/2006 8:43:00 AM

0

On Mar 23, 2006, at 7:24 PM, ara.t.howard@noaa.gov wrote:

> i'm just about to write a server which sends 1-3gb images as the
> response...
> this could be quite useful.
>
> one gripe. it doesn't work:
>
> /home/ahoward is insecure (40777), needs 0700 for perms. Exiting
>
> i work in a collaborative lab... all our home dirs are group
> readable by
> default.

Your home dir is group and world writable. A 755 directory works,
the message is broken. (Well, just fixed in perforce.)

> any way to adjust this? an env var perhaps?

The INLINEDIR environment variable controls this, so set it to a
directory that's got the right permissions (at least 755).

> seems like this should just warn.

Other people may be able to inject code into ~/.ruby_inline if the
directory is writeable by other people than you.

That would be Really Bad.

A warning is insufficient. You would be royally screwed by the time
you read it.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...




Ryan Davis

3/24/2006 8:50:00 AM

0


On Mar 23, 2006, at 7:24 PM, ara.t.howard@noaa.gov wrote:

> i'm just about to write a server which sends 1-3gb images as the
> response...
> this could be quite useful.
>
> one gripe. it doesn't work:
>
> /home/ahoward is insecure (40777), needs 0700 for perms. Exiting
>
> i work in a collaborative lab... all our home dirs are group
> readable by
> default. any way to adjust this? an env var perhaps? seems like
> this should
> just warn.

Your home dir is world and group writable, not just group readable.
There is a big big big difference between those two. There is no way
I'm going to let it just warn in that case. However, you do point out
that the error message poor. I've changed the error message to:

"#{path} is insecure (#{'%o' % mode}). It may not be group or
world writable. Exiting."

--
_why: zenspider's most intense moments of solice are immediately
following the slaughter [...]
_why: that topknot's the only thing keeping a lid on the righteous anger
bricolage: yeah, that and his flagrant obsession with dvorak




Ara.T.Howard

3/24/2006 2:52:00 PM

0

Ara.T.Howard

3/24/2006 3:04:00 PM

0

Ara.T.Howard

3/24/2006 5:12:00 PM

0

Toby DiPasquale

3/24/2006 5:19:00 PM

0

unknown wrote:
> On Sat, 25 Mar 2006, Toby DiPasquale wrote:
>
>>
>> Was there something wrong with my existing ruby-sendfile library?
>>
>> http://rubyforge.org/projects/rub...
>
> ahhhhhh.
>
> ;-)

Does that work for you, ara? It should work on Linux, Solaris and
FreeBSD out of the box. I didn't put it in a gem because I wasn't sure
how to get the GemSpec to correctly identify only the platforms on which
it would build. Let me know.

--
Toby DiPasquale


--
Posted via http://www.ruby-....


Ara.T.Howard

3/24/2006 5:39:00 PM

0