Class: TCPServer
- 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(host = nil, service) ⇒ TCPServer
constructor
A new instance of TCPServer.
-
#listen(backlog) ⇒ Object
-
#sysaccept ⇒ Object
Methods inherited from TCPSocket
Methods inherited from IPSocket
#addr, getaddress, #peeraddr, #recvfrom
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(host = nil, service) ⇒ TCPServer
Returns a new instance of TCPServer
268 269 270 271 272 273 274 275 276 277 278 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 268 def initialize(host=nil, service) ai = Addrinfo.getaddrinfo(host, service, nil, nil, nil, Socket::AI_PASSIVE)[0] @init_with_fd = true super(Socket._socket(ai.afamily, Socket::SOCK_STREAM, 0), "r+") if Socket.const_defined?(:SO_REUSEADDR) self.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) end Socket._bind(self.fileno, ai.to_sockaddr) listen(5) self end |
Instance Method Details
#accept ⇒ Object
280 281 282 283 284 285 286 287 288 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 280 def accept fd = self.sysaccept begin TCPSocket.new_with_prelude(proc { @init_with_fd = true }, fd, "r+") rescue IO._sysclose(fd) rescue nil raise end end |
#accept_nonblock ⇒ Object
290 291 292 293 294 295 296 297 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 290 def accept_nonblock begin self._setnonblock(true) self.accept ensure self._setnonblock(false) end end |
#listen(backlog) ⇒ Object
299 300 301 302 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 299 def listen(backlog) Socket._listen(self.fileno, backlog) 0 end |
#sysaccept ⇒ Object
304 305 306 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 304 def sysaccept Socket._accept(self.fileno) end |