Thread: Nonblocking I/O

  1. #1
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275

    Nonblocking I/O

    Hi

    I am trying to scan a network and i read that it is better to use nonblocking I/O for this (from the fyodor's nmap.txt), since linear socket I/O may take lots of time! With nonblocking I/O, I am able to use multiple socket at the same time.

    What is the main difference between a linear and nonblocking I/O? In action and in coding point of views...

    Thanks in advice...

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    12
    As far as basic I/O theory goes a blocking operation will return (either with some data or after some data has been received and handled) only once the event has occured (i.e write,read,etc). So if it expecting to read something in, it will halt until it has read something.

    This is good in that you can handle your data synchronously, but bad in the sense that it will stop the rest of the process from executing (and possibly hang your program).

    If you were to use a non blocking call, then you would simply send a message to the interface that you expect a response from, and hope it gets back to you. This asynchronous behaviour will stop an I/O call from holding up the rest of the process. So your process can continue on through the code doing whatever. I guess what makes it a little more complicated is that you need a mechanism to acknowledge this response once you have sent off the request (This would be done either automatically for you, or you may have to implement a method of handling this response).

    Ray

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Your web browser, for instance, uses non-blocking I/O. If it used standard (blocking) I/O then the whole browser interface would freeze up while it was trying to connect to a website and get the data. There'd be no use for a Stop button because you'd never be able to use it.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Logic Junkie
    Join Date
    Nov 2005
    Posts
    31
    I think BeeJ guide speaks comprehensibly about the topic - http://beej.us/guide/bgnet/output/html/
    -S

  5. #5
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Thanks for all advice...

    I read beej's guide and realize that i have to concentrate on select(2) system call. I read the man page and see that there is a very useful simple example about usage of select(2).

    So, the example in the man page make the concept more clear for me, I do love Linux

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Buffered/UnBuffered I/O
    By valaris in forum C Programming
    Replies: 1
    Last Post: 08-06-2008, 11:31 PM
  2. asynchronized I/O == multiplexing I/O?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 07-24-2006, 10:06 AM
  3. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  4. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 05:14 PM
  5. WSAAsyncSelect I/O Mode :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-12-2002, 03:23 PM