[#4766] Wiki — "Glen Stampoultzis" <trinexus@...>

21 messages 2000/09/04
[#4768] RE: Wiki — "NAKAMURA, Hiroshi" <nahi@...> 2000/09/04

Hi, Glen,

[#4783] Re: Wiki — Masatoshi SEKI <m_seki@...> 2000/09/04

[#4785] Re: Wiki — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/09/05

Howdy,

[#4883] Re-binding a block — Dave Thomas <Dave@...>

16 messages 2000/09/12

[#4930] Perl 6 rumblings -- RFC 225 (v1) Data: Superpositions — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/09/15

[#4936] Ruby Book Eng. translation editor's questions — Jon Babcock <jon@...>

20 messages 2000/09/16

[#5045] Proposal: Add constants to Math — Robert Feldt <feldt@...>

15 messages 2000/09/21

[#5077] Crazy idea? infix method calls — hal9000@...

This is a generalization of the "in" operator idea which I

17 messages 2000/09/22

[#5157] Compile Problem with 1.6.1 — Scott Billings <aerogems@...>

When I try to compile Ruby 1.6.1, I get the following error:

15 messages 2000/09/27

[ruby-talk:5014] Re: Working server

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-09-19 19:05:16 UTC
List: ruby-talk #5014
> A> 3)
> A> For me the server for the above client does not work.
> 
>  It work for me

Thanks Guy for such a prompt response. It made me update my version of Ruby,
and brand new 1.6.0 seems to work well, just like you described.

I even managed to modify tsrv.rb not to leave any closed connections (at
least netstat won't display them as close anymore). The trick was to catch
exceptions caused byt the socket access, and then ensure TCPSocket#close was
called. Suddenly it became very clear that there was no "blocking" writes in
the first place (so forget my mail which started this thread), but those
raised exceptions, which just were not handled.

Anyway here's a patch for tsvr.rb which won't leave closed connections
behind, and is probably more robust anyway.

    - Aleksi

Index: tsvr.rb
===================================================================
RCS file: /home/cvs/ruby/sample/tsvr.rb,v
retrieving revision 1.2
diff -u -r1.2 tsvr.rb
--- tsvr.rb     2000/06/22 08:29:58     1.2
+++ tsvr.rb     2000/09/19 18:50:02
@@ -3,6 +3,8 @@
 
 require "socket"
 
+Thread.abort_on_exception=true
+
 gs = TCPserver.open(0)
 addr = gs.addr
 addr.shift
@@ -10,9 +12,17 @@
 
 while TRUE
   Thread.start(gs.accept) do |s|
-    print(s, " is accepted\n")
-    while s.gets
-      s.write($_)
+    print("\n", s, " ")
+    print(s.peeraddr[2], " ", s.peeraddr[3], " at port ", s.peeraddr[1])
+    print(" is accepted\n")
+    begin
+      while s.gets("\n")
+       print(s, " got #{$_.length}\n")
+       s.write($_)
+       print(s, " wrote back #{$_.length}\n")
+      end
+    rescue
+      print(s, " raised #$!\n")
     end
     print(s, " is gone\n")
     s.close



It's output might look like this:

#<TCPSocket:0x4017813c> localhost 127.0.0.1 at port 1458 is accepted
#<TCPSocket:0x4017813c> got 4
#<TCPSocket:0x4017813c> wrote back 4
#<TCPSocket:0x4017813c> got 4
#<TCPSocket:0x4017813c> wrote back 4
#<TCPSocket:0x4017813c> got 4
#<TCPSocket:0x4017813c> raised Broken pipe
#<TCPSocket:0x4017813c> is gone

#<TCPSocket:0x40177cf0> localhost 127.0.0.1 at port 1459 is accepted
#<TCPSocket:0x40177cf0> got 4
#<TCPSocket:0x40177cf0> wrote back 4
#<TCPSocket:0x40177cf0> got 4
#<TCPSocket:0x40177cf0> wrote back 4
#<TCPSocket:0x40177cf0> got 4
#<TCPSocket:0x40177cf0> raised Broken pipe
#<TCPSocket:0x40177cf0> is gone

In This Thread

Prev Next