Class: Vertx::NetSocket

Inherits:
Object
  • Object
show all
Includes:
ReadStream, WriteStream
Defined in:
src/main/api_shim/core/net.rb

Overview

NetSocket is a socket-like abstraction used for reading from or writing to TCP connections.

Author:

Instance Method Summary (collapse)

Methods included from ReadStream

#data_handler, #end_handler, #exception_handler, #pause, #resume

Methods included from WriteStream

#drain_handler, #exception_handler, #write, #write_queue_full?, #write_queue_max_size, #write_queue_max_size=

Instance Method Details

- (Object) close

Close the socket


205
206
207
# File 'src/main/api_shim/core/net.rb', line 205

def close
  @j_del.close
end

- (Object) close_handler(&hndlr)

Set a closed handler on the socket.

Parameters:

  • hndlr (Block)
    A block to be used as the handler


191
192
193
194
# File 'src/main/api_shim/core/net.rb', line 191

def close_handler(&hndlr)
  @close_handler = hndlr
  self
end

- (Object) local_address

Return the Addrinfo to which the local end of the socket is bound


227
228
229
230
231
232
# File 'src/main/api_shim/core/net.rb', line 227

def local_address
  if !@local_addr
    @local_addr = Addrinfo.tcp(@j_del.localAddress().getAddress().getHostAddress(), @j_del.localAddress().getPort())
  end
  @local_addr
end

- (Object) remote_address

Return the Addrinfo to which the remote end of the socket is bound


218
219
220
221
222
223
# File 'src/main/api_shim/core/net.rb', line 218

def remote_address
  if !@remote_addr
    @remote_addr = Addrinfo.tcp(@j_del.remoteAddress().getAddress().getHostAddress(), @j_del.remoteAddress().getPort())
  end
  @remote_addr
end

- (Object) send_file(file_path)

Tell the kernel to stream a file directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters:

  • file_path. (String)
    Path to file to send.


199
200
201
202
# File 'src/main/api_shim/core/net.rb', line 199

def send_file(file_path)
  @j_del.sendFile(file_path)
  self
end

- (Object) write_handler_id

When a NetSocket is created it automatically registers an event handler with the system. The address of that handler is given by #write_handler_id. Given this ID, a different event loop can send a buffer to that event handler using the event bus. This allows you to write data to other connections which are owned by different event loops.


213
214
215
# File 'src/main/api_shim/core/net.rb', line 213

def write_handler_id
  @write_handler_id
end

- (Object) write_str(str, enc = "UTF-8")

Write a String to the socket. The handler will be called when the string has actually been written to the wire.

Parameters:

  • str. (String)
    The string to write.
  • enc. (String)
    The encoding to use.


184
185
186
187
# File 'src/main/api_shim/core/net.rb', line 184

def write_str(str, enc = "UTF-8")
  @j_del.write(str, enc)
  self
end