Solved

Urgent: Asychronous I/O in Unix

Posted on 1998-11-11
3
273 Views
Last Modified: 2010-04-21
Please tell me how to simulate asynchronous I/O in Unix.i.e
If I am using  normal
fread( void *buffer, size_t size, size_t count, FILE *stream);
 command in my program the calling Unix process will block until the transfer is complete.

In Win32 we have the option like this

BOOL ReadFile( HANDLE hFile,  // handle of file to read
               LPVOID lpBuffer,  // address of buffer                                 that receives data
               DWORD nNumberOfBytesToRead,  // number of                                 bytes to read
               LPDWORD lpNumberOfBytesRead,
                        // address of number of bytes read
              LPOVERLAPPED lpOverlapped
                       // address of structure for data );
If lpoverlapped is not NULL then
Here the lpOverlapped will be filled up by windows with some internal status info & my process will not block.Instead it will execute instructions written next to point where i made call to this command.
After some time if I want to test the status of my I/O I can use
BOOL GetOverlappedResult( HANDLE hFile,
       // handle of file, pipe, or communications device
                         LPOVERLAPPED lpOverlapped,
      // address of overlapped structure
                         LPDWORD lpNumberOfBytesTransferred,
      // address of actual bytes count
                         BOOL bWait
      // wait flag );
which will return the status of I/O.So I have no need to wait for I/O to complete.
Please give me ways to simulate similar Asynchronous activity in Unix.I do not think it should be impossible  to simulate above two API's using unix API.
Please send me any source code examples if you can.
Please provide some discrete solution.

Thanking in advance..
0
Comment
Question by:flower020397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
braveheart earned 500 total points
ID: 2007763
See the man pages for "aio_read" and related routines.
Use "man -k asynchronous" to discover a full list of related pages

aio_read combines all the arguments into a single structure but has similar information to the ReadFile routine.

aio_result can be used in a similar way to GetOverlappedResult.

Note that these routines are specific to AIX so if you port to a different flavour of UNIX you will need to take this into account. For instance, on Solaris the equivalent routines have no underscore and may have slightly different functionality.
0
 

Author Comment

by:flower020397
ID: 2007764
Thanks for the help.
If you have written some sample source code  please send me.
It can be helpful for me.
0
 
LVL 3

Expert Comment

by:braveheart
ID: 2007765
Sorry. All I did was check the man pages.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question