Skip to content

Commit

Permalink
added debug_puts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbalbert committed Apr 17, 2012
1 parent e5eb10b commit 1434ff4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/eventless.rb
Expand Up @@ -9,6 +9,7 @@
require 'eventless/event' require 'eventless/event'
require 'eventless/threadpool' require 'eventless/threadpool'
require 'eventless/core_ext/string' require 'eventless/core_ext/string'
require 'eventless/util'


module Kernel module Kernel
alias_method :sleep_block, :sleep alias_method :sleep_block, :sleep
Expand Down
2 changes: 1 addition & 1 deletion lib/eventless/resolver/cares.rb
Expand Up @@ -133,7 +133,7 @@ def self.getaddress(hostname)
class Socket < BasicSocket class Socket < BasicSocket
class << self class << self
def pack_sockaddr_in(port, host) def pack_sockaddr_in(port, host)
STDERR.puts "Sockaddr.pack_sockaddr_in" debug_puts "Sockaddr.pack_sockaddr_in"


ip = IPAddress.parse(IPSocket.getaddress(host)) ip = IPAddress.parse(IPSocket.getaddress(host))
family = ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET family = ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET
Expand Down
2 changes: 1 addition & 1 deletion lib/eventless/resolver/threadpool.rb
Expand Up @@ -25,7 +25,7 @@ def self.getaddress(hostname)
class Socket < BasicSocket class Socket < BasicSocket
class << self class << self
def pack_sockaddr_in(port, host) def pack_sockaddr_in(port, host)
STDERR.puts "Sockaddr.pack_sockaddr_in" debug_puts "Sockaddr.pack_sockaddr_in"


ip = IPAddress.parse(IPSocket.getaddress(host)) ip = IPAddress.parse(IPSocket.getaddress(host))
family = ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET family = ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET
Expand Down
4 changes: 2 additions & 2 deletions lib/eventless/select.rb
Expand Up @@ -25,8 +25,8 @@ def self.select(read_array, write_array=[], error_array=[], timeout=nil)


timeout = Timeout.new(timeout).start timeout = Timeout.new(timeout).start


#STDERR.puts "about to select", read_array.inspect, write_array.inspect #debug_puts "about to select", read_array.inspect, write_array.inspect
STDERR.puts "select" debug_puts "select"


begin begin
read_array.each do |io| read_array.each do |io|
Expand Down
32 changes: 16 additions & 16 deletions lib/eventless/socket.rb
Expand Up @@ -96,7 +96,7 @@ def initialize(fd, *rest)
############## ##############
# Sending data # Sending data
def syswrite(*args) def syswrite(*args)
STDERR.puts "syswrite" debug_puts "syswrite"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
result = @socket.write_nonblock(*args) result = @socket.write_nonblock(*args)
Expand All @@ -111,7 +111,7 @@ def syswrite(*args)
end end


def write(str) def write(str)
STDERR.puts "write" debug_puts "write"


str = str.to_s str = str.to_s
written = 0 written = 0
Expand All @@ -125,7 +125,7 @@ def write(str)
end end


def sendmsg(*args) def sendmsg(*args)
STDERR.puts "sendmsg" debug_puts "sendmsg"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
result = @socket.sendmsg_nonblock(*args) result = @socket.sendmsg_nonblock(*args)
Expand Down Expand Up @@ -161,7 +161,7 @@ def putc(arg)
end end


def puts(*args) def puts(*args)
STDERR.puts "puts" debug_puts "puts"


if args.empty? if args.empty?
write("\n") write("\n")
Expand All @@ -186,7 +186,7 @@ def puts(*args)
BUFFER_LENGTH = 128*1024 BUFFER_LENGTH = 128*1024


def sysread(*args) def sysread(*args)
STDERR.puts "sysread" debug_puts "sysread"
buffer = "" buffer = ""
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
Expand All @@ -204,7 +204,7 @@ def sysread(*args)
def readpartial(length, buffer=nil) def readpartial(length, buffer=nil)
length = length.to_int length = length.to_int
raise ArgumentError if length < 0 raise ArgumentError if length < 0
STDERR.puts "readpartial" debug_puts "readpartial"


