• Keine Ergebnisse gefunden

STREAM FILES

Im Dokument 1/0 86 (Seite 51-55)

Stream files provide a means for one task to send large amounts of information to another task in a different job. Be aware that this is one of several techniques for job-to-job communication. If you are not familiar with other techniques, refer to the iRMX 86 PROGRAMMING

TECHNIQUES manual.

The aspect of stream files that makes them very useful is that they allow a task to communicate with a second task as though the second task were a device. This extends the notion of device independence to include tasks.

Because two tasks are involved in using each stream file, each task must perform one half of a protocol. There are several protocols that work, but the following one is typical and serves as a good illustration. Note that the two halves of the protocol can be performed in either order or concurrently.

ACTIONS REQUIRED OF THE WRITING TASK

The writing task must perform seven steps in its half of the protocol to ensure that it has established communication with the reading task. The steps are:

1. Obtain a connection to the stream file device.

Although stream files do not actually require a physical device, your application must call A$PHYSICAL$ATTACH$DEVICE to obtain a device connection before creating a stream file. This is

necessary because, when your application invokes the

A$CREATE$FILE system call, the device connection tells the Basic I/O System what kind of file to create.

The A$PHYSICAL$ATTACH$DEVICE system call requires a parameter that identifies the device to be attached. For stream files, there is only one device, and its name is specified during the process of configuring the system. Intel recommends the name

"stream", but it is possible that the person responsible for configuring your system changed this name. For the remainder of this discussion, this manual assumes that the name of your

system's stream file device is "stream". For more information regarding the configuration process, refer to the iID1X 86 CONFIGURATION GUIDE.

As with other devices, "stream" cannot be multiply attached, so the system program should be written so as to call

A$PHYSICAL$ATTACH$DEVICE only once. The program can then save the device connection and pass it to any application program that requests it.

I

I

I

STREAM FILES

2. Create the stream file.

Use the A$CREATE$FILE system call with the device connection to create the stream file and obtain a token for a file connection to the stream file. Use the token for the device connection as the PREFIX parameter, in order to tell the Basic I/O System to create a stream file.

3. Pass the file connection to the reading task.

There are several ways of doing this, including the use of object directories and mailboxes. For explicit instructions, refer to the iRMX 86 PROGRAMMING TECHNIQUES manual.

4. Open the file for writing.

Use the A$OPEN system call to open the file connection for

writing. Set the CONNECTION parameter equal to the token for the file connection. Set the MODE parameter for writing. And set the SHARE parameter for sharing only with readers.

5. Write information to the stream file.

Use the A$WRITE system call as often as needed to write information to the stream file. Use the token for the file connection as the CONNECTION parameter.

The Basic I/O System uses the concurrent part of the A$WRITE system call to synchronize the writing and reading tasks on a call-by-call basis. The Basic I/O System does this by sending a response to each invocation of A$WRITE only after the reading task has finished reading all information that was written by the A$WRITE call.

6. Close the connection.

When finished writing to the stream file, use the A$CLOSE system call to close the connection. Note that after this step, the writing task can repeat steps 4, 5, and 6.

7. Delete the connection.

Use the A$DELETE$CONNECTION system call to delete the connection to the stream file.

All of these system calls are described in Chapter 8.

6-2

STREAM FILES

ACTIONS REQUIRED OF THE READING TASK

The reading task must perform the following six steps in its half of the protocol to successfully read the information written by the writing task.

1. Get the file connection for the stream file.

The technique used to accomplish this depends on how the writing task passed the file connection.

2. Create a second file connection for the stream file.

There are two reasons for doing this. First, the reading task must have a different file pointer than that of the writing task. Second, the Basic I/O System rejects any connections created in one job but used by another to manipulate a file.

Obtain this new connection by using the A$ATTACH$FILE system call. Set the PREFIX parameter to the token for the original file connection.

NOTE

The reading task can also use the

A$CREATE$FILE system call to obtain the new connection to the same stream

file. The reason for this is that the Basic I/O System examines the nature of the PREFIX parameter in the

A$CREATE$FILE system call. If the value provided is a device connection, the Basic I/O System will create a new file and return a connection for it.

On the other hand, if the value provided is a file connection, the Basic I/O System will just create another connection to the same file.

This careful distinction between the A$CREATE$FILE and the A$ATTACH$FILE

system calls is necessary to be consistent with named and physical files. If you want your application to work with any kind of file, you must maintain this consistency.

3. Open the new file connection for reading.

Use the A$OPEN system call to open the connection for reading.

Set the CONNECTION parameter equal to the token for the new connection. Set the MODE parameter for reading, and set the SHARE parameter for sharing with all connections to the file.

I

STREAM FILES

4. Commence reading.

Use the A$READ system call to read the file until reading is no longer necessary or until an end-of-file condition is detected by the Basic I/O System.

5. Close the new file connection.

Use the A$CLOSE system call to close the new file connection.

Note that after this step, the reading task can repeat steps 3, 4, and 5.

6. Delete the new file connection.

Use the A$DELETE$CONNECTION system call to delete the new

connection to the stream file. The writing task deletes the old connection, and, as soon as both connections have been deleted, the Basic I/O System deletes the stream file.

All of these system calls are described in Chapter 8.

***

6-4

Im Dokument 1/0 86 (Seite 51-55)