Monday, August 29, 2011

Closing the Dual Streams on a socket


After you have two streams established, as shown in Listing 10.2(using separate Read and Writes Stream on sockets), you can safely use functions such as fgetc(3) or fgets(3) on your rx stream. Write calls using fputs(3) or fputc(3), for example, can use the output stream tx instead. Use of the separate streams eliminates buffer interaction and removes the need to call fgetpos(3) at various points in your program flow.

However, when you are finished with these streams, you must perform the following:
  • fclose(rx) to close the input stream.
  • fclose(tx) to close the output stream.

The preceding procedure accomplishes the following:
  • Flushes any buffered writes for the writing stream.
  • Closes the underlying file descriptor.
  • Releases the buffers, if any.
  • Releases the stream managed by the FILE object.


No comments:

Post a Comment