buffer.clear if buffer buffer.clear if buffer
buffer = "" if buffer.nil? buffer = "" if buffer.nil?
Expand All @@ -222,7 +222,7 @@ def readpartial(length, buffer=nil)


def read(length=nil, buffer=nil) def read(length=nil, buffer=nil)
raise ArgumentError if !length.nil? && length < 0 raise ArgumentError if !length.nil? && length < 0
STDERR.puts "read" unless length == 1 debug_puts "read" unless length == 1


return "" if length == 0 return "" if length == 0
buffer.clear if buffer buffer.clear if buffer
Expand Down Expand Up @@ -276,7 +276,7 @@ def getc
end end


def gets(sep=$/, limit=nil) def gets(sep=$/, limit=nil)
STDERR.puts "gets" debug_puts "gets"


if sep.kind_of? Numeric and limit.nil? if sep.kind_of? Numeric and limit.nil?
limit = sep limit = sep
Expand All @@ -301,7 +301,7 @@ def gets(sep=$/, limit=nil)
end end


def recv(*args) def recv(*args)
STDERR.puts "recv" debug_puts "recv"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
mesg = @socket.recv_nonblock(*args) mesg = @socket.recv_nonblock(*args)
Expand All @@ -316,7 +316,7 @@ def recv(*args)
end end


def recvmsg(*args) def recvmsg(*args)
STDERR.puts "recvmsg" debug_puts "recvmsg"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
msg = @socket.recvmsg_nonblock(*args) msg = @socket.recvmsg_nonblock(*args)
Expand All @@ -339,25 +339,25 @@ def remote_address


# connect is private so we can call it from both Socket and TCPSocket # connect is private so we can call it from both Socket and TCPSocket
def connect(*args) def connect(*args)
STDERR.puts "connect" debug_puts "connect"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
@socket.connect_nonblock(*args) @socket.connect_nonblock(*args)
@socket.fcntl(Fcntl::F_SETFL, flags) @socket.fcntl(Fcntl::F_SETFL, flags)
rescue IO::WaitWritable rescue IO::WaitWritable
@socket.fcntl(Fcntl::F_SETFL, flags) @socket.fcntl(Fcntl::F_SETFL, flags)
#STDERR.puts "connect: about to sleep" #debug_puts "connect: about to sleep"
wait(Eventless.loop.io(:write, self)) wait(Eventless.loop.io(:write, self))
retry retry
rescue Errno::EISCONN rescue Errno::EISCONN
@socket.fcntl(Fcntl::F_SETFL, flags) @socket.fcntl(Fcntl::F_SETFL, flags)
end end
#STDERR.puts "Connected!" #debug_puts "Connected!"
end end


# accept is private so we can call it from both Socket and TCPServer # accept is private so we can call it from both Socket and TCPServer
def accept def accept
STDERR.puts "accept" debug_puts "accept"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
real_socket, real_addrinfo = @socket.accept_nonblock real_socket, real_addrinfo = @socket.accept_nonblock
Expand All @@ -375,7 +375,7 @@ def accept
end end


def bind(addr) def bind(addr)
STDERR.puts "bind" debug_puts "bind"


# bind() can also take an Addrinfo, but it does a strict type check # bind() can also take an Addrinfo, but it does a strict type check
# before converting. Because Eventless::Addrinfo isn't an Addrinfo, we # before converting. Because Eventless::Addrinfo isn't an Addrinfo, we
Expand Down Expand Up @@ -461,7 +461,7 @@ def bind(*args)
end end


def recvfrom(*args) def recvfrom(*args)
STDERR.puts "recvfrom" debug_puts "recvfrom"
begin begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0) flags = @socket.fcntl(Fcntl::F_GETFL, 0)
pair = @socket.recvfrom_nonblock(*args) pair = @socket.recvfrom_nonblock(*args)
Expand Down
7 changes: 7 additions & 0 deletions lib/eventless/util.rb
@@ -0,0 +1,7 @@
if ENV['DEBUG']
def debug_puts(*args)
STDERR.puts(*args)
end
else
def debug_puts(*args); end
end

0 comments on commit 1434ff4

Please sign in to comment.