Class: Vertx::NetSocket

Inherits:
Object
  • Object
show all
Includes:
ReadStream, WriteStream
Defined in:
src/main/ruby_scripts/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_queue_full?, #write_queue_max_size=

Instance Method Details

- (Object) close

Close the socket


180
181
182
# File 'src/main/ruby_scripts/core/net.rb', line 180

def close
  @j_del.close
end

- (Object) closed_handler(proc = nil, &hndlr)

Set a closed handler on the socket.

Parameters:

  • proc (Proc) (defaults to: nil)
    A proc to be used as the handler
  • hndlr (Block)
    A block to be used as the handler


167
168
169
170
# File 'src/main/ruby_scripts/core/net.rb', line 167

def closed_handler(proc = nil, &hndlr)
  hndlr = proc if proc
  @closed_handler = hndlr
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.


175
176
177
# File 'src/main/ruby_scripts/core/net.rb', line 175

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

- (Object) write_buffer(buff, &compl)

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

Parameters:

  • buff. (Buffer)
    The buffer to write.
  • compl. (Block)
    The handler to call on completion.


143
144
145
146
147
148
149
150
# File 'src/main/ruby_scripts/core/net.rb', line 143

def write_buffer(buff, &compl)
  j_buff = buff._to_java_buffer
  if compl == nil
    @j_del.write(j_buff)
  else
    @j_del.write(j_buff, compl)
  end
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.


188
189
190
# File 'src/main/ruby_scripts/core/net.rb', line 188

def write_handler_id
  @write_handler_id
end

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

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.
  • compl. (Block)
    The handler to call on completion.


156
157
158
159
160
161
162
# File 'src/main/ruby_scripts/core/net.rb', line 156

def write_str(str, enc = "UTF-8", &compl)
  if (compl == nil)
    @j_del.write(str, enc)
  else
    @j_del.write(str, enc, compl)
  end
end