Class: UNIXSocket
- Inherits:
-
BasicSocket
- Object
- IO
- BasicSocket
- UNIXSocket
- Defined in:
- mrbgems/mruby-socket/mrblib/socket.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BasicSocket
Class Method Summary collapse
Instance Method Summary collapse
- #addr ⇒ Object
-
#initialize(path, &block) ⇒ UNIXSocket
constructor
A new instance of UNIXSocket.
- #path ⇒ Object
- #peeraddr ⇒ Object
-
#recvfrom(maxlen, flags = 0) ⇒ Object
def recv_io.
Methods inherited from BasicSocket
do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, #local_address, #recv_nonblock, #remote_address
Methods inherited from IO
#<<, #each, #each_byte, #each_char, #hash, open, pipe, popen, #pos=, #print, #printf, #puts, read, #rewind, #ungetbyte
Constructor Details
#initialize(path, &block) ⇒ UNIXSocket
Returns a new instance of UNIXSocket.
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 470 def initialize(path, &block) if self.is_a? UNIXServer super(path, "r") else super(Socket._socket(Socket::AF_UNIX, Socket::SOCK_STREAM, 0), "r+") Socket._connect(self.fileno, Socket.sockaddr_un(path)) if block_given? begin yield self ensure begin self.close unless self.closed? rescue StandardError end end end end end |
Class Method Details
.socketpair(type = Socket::SOCK_STREAM, protocol = 0) ⇒ Object Also known as: pair
491 492 493 494 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 491 def socketpair(type=Socket::SOCK_STREAM, protocol=0) a = Socket.socketpair(Socket::AF_UNIX, type, protocol) [ UNIXSocket.for_fd(a[0]), UNIXSocket.for_fd(a[1]) ] end |
Instance Method Details
#addr ⇒ Object
499 500 501 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 499 def addr [ "AF_UNIX", path ] end |
#path ⇒ Object
503 504 505 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 503 def path Addrinfo.new(self.getsockname).unix_path end |
#peeraddr ⇒ Object
507 508 509 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 507 def peeraddr [ "AF_UNIX", Addrinfo.new(self.getpeername).unix_path ] end |
#recvfrom(maxlen, flags = 0) ⇒ Object
def recv_io
513 514 515 516 517 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 513 def recvfrom(maxlen, flags=0) msg, sa = _recvfrom(maxlen, flags) path = (sa.size > 0) ? Addrinfo.new(sa).unix_path : "" [ msg, [ "AF_UNIX", path ] ] end |