Solved

Urgent: Asychronous I/O in Unix

Posted on 1998-11-11
3
268 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

821 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