Sha256: 72344af7501adec74a765edba2f1174675bd392f23373ae63872e182869f9e2b

Contents?: true

Size: 667 Bytes

Versions: 19

Compression:

Stored size: 667 Bytes

Contents

require 'socket'
require 'Yk/__defun__'


class String
	def accept (&bl)
		if self =~ /:/
			args = [$`, $']
		else
			args = [self]
		end
		gs = TCPServer.open *args
		while true
			Thread.start(gs.accept) do |s|       # save to dynamic variable
				s.__defun__ :peer, "#{s.peeraddr[2]}:#{s.peeraddr[1]}"
				begin
					bl.call s
				ensure
					s.close
				end
			end
		end
	end
	def connect (sv = nil, &bl)
		if self =~ /:/
			host, service = $`, $'
		elsif sv
			host, service = self, sv
		else
			ArgumentError.new "cannot connect to #{self} : port not specified"
		end
		s = TCPSocket.open host, service
		begin
			yield s
		ensure
			s.close
		end
	end
end


Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
YkLib-0.1.8.9 lib/Yk/sock_aux.rb
YkLib-0.1.8.8 lib/Yk/sock_aux.rb
YkLib-0.1.8.7 lib/Yk/sock_aux.rb
YkLib-0.1.8.6 lib/Yk/sock_aux.rb
YkLib-0.1.8.5 lib/Yk/sock_aux.rb
YkLib-0.1.8.4 lib/Yk/sock_aux.rb
YkLib-0.1.8.3 lib/Yk/sock_aux.rb
YkLib-0.1.8.2 lib/Yk/sock_aux.rb
YkLib-0.1.8.1 lib/Yk/sock_aux.rb
YkLib-0.1.8 lib/Yk/sock_aux.rb
YkLib-0.1.7.1 lib/Yk/sock_aux.rb
YkLib-0.1.7 lib/Yk/sock_aux.rb
YkLib-0.1.6 lib/Yk/sock_aux.rb
YkLib-0.1.5 lib/Yk/sock_aux.rb
YkLib-0.1.4 lib/Yk/sock_aux.rb
YkLib-0.1.3 lib/Yk/sock_aux.rb
YkLib-0.1.2 lib/Yk/sock_aux.rb
YkLib-0.1.1 lib/Yk/sock_aux.rb
YkLib-0.1.0 lib/YkLib/Yk/sock_aux.rb