[#7872] Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...>

All, I needed a nonblocking socket connect for my asynchronous-event

18 messages 2006/05/14
[#7873] Re: Nonblocking socket-connect — Tanaka Akira <akr@...17n.org> 2006/05/14

In article <3a94cf510605140559l7baa0205le341dac4f47d424b@mail.gmail.com>,

[#7874] Re: Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...> 2006/05/15

How about introducing the method Socket#set_nonblocking, or alternatively

[#7875] Re: Nonblocking socket-connect — Yukihiro Matsumoto <matz@...> 2006/05/15

Hi,

[#7876] Re: Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...> 2006/05/15

Well, it's ok then. I'm comfortable adding in the nonblocking

[#7877] Re: Nonblocking socket-connect — Yukihiro Matsumoto <matz@...> 2006/05/15

Hi,

String#nstrip ?

From: "Daniel Berger" <Daniel.Berger@...>
Date: 2006-05-18 15:48:15 UTC
List: ruby-core #7901
Hi all,

When using the Win32API package, I often have to resort to this idiom to get a 
string out of a buffer:

string.split(0.chr).first

The problem is that it's kinda slow.  No, I can't use String#rstrip or 
String#gsub because often there's other junk at the end of the string that 
would prevent those methods from working.

What about adding a String#nstrip (null strip) method that would return a 
string up to the first NULL character?  Here's a simple implementation:

/* Returns the string up to and excluding the first NULL character */
static VALUE rb_str_nstrip(str){
    return rb_str_new2(RSTRING(str)->ptr);
}

This does emit a "cast to pointer from integer of different size" warning 
however, so perhaps there's a more appropriate approach.  Any, you get the 
general idea.

It's also about six times faster according to my benchmarks:

# nullbench.rb
require 'benchmark'

MAX = 100000
STRING = "hello\0\0\0\0"

Benchmark.bm do |x|
require 'benchmark'

MAX = 100000
STRING = "hello\0\0\0\0"

Benchmark.bm do |x|
    x.report("String#split"){
       MAX.times{ STRING.split("\0").first }
    }

    # Custom method
    x.report("String#nstrip"){
       MAX.times{ STRING.nstrip }
    }
end

djberge@~/programming/ruby-544>/opt/test/bin/ruby nullbench.rb
       user     system      total        real
String#split  3.470000   0.020000   3.490000 (  3.561128)
String#nstrip  0.550000   0.010000   0.560000 (  0.587311)

Useful? Or too specialized?

Thanks,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.


In This Thread

Prev Next