Working With TCP Sockets by Jesse Storimer
Author:Jesse Storimer
Language: eng
Format: epub, pdf
Publisher: Jesse Storimer
Published: 2012-01-17T16:00:00+00:00
Non-blocking Connect
Think you can guess what the connect_nonblock method does by now? Then you're in for a surprise! connect_nonblock behaves a bit differently than the other non-blocking IO methods.
Whereas the other methods either complete their operation or raise an appropriate exception, connect_nonblock leaves its operation in progress and raises an exception.
If connect_nonblock cannot make an immediate connection to the remote host, then it actually lets the operation continue in the background and raises Errno::EINPROGRESS to notify us that the operation is still in progress. In the next chapter we'll see how we can be notified when this background operation completes. For now, a quick example:
# ./code/snippets/connect_nonblock.rbrequire 'socket' socket = Socket.new(:INET, :STREAM) remote_addr = Socket.pack_sockaddr_in(80, 'google.com') begin # Initiate a nonblocking connection to google.com on port 80. socket.connect_nonblock(remote_addr) rescue Errno::EINPROGRESS # Operation is in progress. rescue Errno::EALREADY # A previous nonblocking connect is already in progress. rescue Errno::ECONNREFUSED # The remote host refused our connect. end
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(10116)
The Mikado Method by Ola Ellnestam Daniel Brolund(10005)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9976)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8517)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7909)
Grails in Action by Glen Smith Peter Ledbrook(7877)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7845)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7758)
Windows APT Warfare by Sheng-Hao Ma(7418)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(7173)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(7052)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6627)
Kotlin in Action by Dmitry Jemerov(5291)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4377)
Solidity Programming Essentials by Ritesh Modi(4338)
WordPress Plugin Development Cookbook by Yannick Lefebvre(4155)
Functional Programming in JavaScript by Mantyla Dan(4116)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(4065)
The Ultimate iOS Interview Playbook by Avi Tsadok(4038)
