Class: UV::TcpConnection

Inherits:
Connection show all
Defined in:
lib/uv-rays/connection.rb

Direct Known Subclasses

InboundConnection, OutboundConnection

Instance Attribute Summary

Attributes inherited from Connection

#using_tls

Instance Method Summary collapse

Methods inherited from Connection

#initialize, #on_read, #pause, #paused?, #post_init, #resume

Constructor Details

This class inherits a constructor from UV::Connection

Instance Method Details

#close_connection(after_writing = false) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/uv-rays/connection.rb', line 73

def close_connection(after_writing = false)
    if after_writing
        @transport.shutdown
    else
        @transport.close
    end
end

#keepalive(raw_time) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/uv-rays/connection.rb', line 90

def keepalive(raw_time)
    time = raw_time.to_i
    if time.to_i <= 0
        @transport.disable_keepalive
    else
        @transport.enable_keepalive(time)
    end
end

#on_closeObject

user to define



102
103
# File 'lib/uv-rays/connection.rb', line 102

def on_close # user to define
end

#on_connect(transport) ⇒ Object

user to define



99
100
# File 'lib/uv-rays/connection.rb', line 99

def on_connect(transport) # user to define
end

#stream_file(filename, type = :raw) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/uv-rays/connection.rb', line 81

def stream_file(filename, type = :raw)
    file = @reactor.file(filename, File::RDONLY) do    # File is open and available for reading
        file.send_file(@transport, type, wait: :promise).finally do
            file.close
        end
    end
    return file
end

#write(data) ⇒ Object



69
70
71
# File 'lib/uv-rays/connection.rb', line 69

def write(data)
    @transport.write(data, wait: :promise)
end