Nonblocking I/O

This is a discussion on Nonblocking I/O within the Linux Programming forums, part of the Platform Specific Boards category; Hi I am trying to scan a network and i read that it is better to use nonblocking I/O for ...

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

    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,164
    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/

  5. #5
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    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, 04:14 PM
  5. WSAAsyncSelect I/O Mode :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-12-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21