Module: Socket::ListenAndAccept

Includes:
IO::Socketable
Included in:
Socket, TCPServer, UNIXServer
Defined in:
lib/rubysl/socket/socket.rb

Instance Method Summary collapse

Instance Method Details

#acceptObject



453
454
455
456
457
458
459
460
461
# File 'lib/rubysl/socket/socket.rb', line 453

def accept
  return if closed?

  fd = super

  socket = self.class.superclass.allocate
  IO.setup socket, fd, nil, true
  socket
end

#accept_nonblockObject

Set nonblocking and accept.



466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/rubysl/socket/socket.rb', line 466

def accept_nonblock
  return if closed?

  fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)

  fd = Socket::Foreign.accept descriptor, nil, nil

  Errno.handle 'accept(2)' if fd < 0

  # TCPServer -> TCPSocket etc. *sigh*
  socket = self.class.superclass.allocate
  IO.setup socket, fd, nil, true
  socket
end

#accept_nonblock2Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/rubysl/socket/socket.rb', line 481

def accept_nonblock2
  return if closed?

  fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)

  fd = Socket::Foreign.accept descriptor, nil, nil
  if fd < 0
    return nil if FFI::Platform::POSIX.errno == Errno::EAGAIN::Errno
    Errno.handle 'accept(2)'
  end

  # TCPServer -> TCPSocket etc. *sigh*
  socket = self.class.superclass.allocate
  IO.setup socket, fd, nil, true
  socket
end

#listen(backlog) ⇒ Object



443
444
445
446
447
448
449
450
451
# File 'lib/rubysl/socket/socket.rb', line 443

def listen(backlog)
  backlog = Rubinius::Type.coerce_to backlog, Fixnum, :to_int

  err = Socket::Foreign.listen descriptor, backlog

  Errno.handle 'listen(2)' unless err == 0

  err
end