Created
March 2, 2011 10:08
-
-
Save elia/850728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SocketWithStats | |
attr_reader :read_bytes | |
def read *args | |
@read_bytes ||= 0.bytes | |
got = super | |
@read_bytes += args.first | |
return got | |
end | |
end | |
TCPSocket.open(host,port) do |socket| | |
socket.extend SocketWithStats | |
Thread.new { loop {puts socket.read_bytes} } | |
socket.gets | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment