Module: EventMachine::RubySockets::TcpConnection
- Included in:
- TcpClient
- Defined in:
- lib/em-ruby-sockets/tcp_connection.rb
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns true if the socket has been closed or failed to connect.
-
#get_outbound_data_size ⇒ Object
Returns the number of bytes to be sent by the socket.
-
#io ⇒ Object
Access to the Ruby socket itself.
-
#local_address ⇒ Object
Returns an array of [ port, ip ] with the local address used for this socket.
-
#remote_address ⇒ Object
Returns an array of [ port, ip ] with the remote connected address.
-
#stream_file_data(filename, args = {}) ⇒ Object
(also: #send_file_data)
Streams the given filename through this connection.
Instance Method Details
#error? ⇒ Boolean
Returns true if the socket has been closed or failed to connect.
12 13 14 |
# File 'lib/em-ruby-sockets/tcp_connection.rb', line 12 def error? @error end |
#get_outbound_data_size ⇒ Object
Returns the number of bytes to be sent by the socket.
17 18 19 |
# File 'lib/em-ruby-sockets/tcp_connection.rb', line 17 def get_outbound_data_size @buffer.size end |
#io ⇒ Object
Access to the Ruby socket itself. A good place for socket settings is the post_init() method.
7 8 9 |
# File 'lib/em-ruby-sockets/tcp_connection.rb', line 7 def io @io end |
#local_address ⇒ Object
Returns an array of [ port, ip ] with the local address used for this socket. It returns nil in case the socket has been closed or failed to connect.
24 25 26 27 |
# File 'lib/em-ruby-sockets/tcp_connection.rb', line 24 def local_address return nil if @error ::Socket.unpack_sockaddr_in @io.getsockname end |
#remote_address ⇒ Object
Returns an array of [ port, ip ] with the remote connected address. It returns nil in case the socket is not connected.
31 32 33 34 |
# File 'lib/em-ruby-sockets/tcp_connection.rb', line 31 def remote_address return nil unless @connected ::Socket.unpack_sockaddr_in @io.getpeername end |
#stream_file_data(filename, args = {}) ⇒ Object Also known as: send_file_data
Streams the given filename through this connection. It does not set callback or errback. For a more powerful usage create a EventMachine::RubySockets::FileStreamer instance.
39 40 41 |
# File 'lib/em-ruby-sockets/tcp_connection.rb', line 39 def stream_file_data filename, args={} EM::RubySockets::FileStreamer.new(self, filename, args).run end |