Class: UNIXServer
- Inherits:
-
UNIXSocket
- Object
- IO
- BasicSocket
- UNIXSocket
- UNIXServer
- Defined in:
- mrbgems/mruby-socket/mrblib/socket.rb
Instance Attribute Summary
Attributes inherited from BasicSocket
Instance Method Summary collapse
- #accept ⇒ Object
- #accept_nonblock ⇒ Object
-
#initialize(path) ⇒ UNIXServer
constructor
A new instance of UNIXServer.
- #listen(backlog) ⇒ Object
- #sysaccept ⇒ Object
Methods inherited from UNIXSocket
#addr, #path, #peeraddr, #recvfrom, socketpair
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) ⇒ UNIXServer
Returns a new instance of UNIXServer.
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 523 def initialize(path) fd = Socket._socket(Socket::AF_UNIX, Socket::SOCK_STREAM, 0) begin super(fd) Socket._bind(fd, Socket.pack_sockaddr_un(path)) self.listen(5) rescue => e IO._sysclose(fd) rescue nil raise e end if block_given? begin yield self ensure self.close rescue nil unless self.closed? end end end |
Instance Method Details
#accept ⇒ Object
543 544 545 546 547 548 549 550 551 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 543 def accept fd = self.sysaccept begin sock = UNIXSocket.for_fd(fd) rescue IO._sysclose(fd) rescue nil end sock end |
#accept_nonblock ⇒ Object
553 554 555 556 557 558 559 560 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 553 def accept_nonblock begin self._setnonblock(true) self.accept ensure self._setnonblock(false) end end |
#listen(backlog) ⇒ Object
562 563 564 565 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 562 def listen(backlog) Socket._listen(self.fileno, backlog) 0 end |
#sysaccept ⇒ Object
567 568 569 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 567 def sysaccept Socket._accept(self.fileno) end |