| 377 | | @loopbreak_writer.close if @loopbreak_writer |
|---|
| 378 | | rd,@loopbreak_writer = IO.pipe |
|---|
| 379 | | LoopbreakReader.new rd |
|---|
| | 377 | # Can't use an IO.pipe because they can't be set nonselectable in Windows. |
|---|
| | 378 | # Pick a random localhost UDP port. |
|---|
| | 379 | #@loopbreak_writer.close if @loopbreak_writer |
|---|
| | 380 | #rd,@loopbreak_writer = IO.pipe |
|---|
| | 381 | @loopbreak_reader = UDPSocket.new |
|---|
| | 382 | @loopbreak_writer = UDPSocket.new |
|---|
| | 383 | bound = false |
|---|
| | 384 | 100.times { |
|---|
| | 385 | @loopbreak_port = rand(10000) + 40000 |
|---|
| | 386 | begin |
|---|
| | 387 | @loopbreak_reader.bind "localhost", @loopbreak_port |
|---|
| | 388 | bound = true |
|---|
| | 389 | break |
|---|
| | 390 | rescue |
|---|
| | 391 | end |
|---|
| | 392 | } |
|---|
| | 393 | raise "Unable to bind Loopbreaker" unless bound |
|---|
| | 394 | LoopbreakReader.new(@loopbreak_reader) |
|---|
| 431 | | m = @io.fcntl(Fcntl::F_GETFL, 0) |
|---|
| 432 | | @io.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK | m) |
|---|
| | 447 | if defined?(Fcntl::F_GETFL) |
|---|
| | 448 | m = @io.fcntl(Fcntl::F_GETFL, 0) |
|---|
| | 449 | @io.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK | m) |
|---|
| | 450 | else |
|---|
| | 451 | # Windows doesn't define F_GETFL. |
|---|
| | 452 | # It's not very reliable about setting descriptors nonblocking either. |
|---|
| | 453 | begin |
|---|
| | 454 | s = Socket.for_fd(@io.fileno) |
|---|
| | 455 | s.fcntl( Fcntl::F_SETFL, Fcntl::O_NONBLOCK ) |
|---|
| | 456 | rescue Errno::EINVAL, Errno::EBADF |
|---|
| | 457 | STDERR.puts "Serious error: unable to set descriptor non-blocking" |
|---|
| | 458 | end |
|---|
| | 459 | end |
|---|