ionian 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/Ionian/Extension/IO.html +48 -13
- data/doc/Ionian/Extension/Socket.html +6 -7
- data/doc/Ionian/Extension.html +6 -7
- data/doc/Ionian/Server.html +389 -0
- data/doc/Ionian/Socket.html +221 -55
- data/doc/Ionian.html +6 -7
- data/doc/created.rid +5 -4
- data/doc/index.html +8 -7
- data/doc/js/search.js +8 -1
- data/doc/js/search_index.js +1 -1
- data/doc/rdoc.css +9 -3
- data/doc/table_of_contents.html +55 -7
- data/lib/ionian/extension/io.rb +7 -1
- data/lib/ionian/server.rb +85 -0
- data/lib/ionian/socket.rb +80 -22
- data/lib/ionian.rb +1 -0
- metadata +52 -50
data/doc/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["ionian","extension","io","socket","socket","<<()","closed?()","cmd()","cork()","cork=()","cork?()","expression()","expression=()","extended()","extended()","flush()","has_data?()","has_data?()","initialize_ionian()","initialize_ionian_socket()","ip_add_membership()","ip_drop_membership()","ip_multicast_if()","ip_multicast_if=()","ip_multicast_loop()","ip_multicast_loop=()","ip_multicast_loop?()","ip_multicast_ttl()","ip_multicast_ttl=()","ipv6_add_membership()","ipv6_drop_membership()","ipv6_multicast_hops()","ipv6_multicast_hops=()","ipv6_multicast_if()","ipv6_multicast_if=()","ipv6_multicast_loop()","ipv6_multicast_loop=()","ipv6_multicast_loop?()","multicast()","multicast?()","new()","no_delay()","no_delay=()","no_delay?()","on_match()","persistent?()","protocol?()","purge()","puts()","read_match()","recork()","register_observer()","reuse_addr()","reuse_addr=()","reuse_addr?()","run_match()","ttl()","ttl=()","ttl?()","unregister_observer()","write()"],"longSearchIndex":["ionian","ionian::extension","ionian::extension::io","ionian::extension::socket","ionian::socket","ionian::socket#<<()","ionian::socket#closed?()","ionian::socket#cmd()","ionian::extension::socket#cork()","ionian::extension::socket#cork=()","ionian::extension::socket#cork?()","ionian::extension::io#expression()","ionian::extension::io#expression=()","ionian::extension::io::extended()","ionian::extension::socket::extended()","ionian::socket#flush()","ionian::extension::io#has_data?()","ionian::socket#has_data?()","ionian::extension::io#initialize_ionian()","ionian::extension::socket#initialize_ionian_socket()","ionian::extension::socket#ip_add_membership()","ionian::extension::socket#ip_drop_membership()","ionian::extension::socket#ip_multicast_if()","ionian::extension::socket#ip_multicast_if=()","ionian::extension::socket#ip_multicast_loop()","ionian::extension::socket#ip_multicast_loop=()","ionian::extension::socket#ip_multicast_loop?()","ionian::extension::socket#ip_multicast_ttl()","ionian::extension::socket#ip_multicast_ttl=()","ionian::extension::socket#ipv6_add_membership()","ionian::extension::socket#ipv6_drop_membership()","ionian::extension::socket#ipv6_multicast_hops()","ionian::extension::socket#ipv6_multicast_hops=()","ionian::extension::socket#ipv6_multicast_if()","ionian::extension::socket#ipv6_multicast_if=()","ionian::extension::socket#ipv6_multicast_loop()","ionian::extension::socket#ipv6_multicast_loop=()","ionian::extension::socket#ipv6_multicast_loop?()","ionian::extension::socket#multicast()","ionian::extension::socket#multicast?()","ionian::socket::new()","ionian::extension::socket#no_delay()","ionian::extension::socket#no_delay=()","ionian::extension::socket#no_delay?()","ionian::extension::io#on_match()","ionian::socket#persistent?()","ionian::socket#protocol?()","ionian::extension::io#purge()","ionian::socket#puts()","ionian::extension::io#read_match()","ionian::extension::socket#recork()","ionian::extension::io#register_observer()","ionian::extension::socket#reuse_addr()","ionian::extension::socket#reuse_addr=()","ionian::extension::socket#reuse_addr?()","ionian::extension::io#run_match()","ionian::extension::socket#ttl()","ionian::extension::socket#ttl=()","ionian::extension::socket#ttl?()","ionian::extension::io#unregister_observer()","ionian::socket#write()"],"info":[["Ionian","","Ionian.html","","<p>A library to simplify interaction with IO streams. This includes network\nsockets, file sockets, and serial …\n"],["Ionian::Extension","","Ionian/Extension.html","","<p>A collection of mixins.\n"],["Ionian::Extension::IO","","Ionian/Extension/IO.html","","<p>A mixin for IO objects that allows regular expression matching and\nconvenient notification of received …\n"],["Ionian::Extension::Socket","","Ionian/Extension/Socket.html","","<p>A mixin for Socket objects.\n<p>This module was designed to be extended by instantiated objects that\nimplement …\n"],["Ionian::Socket","","Ionian/Socket.html","","<p>A convenient wrapper for TCP, UDP, and Unix sockets.\n"],["<<","Ionian::Socket","Ionian/Socket.html#method-i-3C-3C","(string)",""],["closed?","Ionian::Socket","Ionian/Socket.html#method-i-closed-3F","()","<p>Returns true if the socket is closed.\n"],["cmd","Ionian::Socket","Ionian/Socket.html#method-i-cmd","(string, **kwargs, &block)","<p>Send a command (data) to the socket. Returns an array of received matches.\nBlock yields received match. …\n"],["cork","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-cork","()","<p>Returns true if multiple writes are buffered into a single segment. See\n#recork. Linux only. ( TCP_CORK …\n"],["cork=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-cork-3D","(value)","<p>Buffers multiple writes into a single segment if true. The segment is sent\nonce the cork flag is disabled, …\n"],["cork?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-cork-3F","()",""],["expression","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-expression","()","<p>Returns the regular expression used for #read_match.\n"],["expression=","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-expression-3D","(exp)","<p>Set the expression to match against the read buffer. Can be a regular\nexpression specifying capture groups, …\n"],["extended","Ionian::Extension::IO","Ionian/Extension/IO.html#method-c-extended","(obj)","<p>Called automaticallly when the object is extended with #extend.\n"],["extended","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-c-extended","(obj)","<p>Called automaticallly when the object is extended with #extend.\n"],["flush","Ionian::Socket","Ionian/Socket.html#method-i-flush","()","<p>Flushes buffered data to the operating system. This method has no effect on\nnon-persistent sockets.\n"],["has_data?","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-has_data-3F","(timeout: 0)","<p>Returns true if there is data in the receive buffer. Args:\n\n<pre>Timeout: Number of seconds to wait for data ...</pre>\n"],["has_data?","Ionian::Socket","Ionian/Socket.html#method-i-has_data-3F","(**kwargs)","<p>Returns true if there is data in the receive buffer. Args:\n\n<pre>Timeout: Number of seconds to wait for data ...</pre>\n"],["initialize_ionian","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-initialize_ionian","()","<p>Initialize the Ionian instance variables. This is called automatically if\n#extend is called on an object. …\n"],["initialize_ionian_socket","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-initialize_ionian_socket","()","<p>Initialize the Ionian Socket variables. This is called automatically if\n#extend is called on an object. …\n"],["ip_add_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_add_membership","(address = nil, interface = nil)","<p>Join a multicast group. Address is the class D multicast address (uses\nremote address if not specified). …\n"],["ip_drop_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_drop_membership","(address = nil, interface = nil)","<p>Leave a multicast group. Address is the class D multicast address (uses\nremote address if not specified). …\n"],["ip_multicast_if","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_if","()","<p>Returns the default interface for outgoing multicasts. ( IP_MULTICAST_IF )\n"],["ip_multicast_if=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_if-3D","(interface = nil)","<p>Specify default interface for outgoing multicasts. ( IP_MULTICAST_IF )\n"],["ip_multicast_loop","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_loop","()","<p>Returns true if loopback of outgoing multicasts is enabled. (\nIP_MULTICAST_LOOP )\n"],["ip_multicast_loop=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_loop-3D","(value)","<p>Enables loopback of outgoing multicasts if true. ( IP_MULTICAST_LOOP )\n"],["ip_multicast_loop?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_loop-3F","()",""],["ip_multicast_ttl","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_ttl","()","<p>Returns the time to live (hop limit) for outgoing multicasts. (\nIP_MULTICAST_TTL )\n"],["ip_multicast_ttl=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_ttl-3D","(value)","<p>Set the time to live (hop limit) for outgoing multicasts. (\nIP_MULTICAST_TTL )\n"],["ipv6_add_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_add_membership","()",""],["ipv6_drop_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_drop_membership","()",""],["ipv6_multicast_hops","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_hops","()",""],["ipv6_multicast_hops=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_hops-3D","(value)",""],["ipv6_multicast_if","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_if","()",""],["ipv6_multicast_if=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_if-3D","(value)",""],["ipv6_multicast_loop","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_loop","()",""],["ipv6_multicast_loop=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_loop-3D","(value)",""],["ipv6_multicast_loop?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_loop-3F","()",""],["multicast","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-multicast","(address)","<p>Returns true if the given address is within the multicast range.\n"],["multicast?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-multicast-3F","(address)",""],["new","Ionian::Socket","Ionian/Socket.html#method-c-new","(**kwargs)","<p>Args:\n\n<pre>host: IP or hostname to connect to.\nport: Connection's port number. Default is 23. Unused ...</pre>\n"],["no_delay","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-no_delay","()","<p>Returns true if the Nagle algorithm is disabled. ( TCP_NODELAY )\n"],["no_delay=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-no_delay-3D","(value)","<p>Disables the Nagle algorithm if true. ( TCP_NODELAY )\n"],["no_delay?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-no_delay-3F","()",""],["on_match","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-on_match","(&block)",""],["persistent?","Ionian::Socket","Ionian/Socket.html#method-i-persistent-3F","()","<p>Returns true if the socket remains open after writing data.\n"],["protocol?","Ionian::Socket","Ionian/Socket.html#method-i-protocol-3F","()","<p>Returns a symbol of the type of protocol this socket uses: :tcp, :udp,\n:unix\n"],["purge","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-purge","()","<p>Erase the data in the IO and Ionian buffers. This is typically handled\nautomatically.\n"],["puts","Ionian::Socket","Ionian/Socket.html#method-i-puts","(*string)","<p>Writes the given string(s) to the socket and appends a newline character to\nany string not already ending …\n"],["read_match","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-read_match","(**kwargs, &block)","<p>Read matched data from the buffer. This method SHOULD NOT be used if\n#run_match is used.\n<p>Passes matches …\n"],["recork","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-recork","()","<p>Unsets cork to transmit data, then reapplies cork. ( TCP_CORK )\n"],["register_observer","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-register_observer","(&block)","<p>Register a block to be called when #run_match receives matched data. Method\ncallbacks can be registered …\n"],["reuse_addr","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-reuse_addr","()","<p>Returns true if local address reuse is allowed. ( SO_REUSEADDR )\n"],["reuse_addr=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-reuse_addr-3D","(value)","<p>Allows local address reuse if true. ( SO_REUSEADDR )\n"],["reuse_addr?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-reuse_addr-3F","()",""],["run_match","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-run_match","(**kwargs)","<p>Start a thread that checks for data and notifies listeners (do |match,\nsocket|). Passes kwargs to #read_match …\n"],["ttl","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ttl","()","<p>Returns the time to live (hop limit). ( IP_TTL )\n"],["ttl=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ttl-3D","(value)","<p>Sets the time to live (hop limit). ( IP_TTL )\n"],["ttl?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ttl-3F","()",""],["unregister_observer","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-unregister_observer","(&block)","<p>Unregister a block from being called when matched data is received.\n"],["write","Ionian::Socket","Ionian/Socket.html#method-i-write","(string)","<p>Writes the given string to the socket. Returns the number of bytes written.\n"]]}}
|
1
|
+
var search_data = {"index":{"searchIndex":["ionian","extension","io","socket","server","socket","<<()","close()","closed?()","cmd()","cork()","cork=()","cork?()","expression()","expression=()","extended()","extended()","flush()","has_data?()","has_data?()","initialize_ionian()","initialize_ionian_socket()","ip_add_membership()","ip_drop_membership()","ip_multicast_if()","ip_multicast_if=()","ip_multicast_loop()","ip_multicast_loop=()","ip_multicast_loop?()","ip_multicast_ttl()","ip_multicast_ttl=()","ipv6_add_membership()","ipv6_drop_membership()","ipv6_multicast_hops()","ipv6_multicast_hops=()","ipv6_multicast_if()","ipv6_multicast_if=()","ipv6_multicast_loop()","ipv6_multicast_loop=()","ipv6_multicast_loop?()","listen()","multicast()","multicast?()","new()","new()","no_delay()","no_delay=()","no_delay?()","on_accept()","on_match()","on_match()","persistent?()","purge()","puts()","read_all()","read_match()","recork()","register_accept_listener()","register_observer()","register_observer()","reuse_addr()","reuse_addr=()","reuse_addr?()","run_match()","ttl()","ttl=()","ttl?()","unregister_accept_listener()","unregister_observer()","unregister_observer()","write()"],"longSearchIndex":["ionian","ionian::extension","ionian::extension::io","ionian::extension::socket","ionian::server","ionian::socket","ionian::socket#<<()","ionian::server#close()","ionian::socket#closed?()","ionian::socket#cmd()","ionian::extension::socket#cork()","ionian::extension::socket#cork=()","ionian::extension::socket#cork?()","ionian::extension::io#expression()","ionian::extension::io#expression=()","ionian::extension::io::extended()","ionian::extension::socket::extended()","ionian::socket#flush()","ionian::extension::io#has_data?()","ionian::socket#has_data?()","ionian::extension::io#initialize_ionian()","ionian::extension::socket#initialize_ionian_socket()","ionian::extension::socket#ip_add_membership()","ionian::extension::socket#ip_drop_membership()","ionian::extension::socket#ip_multicast_if()","ionian::extension::socket#ip_multicast_if=()","ionian::extension::socket#ip_multicast_loop()","ionian::extension::socket#ip_multicast_loop=()","ionian::extension::socket#ip_multicast_loop?()","ionian::extension::socket#ip_multicast_ttl()","ionian::extension::socket#ip_multicast_ttl=()","ionian::extension::socket#ipv6_add_membership()","ionian::extension::socket#ipv6_drop_membership()","ionian::extension::socket#ipv6_multicast_hops()","ionian::extension::socket#ipv6_multicast_hops=()","ionian::extension::socket#ipv6_multicast_if()","ionian::extension::socket#ipv6_multicast_if=()","ionian::extension::socket#ipv6_multicast_loop()","ionian::extension::socket#ipv6_multicast_loop=()","ionian::extension::socket#ipv6_multicast_loop?()","ionian::server#listen()","ionian::extension::socket#multicast()","ionian::extension::socket#multicast?()","ionian::server::new()","ionian::socket::new()","ionian::extension::socket#no_delay()","ionian::extension::socket#no_delay=()","ionian::extension::socket#no_delay?()","ionian::server#on_accept()","ionian::extension::io#on_match()","ionian::socket#on_match()","ionian::socket#persistent?()","ionian::extension::io#purge()","ionian::socket#puts()","ionian::extension::io#read_all()","ionian::extension::io#read_match()","ionian::extension::socket#recork()","ionian::server#register_accept_listener()","ionian::extension::io#register_observer()","ionian::socket#register_observer()","ionian::extension::socket#reuse_addr()","ionian::extension::socket#reuse_addr=()","ionian::extension::socket#reuse_addr?()","ionian::extension::io#run_match()","ionian::extension::socket#ttl()","ionian::extension::socket#ttl=()","ionian::extension::socket#ttl?()","ionian::server#unregister_accept_listener()","ionian::extension::io#unregister_observer()","ionian::socket#unregister_observer()","ionian::socket#write()"],"info":[["Ionian","","Ionian.html","","<p>A library to simplify interaction with IO streams. This includes network\nsockets, file sockets, and serial …\n"],["Ionian::Extension","","Ionian/Extension.html","","<p>A collection of mixins.\n"],["Ionian::Extension::IO","","Ionian/Extension/IO.html","","<p>A mixin for IO objects that allows regular expression matching and\nconvenient notification of received …\n"],["Ionian::Extension::Socket","","Ionian/Extension/Socket.html","","<p>A mixin for Socket objects.\n<p>This module was designed to be extended by instantiated objects that\nimplement …\n"],["Ionian::Server","","Ionian/Server.html","","<p>A convenient wrapper for TCP, UDP, and Unix server sockets.\n"],["Ionian::Socket","","Ionian/Socket.html","","<p>A convenient wrapper for TCP, UDP, and Unix client sockets.\n"],["<<","Ionian::Socket","Ionian/Socket.html#method-i-3C-3C","(string)",""],["close","Ionian::Server","Ionian/Server.html#method-i-close","()","<p>Shutdown the server socket and stop listening for connections.\n"],["closed?","Ionian::Socket","Ionian/Socket.html#method-i-closed-3F","()","<p>Returns true if the socket is closed.\n"],["cmd","Ionian::Socket","Ionian/Socket.html#method-i-cmd","(string, **kwargs, &block)","<p>Send a command (data) to the socket. Returns an array of received matches.\nBlock yields received match. …\n"],["cork","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-cork","()","<p>Returns true if multiple writes are buffered into a single segment. See\n#recork. Linux only. ( TCP_CORK …\n"],["cork=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-cork-3D","(value)","<p>Buffers multiple writes into a single segment if true. The segment is sent\nonce the cork flag is disabled, …\n"],["cork?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-cork-3F","()",""],["expression","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-expression","()","<p>Returns the regular expression used for #read_match.\n"],["expression=","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-expression-3D","(exp)","<p>Set the expression to match against the read buffer. Can be a regular\nexpression specifying capture groups, …\n"],["extended","Ionian::Extension::IO","Ionian/Extension/IO.html#method-c-extended","(obj)","<p>Called automaticallly when the object is extended with #extend.\n"],["extended","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-c-extended","(obj)","<p>Called automaticallly when the object is extended with #extend.\n"],["flush","Ionian::Socket","Ionian/Socket.html#method-i-flush","()","<p>Flushes buffered data to the operating system. This method has no effect on\nnon-persistent sockets.\n"],["has_data?","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-has_data-3F","(timeout: 0)","<p>Returns true if there is data in the receive buffer. Args:\n\n<pre>Timeout: Number of seconds to wait for data ...</pre>\n"],["has_data?","Ionian::Socket","Ionian/Socket.html#method-i-has_data-3F","(**kwargs)","<p>Returns true if there is data in the receive buffer. Args:\n\n<pre>Timeout: Number of seconds to wait for data ...</pre>\n"],["initialize_ionian","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-initialize_ionian","()","<p>Initialize the Ionian instance variables. This is called automatically if\n#extend is called on an object. …\n"],["initialize_ionian_socket","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-initialize_ionian_socket","()","<p>Initialize the Ionian Socket variables. This is called automatically if\n#extend is called on an object. …\n"],["ip_add_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_add_membership","(address = nil, interface = nil)","<p>Join a multicast group. Address is the class D multicast address (uses\nremote address if not specified). …\n"],["ip_drop_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_drop_membership","(address = nil, interface = nil)","<p>Leave a multicast group. Address is the class D multicast address (uses\nremote address if not specified). …\n"],["ip_multicast_if","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_if","()","<p>Returns the default interface for outgoing multicasts. ( IP_MULTICAST_IF )\n"],["ip_multicast_if=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_if-3D","(interface = nil)","<p>Specify default interface for outgoing multicasts. ( IP_MULTICAST_IF )\n"],["ip_multicast_loop","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_loop","()","<p>Returns true if loopback of outgoing multicasts is enabled. (\nIP_MULTICAST_LOOP )\n"],["ip_multicast_loop=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_loop-3D","(value)","<p>Enables loopback of outgoing multicasts if true. ( IP_MULTICAST_LOOP )\n"],["ip_multicast_loop?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_loop-3F","()",""],["ip_multicast_ttl","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_ttl","()","<p>Returns the time to live (hop limit) for outgoing multicasts. (\nIP_MULTICAST_TTL )\n"],["ip_multicast_ttl=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ip_multicast_ttl-3D","(value)","<p>Set the time to live (hop limit) for outgoing multicasts. (\nIP_MULTICAST_TTL )\n"],["ipv6_add_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_add_membership","()",""],["ipv6_drop_membership","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_drop_membership","()",""],["ipv6_multicast_hops","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_hops","()",""],["ipv6_multicast_hops=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_hops-3D","(value)",""],["ipv6_multicast_if","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_if","()",""],["ipv6_multicast_if=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_if-3D","(value)",""],["ipv6_multicast_loop","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_loop","()",""],["ipv6_multicast_loop=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_loop-3D","(value)",""],["ipv6_multicast_loop?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ipv6_multicast_loop-3F","()",""],["listen","Ionian::Server","Ionian/Server.html#method-i-listen","(&block)","<p>Starts the socket server listening for connections. Blocks registered with\n#register_accept_listener …\n"],["multicast","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-multicast","(address)","<p>Returns true if the given address is within the multicast range.\n"],["multicast?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-multicast-3F","(address)",""],["new","Ionian::Server","Ionian/Server.html#method-c-new","(**kwargs, &block)",""],["new","Ionian::Socket","Ionian/Socket.html#method-c-new","(existing_socket = nil, **kwargs)","<p>Creates a new socket or wraps an existing socket.\n<p>Args:\n\n<pre>host: IP or hostname to connect to.\nport: ...</pre>\n"],["no_delay","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-no_delay","()","<p>Returns true if the Nagle algorithm is disabled. ( TCP_NODELAY )\n"],["no_delay=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-no_delay-3D","(value)","<p>Disables the Nagle algorithm if true. ( TCP_NODELAY )\n"],["no_delay?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-no_delay-3F","()",""],["on_accept","Ionian::Server","Ionian/Server.html#method-i-on_accept","(&block)",""],["on_match","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-on_match","(&block)",""],["on_match","Ionian::Socket","Ionian/Socket.html#method-i-on_match","(&block)",""],["persistent?","Ionian::Socket","Ionian/Socket.html#method-i-persistent-3F","()","<p>Returns true if the socket remains open after writing data.\n"],["purge","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-purge","()","<p>Erase the data in the IO and Ionian buffers. This is typically handled\nautomatically.\n"],["puts","Ionian::Socket","Ionian/Socket.html#method-i-puts","(*string)","<p>Writes the given string(s) to the socket and appends a newline character to\nany string not already ending …\n"],["read_all","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-read_all","()","<p>Read all data in the buffer. An alternative to using #readpartial with a\nlarge length.\n"],["read_match","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-read_match","(**kwargs, &block)","<p>Read matched data from the buffer. This method SHOULD NOT be used if\n#run_match is used.\n<p>Passes matches …\n"],["recork","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-recork","()","<p>Unsets cork to transmit data, then reapplies cork. ( TCP_CORK )\n"],["register_accept_listener","Ionian::Server","Ionian/Server.html#method-i-register_accept_listener","(&block)","<p>Register a block to be run when server accepts a client connection. The\nconnected client is passed to …\n"],["register_observer","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-register_observer","(&block)","<p>Register a block to be called when #run_match receives matched data. Method\ncallbacks can be registered …\n"],["register_observer","Ionian::Socket","Ionian/Socket.html#method-i-register_observer","(&block)","<p>Register a block to be called when #run_match receives matched data. Method\ncallbacks can be registered …\n"],["reuse_addr","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-reuse_addr","()","<p>Returns true if local address reuse is allowed. ( SO_REUSEADDR )\n"],["reuse_addr=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-reuse_addr-3D","(value)","<p>Allows local address reuse if true. ( SO_REUSEADDR )\n"],["reuse_addr?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-reuse_addr-3F","()",""],["run_match","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-run_match","(**kwargs)","<p>Start a thread that checks for data and notifies listeners (do |match,\nsocket|). Passes kwargs to #read_match …\n"],["ttl","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ttl","()","<p>Returns the time to live (hop limit). ( IP_TTL )\n"],["ttl=","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ttl-3D","(value)","<p>Sets the time to live (hop limit). ( IP_TTL )\n"],["ttl?","Ionian::Extension::Socket","Ionian/Extension/Socket.html#method-i-ttl-3F","()",""],["unregister_accept_listener","Ionian::Server","Ionian/Server.html#method-i-unregister_accept_listener","(proc)","<p>Unregisters a socket accept notifier block.\n"],["unregister_observer","Ionian::Extension::IO","Ionian/Extension/IO.html#method-i-unregister_observer","(&block)","<p>Unregister a block from being called when matched data is received.\n"],["unregister_observer","Ionian::Socket","Ionian/Socket.html#method-i-unregister_observer","(&block)","<p>Unregister a block from being called when matched data is received.\n"],["write","Ionian::Socket","Ionian/Socket.html#method-i-write","(string)","<p>Writes the given string to the socket. Returns the number of bytes written.\n"]]}}
|
data/doc/rdoc.css
CHANGED
@@ -193,7 +193,8 @@ nav h2 {
|
|
193
193
|
text-align: center;
|
194
194
|
}
|
195
195
|
|
196
|
-
nav h3
|
196
|
+
nav h3,
|
197
|
+
#table-of-contents-navigation {
|
197
198
|
margin: 0;
|
198
199
|
padding: 2px 8px 2px 8px;
|
199
200
|
text-align: right;
|
@@ -213,8 +214,13 @@ nav p {
|
|
213
214
|
border-top: 0;
|
214
215
|
}
|
215
216
|
|
216
|
-
#home-section h2
|
217
|
-
|
217
|
+
#home-section h2 {
|
218
|
+
text-align: center;
|
219
|
+
}
|
220
|
+
|
221
|
+
#table-of-contents-navigation {
|
222
|
+
font-size: 1.2em;
|
223
|
+
font-weight: bold;
|
218
224
|
text-align: center;
|
219
225
|
}
|
220
226
|
|
data/doc/table_of_contents.html
CHANGED
@@ -40,6 +40,9 @@
|
|
40
40
|
<li class="module">
|
41
41
|
<a href="Ionian/Extension/Socket.html">Ionian::Extension::Socket</a>
|
42
42
|
</li>
|
43
|
+
<li class="class">
|
44
|
+
<a href="Ionian/Server.html">Ionian::Server</a>
|
45
|
+
</li>
|
43
46
|
<li class="class">
|
44
47
|
<a href="Ionian/Socket.html">Ionian::Socket</a>
|
45
48
|
</li>
|
@@ -49,25 +52,35 @@
|
|
49
52
|
<ul>
|
50
53
|
|
51
54
|
<li class="method">
|
52
|
-
<a href="Ionian/Extension/
|
55
|
+
<a href="Ionian/Extension/Socket.html#method-c-extended">::extended</a>
|
53
56
|
—
|
54
|
-
<span class="container">Ionian::Extension::
|
57
|
+
<span class="container">Ionian::Extension::Socket</span>
|
55
58
|
|
56
59
|
<li class="method">
|
57
|
-
<a href="Ionian/Extension/
|
60
|
+
<a href="Ionian/Extension/IO.html#method-c-extended">::extended</a>
|
58
61
|
—
|
59
|
-
<span class="container">Ionian::Extension::
|
62
|
+
<span class="container">Ionian::Extension::IO</span>
|
60
63
|
|
61
64
|
<li class="method">
|
62
65
|
<a href="Ionian/Socket.html#method-c-new">::new</a>
|
63
66
|
—
|
64
67
|
<span class="container">Ionian::Socket</span>
|
65
68
|
|
69
|
+
<li class="method">
|
70
|
+
<a href="Ionian/Server.html#method-c-new">::new</a>
|
71
|
+
—
|
72
|
+
<span class="container">Ionian::Server</span>
|
73
|
+
|
66
74
|
<li class="method">
|
67
75
|
<a href="Ionian/Socket.html#method-i-3C-3C">#<<</a>
|
68
76
|
—
|
69
77
|
<span class="container">Ionian::Socket</span>
|
70
78
|
|
79
|
+
<li class="method">
|
80
|
+
<a href="Ionian/Server.html#method-i-close">#close</a>
|
81
|
+
—
|
82
|
+
<span class="container">Ionian::Server</span>
|
83
|
+
|
71
84
|
<li class="method">
|
72
85
|
<a href="Ionian/Socket.html#method-i-closed-3F">#closed?</a>
|
73
86
|
—
|
@@ -218,6 +231,11 @@
|
|
218
231
|
—
|
219
232
|
<span class="container">Ionian::Extension::Socket</span>
|
220
233
|
|
234
|
+
<li class="method">
|
235
|
+
<a href="Ionian/Server.html#method-i-listen">#listen</a>
|
236
|
+
—
|
237
|
+
<span class="container">Ionian::Server</span>
|
238
|
+
|
221
239
|
<li class="method">
|
222
240
|
<a href="Ionian/Extension/Socket.html#method-i-multicast">#multicast</a>
|
223
241
|
—
|
@@ -243,18 +261,23 @@
|
|
243
261
|
—
|
244
262
|
<span class="container">Ionian::Extension::Socket</span>
|
245
263
|
|
264
|
+
<li class="method">
|
265
|
+
<a href="Ionian/Server.html#method-i-on_accept">#on_accept</a>
|
266
|
+
—
|
267
|
+
<span class="container">Ionian::Server</span>
|
268
|
+
|
246
269
|
<li class="method">
|
247
270
|
<a href="Ionian/Extension/IO.html#method-i-on_match">#on_match</a>
|
248
271
|
—
|
249
272
|
<span class="container">Ionian::Extension::IO</span>
|
250
273
|
|
251
274
|
<li class="method">
|
252
|
-
<a href="Ionian/Socket.html#method-i-
|
275
|
+
<a href="Ionian/Socket.html#method-i-on_match">#on_match</a>
|
253
276
|
—
|
254
277
|
<span class="container">Ionian::Socket</span>
|
255
278
|
|
256
279
|
<li class="method">
|
257
|
-
<a href="Ionian/Socket.html#method-i-
|
280
|
+
<a href="Ionian/Socket.html#method-i-persistent-3F">#persistent?</a>
|
258
281
|
—
|
259
282
|
<span class="container">Ionian::Socket</span>
|
260
283
|
|
@@ -268,6 +291,11 @@
|
|
268
291
|
—
|
269
292
|
<span class="container">Ionian::Socket</span>
|
270
293
|
|
294
|
+
<li class="method">
|
295
|
+
<a href="Ionian/Extension/IO.html#method-i-read_all">#read_all</a>
|
296
|
+
—
|
297
|
+
<span class="container">Ionian::Extension::IO</span>
|
298
|
+
|
271
299
|
<li class="method">
|
272
300
|
<a href="Ionian/Extension/IO.html#method-i-read_match">#read_match</a>
|
273
301
|
—
|
@@ -278,11 +306,21 @@
|
|
278
306
|
—
|
279
307
|
<span class="container">Ionian::Extension::Socket</span>
|
280
308
|
|
309
|
+
<li class="method">
|
310
|
+
<a href="Ionian/Server.html#method-i-register_accept_listener">#register_accept_listener</a>
|
311
|
+
—
|
312
|
+
<span class="container">Ionian::Server</span>
|
313
|
+
|
281
314
|
<li class="method">
|
282
315
|
<a href="Ionian/Extension/IO.html#method-i-register_observer">#register_observer</a>
|
283
316
|
—
|
284
317
|
<span class="container">Ionian::Extension::IO</span>
|
285
318
|
|
319
|
+
<li class="method">
|
320
|
+
<a href="Ionian/Socket.html#method-i-register_observer">#register_observer</a>
|
321
|
+
—
|
322
|
+
<span class="container">Ionian::Socket</span>
|
323
|
+
|
286
324
|
<li class="method">
|
287
325
|
<a href="Ionian/Extension/Socket.html#method-i-reuse_addr">#reuse_addr</a>
|
288
326
|
—
|
@@ -318,6 +356,16 @@
|
|
318
356
|
—
|
319
357
|
<span class="container">Ionian::Extension::Socket</span>
|
320
358
|
|
359
|
+
<li class="method">
|
360
|
+
<a href="Ionian/Server.html#method-i-unregister_accept_listener">#unregister_accept_listener</a>
|
361
|
+
—
|
362
|
+
<span class="container">Ionian::Server</span>
|
363
|
+
|
364
|
+
<li class="method">
|
365
|
+
<a href="Ionian/Socket.html#method-i-unregister_observer">#unregister_observer</a>
|
366
|
+
—
|
367
|
+
<span class="container">Ionian::Socket</span>
|
368
|
+
|
321
369
|
<li class="method">
|
322
370
|
<a href="Ionian/Extension/IO.html#method-i-unregister_observer">#unregister_observer</a>
|
323
371
|
—
|
@@ -333,7 +381,7 @@
|
|
333
381
|
|
334
382
|
<footer id="validator-badges" role="contentinfo">
|
335
383
|
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
336
|
-
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.
|
384
|
+
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.
|
337
385
|
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
338
386
|
</footer>
|
339
387
|
|
data/lib/ionian/extension/io.rb
CHANGED
@@ -51,6 +51,12 @@ module Ionian
|
|
51
51
|
@ionian_expression = Regexp.new "(.*?)#{expression}" if exp.is_a? String
|
52
52
|
end
|
53
53
|
|
54
|
+
# Read all data in the buffer.
|
55
|
+
# An alternative to using #readpartial with a large length.
|
56
|
+
def read_all
|
57
|
+
readpartial 0xFFFF
|
58
|
+
end
|
59
|
+
|
54
60
|
# Read matched data from the buffer.
|
55
61
|
# This method SHOULD NOT be used if #run_match is used.
|
56
62
|
#
|
@@ -72,7 +78,7 @@ module Ionian
|
|
72
78
|
# timeout: Timeout in seconds IO::select will block.
|
73
79
|
# skip_select: Skip over the IO::select statement. Use if you
|
74
80
|
# are calling IO::select ahead of this method.
|
75
|
-
# build_methods: Build
|
81
|
+
# build_methods: Build accessor methods from named capture groups.
|
76
82
|
# Enabled by default.
|
77
83
|
def read_match(**kwargs, &block)
|
78
84
|
timeout = kwargs.fetch :timeout, @ionian_timeout
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'ionian/socket'
|
3
|
+
|
4
|
+
module Ionian
|
5
|
+
|
6
|
+
# A convenient wrapper for TCP, UDP, and Unix server sockets.
|
7
|
+
class Server
|
8
|
+
|
9
|
+
def initialize **kwargs, &block
|
10
|
+
@accept_listeners = []
|
11
|
+
register_accept_listener &block if block_given?
|
12
|
+
|
13
|
+
@interface = kwargs.fetch :interface, ''
|
14
|
+
@port = kwargs.fetch :port, nil
|
15
|
+
|
16
|
+
|
17
|
+
# Automatically select UDP for the multicast range. Otherwise default to TCP.
|
18
|
+
default_protocol = :tcp
|
19
|
+
# TODO: This ivar may be incorrect for UDP -- bound interface is not destination.
|
20
|
+
default_protocol = :udp if Ionian::Extension::Socket.multicast? @interface
|
21
|
+
default_protocol = :unix if @interface.start_with? '/'
|
22
|
+
|
23
|
+
@protocol = kwargs.fetch :protocol, default_protocol
|
24
|
+
|
25
|
+
# TODO: Move this to #listen.
|
26
|
+
case @protocol
|
27
|
+
when :tcp
|
28
|
+
@server = TCPServer.new @interface, @port
|
29
|
+
@server.setsockopt ::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, [1].pack('i')
|
30
|
+
when :udp
|
31
|
+
@server = Ionian::Socket.new host: @interface, port: @port, protocol: :udp
|
32
|
+
when :unix
|
33
|
+
@server = UNIXServer.new @interface
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Starts the socket server listening for connections.
|
38
|
+
# Blocks registered with #register_accept_listener will
|
39
|
+
# be run when a connection is accepted.
|
40
|
+
def listen &block
|
41
|
+
register_accept_listener &block if block_given?
|
42
|
+
|
43
|
+
@accept_thread ||= Thread.new do
|
44
|
+
# Package in an Ionian::Socket
|
45
|
+
begin
|
46
|
+
client = Ionian::Socket.new @server.accept
|
47
|
+
|
48
|
+
@accept_listeners.each do |listener|
|
49
|
+
listener.call client
|
50
|
+
end
|
51
|
+
rescue Errno::EBADF
|
52
|
+
# This ignores the connection if the client closed it before it
|
53
|
+
# could be accepted.
|
54
|
+
rescue IOError
|
55
|
+
# This ignores the connection if the client closed it before it
|
56
|
+
# could be accepted.
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Shutdown the server socket and stop listening for connections.
|
62
|
+
def close
|
63
|
+
@server.close if @server
|
64
|
+
@accept_thread.join if @accept_thread
|
65
|
+
@accept_thread = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
# Register a block to be run when server accepts a client connection.
|
69
|
+
# The connected client is passed to the block as an Ionain::Client.
|
70
|
+
def register_accept_listener &block
|
71
|
+
@accept_listeners << block unless @accept_listeners.include? block
|
72
|
+
block
|
73
|
+
end
|
74
|
+
|
75
|
+
alias_method :on_accept, :register_accept_listener
|
76
|
+
|
77
|
+
# Unregisters a socket accept notifier block.
|
78
|
+
def unregister_accept_listener proc
|
79
|
+
@accept_listeners.delete_if {|o| o == proc}
|
80
|
+
proc
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/lib/ionian/socket.rb
CHANGED
@@ -2,9 +2,12 @@ require 'ionian/extension/socket'
|
|
2
2
|
|
3
3
|
module Ionian
|
4
4
|
|
5
|
-
# A convenient wrapper for TCP, UDP, and Unix sockets.
|
5
|
+
# A convenient wrapper for TCP, UDP, and Unix client sockets.
|
6
6
|
class Socket
|
7
|
+
attr_accessor :expression
|
7
8
|
|
9
|
+
# Creates a new socket or wraps an existing socket.
|
10
|
+
#
|
8
11
|
# Args:
|
9
12
|
# host: IP or hostname to connect to.
|
10
13
|
# port: Connection's port number. Default is 23. Unused by :unix protocol.
|
@@ -20,37 +23,70 @@ module Ionian
|
|
20
23
|
# cork: Set true to enable the TCP_CORK flag. Buffers multiple writes
|
21
24
|
# into one segment.
|
22
25
|
# expression: Overrides the #read_match regular expression for received data.
|
23
|
-
def initialize(**kwargs)
|
24
|
-
@socket
|
26
|
+
def initialize(existing_socket = nil, **kwargs)
|
27
|
+
@socket = existing_socket
|
25
28
|
|
26
|
-
|
27
|
-
# :port should override this parsed value.
|
29
|
+
@ionian_listeners = []
|
28
30
|
|
29
|
-
@
|
30
|
-
@port = kwargs.fetch :port, 23
|
31
|
-
@bind_port = kwargs.fetch :bind_port, @port
|
31
|
+
@expression = kwargs.fetch :expression, nil
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
if existing_socket
|
34
|
+
# Convert existing socket.
|
35
|
+
@socket.extend Ionian::Extension::IO
|
36
|
+
@socket.extend Ionian::Extension::Socket
|
37
|
+
|
38
|
+
if existing_socket.is_a? UNIXSocket
|
39
|
+
@host = existing_socket.path
|
40
|
+
@port = nil
|
41
|
+
else
|
42
|
+
@host = existing_socket.remote_address.ip_address if existing_socket
|
43
|
+
@port = existing_socket.remote_address.ip_port if existing_socket
|
44
|
+
end
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
if @socket.is_a? TCPSocket
|
47
|
+
@protocol = :tcp
|
48
|
+
elsif @socket.is_a? UDPSocket
|
49
|
+
@protocol = :udp
|
50
|
+
elsif @socket.is_a? UNIXSocket
|
51
|
+
@protocol = :unix
|
52
|
+
end
|
53
|
+
|
54
|
+
@persistent = true # Existing sockets are always persistent.
|
55
|
+
|
56
|
+
@socket.expression = @expression if @expression
|
57
|
+
|
58
|
+
initialize_socket_methods
|
59
|
+
else
|
60
|
+
# Initialize new socket.
|
61
|
+
|
62
|
+
# TODO: Should be able to parse the port out of host.
|
63
|
+
# :port should override this parsed value.
|
64
|
+
|
65
|
+
@host = kwargs.fetch :host
|
66
|
+
@port = kwargs.fetch :port, 23
|
67
|
+
@bind_port = kwargs.fetch :bind_port, @port
|
41
68
|
|
42
|
-
|
43
|
-
|
44
|
-
|
69
|
+
# Automatically select UDP for the multicast range. Otherwise default to TCP.
|
70
|
+
default_protocol = :tcp
|
71
|
+
default_protocol = :udp if Ionian::Extension::Socket.multicast? @host
|
72
|
+
default_protocol = :unix if @host.start_with? '/'
|
73
|
+
|
74
|
+
@protocol = kwargs.fetch :protocol, default_protocol
|
75
|
+
@persistent = kwargs.fetch :persistent, true
|
76
|
+
|
77
|
+
@reuse_addr = kwargs.fetch :reuse_addr, false
|
78
|
+
@no_delay = kwargs.fetch :no_delay, false
|
79
|
+
@cork = kwargs.fetch :cork, false
|
45
80
|
|
46
|
-
|
81
|
+
|
82
|
+
create_socket if @persistent
|
83
|
+
end
|
47
84
|
end
|
48
85
|
|
49
86
|
# Returns a symbol of the type of protocol this socket uses:
|
50
87
|
# :tcp, :udp, :unix
|
51
|
-
|
52
|
-
|
53
|
-
end
|
88
|
+
attr_reader :protocol
|
89
|
+
alias_method :protocol?, :protocol
|
54
90
|
|
55
91
|
# Returns true if the socket remains open after writing data.
|
56
92
|
def persistent?
|
@@ -78,6 +114,24 @@ module Ionian
|
|
78
114
|
matches
|
79
115
|
end
|
80
116
|
|
117
|
+
# Register a block to be called when #run_match receives matched data.
|
118
|
+
# Method callbacks can be registered with &object.method(:method).
|
119
|
+
# Returns a reference to the given block.
|
120
|
+
# block = ionian_socket.register_observer {...}
|
121
|
+
def register_observer &block
|
122
|
+
@ionian_listeners << block unless @ionian_listeners.include? block
|
123
|
+
@socket.register_observer &block if @socket
|
124
|
+
block
|
125
|
+
end
|
126
|
+
|
127
|
+
alias_method :on_match, :register_observer
|
128
|
+
|
129
|
+
# Unregister a block from being called when matched data is received.
|
130
|
+
def unregister_observer(&block)
|
131
|
+
@ionian_listeners.delete_if {|o| o == block}
|
132
|
+
@socket.unregister_observer &block if @socket
|
133
|
+
block
|
134
|
+
end
|
81
135
|
|
82
136
|
### Methods Forwarded To @socket ###
|
83
137
|
|
@@ -145,6 +199,7 @@ module Ionian
|
|
145
199
|
when :tcp
|
146
200
|
@socket = ::TCPSocket.new @host, @port
|
147
201
|
@socket.extend Ionian::Extension::Socket
|
202
|
+
@socket.expression = @expression if @expression
|
148
203
|
@socket.no_delay = true if @no_delay
|
149
204
|
@socket.cork = true if @cork
|
150
205
|
|
@@ -170,6 +225,9 @@ module Ionian
|
|
170
225
|
|
171
226
|
@socket.expression = @expression if @expression
|
172
227
|
|
228
|
+
# Register listeners.
|
229
|
+
@ionian_listeners.each { |proc| @socket.on_match &proc }
|
230
|
+
|
173
231
|
initialize_socket_methods
|
174
232
|
end
|
175
233
|
|