Solved

Urgent: Asychronous I/O in Unix

Posted on 1998-11-11
3
259 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry. All I did was check the man pages.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now