Class: UNIXServer
- Inherits:
-
UNIXSocket
- Object
- IO
- BasicSocket
- UNIXSocket
- UNIXServer
- Defined in:
- mrbgems/mruby-socket/mrblib/socket.rb
Constant Summary
Constants inherited from IO
IO::BUF_SIZE, IO::SEEK_CUR, IO::SEEK_END, IO::SEEK_SET
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
#_is_socket=, #_recvfrom, #_setnonblock, #close, do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, #getpeereid, #getpeername, #getsockname, #getsockopt, #local_address, #recv, #recv_nonblock, #remote_address, #send, #setsockopt, #shutdown, #sysread, #sysseek, #syswrite
Methods inherited from IO
#<<, #_check_readable, #_read_buf, #close, #close_on_exec=, #close_on_exec?, #close_write, #closed?, #each, #each_byte, #eof?, #fileno, #flush, #getc, #gets, #hash, #initialize_copy, #isatty, open, #pid, pipe, popen, #pos, #pos=, #print, #printf, #puts, read, #read, #readchar, #readline, #readlines, #rewind, #seek, #sync, #sync=, #sysread, #sysseek, #syswrite, #ungetc, #write
Constructor Details
#initialize(path) ⇒ UNIXServer
Returns a new instance of UNIXServer
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 524 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
544 545 546 547 548 549 550 551 552 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 544 def accept fd = self.sysaccept begin sock = UNIXSocket.for_fd(fd) rescue IO._sysclose(fd) rescue nil end sock end |
#accept_nonblock ⇒ Object
554 555 556 557 558 559 560 561 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 554 def accept_nonblock begin self._setnonblock(true) self.accept ensure self._setnonblock(false) end end |
#listen(backlog) ⇒ Object
563 564 565 566 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 563 def listen(backlog) Socket._listen(self.fileno, backlog) 0 end |
#sysaccept ⇒ Object
568 569 570 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 568 def sysaccept Socket._accept(self.fileno) end |