Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added debug_puts

  • Loading branch information...
commit 1434ff4635256c500bdb04cdd10538416472160a 1 parent e5eb10b
@davidbalbert authored
View
1  lib/eventless.rb
@@ -9,6 +9,7 @@
require 'eventless/event'
require 'eventless/threadpool'
require 'eventless/core_ext/string'
+require 'eventless/util'
module Kernel
alias_method :sleep_block, :sleep
View
2  lib/eventless/resolver/cares.rb
@@ -133,7 +133,7 @@ def self.getaddress(hostname)
class Socket < BasicSocket
class << self
def pack_sockaddr_in(port, host)
- STDERR.puts "Sockaddr.pack_sockaddr_in"
+ debug_puts "Sockaddr.pack_sockaddr_in"
ip = IPAddress.parse(IPSocket.getaddress(host))
family = ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET
View
2  lib/eventless/resolver/threadpool.rb
@@ -25,7 +25,7 @@ def self.getaddress(hostname)
class Socket < BasicSocket
class << self
def pack_sockaddr_in(port, host)
- STDERR.puts "Sockaddr.pack_sockaddr_in"
+ debug_puts "Sockaddr.pack_sockaddr_in"
ip = IPAddress.parse(IPSocket.getaddress(host))
family = ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET
View
4 lib/eventless/select.rb
@@ -25,8 +25,8 @@ def self.select(read_array, write_array=[], error_array=[], timeout=nil)
timeout = Timeout.new(timeout).start
- #STDERR.puts "about to select", read_array.inspect, write_array.inspect
- STDERR.puts "select"
+ #debug_puts "about to select", read_array.inspect, write_array.inspect
+ debug_puts "select"
begin
read_array.each do |io|
View
32 lib/eventless/socket.rb
@@ -96,7 +96,7 @@ def initialize(fd, *rest)
##############
# Sending data
def syswrite(*args)
- STDERR.puts "syswrite"
+ debug_puts "syswrite"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
result = @socket.write_nonblock(*args)
@@ -111,7 +111,7 @@ def syswrite(*args)
end
def write(str)
- STDERR.puts "write"
+ debug_puts "write"
str = str.to_s
written = 0
@@ -125,7 +125,7 @@ def write(str)
end
def sendmsg(*args)
- STDERR.puts "sendmsg"
+ debug_puts "sendmsg"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
result = @socket.sendmsg_nonblock(*args)
@@ -161,7 +161,7 @@ def putc(arg)
end
def puts(*args)
- STDERR.puts "puts"
+ debug_puts "puts"
if args.empty?
write("\n")
@@ -186,7 +186,7 @@ def puts(*args)
BUFFER_LENGTH = 128*1024
def sysread(*args)
- STDERR.puts "sysread"
+ debug_puts "sysread"
buffer = ""
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
@@ -204,7 +204,7 @@ def sysread(*args)
def readpartial(length, buffer=nil)
length = length.to_int
raise ArgumentError if length < 0
- STDERR.puts "readpartial"
+ debug_puts "readpartial"
buffer.clear if buffer
buffer = "" if buffer.nil?
@@ -222,7 +222,7 @@ def readpartial(length, buffer=nil)
def read(length=nil, buffer=nil)
raise ArgumentError if !length.nil? && length < 0
- STDERR.puts "read" unless length == 1
+ debug_puts "read" unless length == 1
return "" if length == 0
buffer.clear if buffer
@@ -276,7 +276,7 @@ def getc
end
def gets(sep=$/, limit=nil)
- STDERR.puts "gets"
+ debug_puts "gets"
if sep.kind_of? Numeric and limit.nil?
limit = sep
@@ -301,7 +301,7 @@ def gets(sep=$/, limit=nil)
end
def recv(*args)
- STDERR.puts "recv"
+ debug_puts "recv"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
mesg = @socket.recv_nonblock(*args)
@@ -316,7 +316,7 @@ def recv(*args)
end
def recvmsg(*args)
- STDERR.puts "recvmsg"
+ debug_puts "recvmsg"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
msg = @socket.recvmsg_nonblock(*args)
@@ -339,25 +339,25 @@ def remote_address
# connect is private so we can call it from both Socket and TCPSocket
def connect(*args)
- STDERR.puts "connect"
+ debug_puts "connect"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
@socket.connect_nonblock(*args)
@socket.fcntl(Fcntl::F_SETFL, flags)
rescue IO::WaitWritable
@socket.fcntl(Fcntl::F_SETFL, flags)
- #STDERR.puts "connect: about to sleep"
+ #debug_puts "connect: about to sleep"
wait(Eventless.loop.io(:write, self))
retry
rescue Errno::EISCONN
@socket.fcntl(Fcntl::F_SETFL, flags)
end
- #STDERR.puts "Connected!"
+ #debug_puts "Connected!"
end
# accept is private so we can call it from both Socket and TCPServer
def accept
- STDERR.puts "accept"
+ debug_puts "accept"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
real_socket, real_addrinfo = @socket.accept_nonblock
@@ -375,7 +375,7 @@ def accept
end
def bind(addr)
- STDERR.puts "bind"
+ debug_puts "bind"
# bind() can also take an Addrinfo, but it does a strict type check
# before converting. Because Eventless::Addrinfo isn't an Addrinfo, we
@@ -461,7 +461,7 @@ def bind(*args)
end
def recvfrom(*args)
- STDERR.puts "recvfrom"
+ debug_puts "recvfrom"
begin
flags = @socket.fcntl(Fcntl::F_GETFL, 0)
pair = @socket.recvfrom_nonblock(*args)
View
7 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.
Something went wrong with that request. Please try again.