This chapter describes buffering modes used by z/OS XL C/C++ library functions available to control buffering and methods of flushing buffers.

z/OS XL C/C++ uses buffers to map C I/O to system-level I/O. When z/OS XL C/C++ performs I/O operations, it uses one of the following buffering modes:

  • Line buffering - characters are transmitted to the system as a block when a new-line character is encountered. Line buffering is meaningful only for text streams and UNIX® file system files.
  • Full buffering - characters are transmitted to the system as a block when a buffer is filled.
  • No buffering - characters are transmitted to the system as they are written. Only regular memory files and UNIX file system files support the no buffering mode.

The buffer mode affects the way the buffer is flushed. You can use the setvbuf() and setbuf()library functions to control buffering, but you cannot change the buffering mode after an I/O operation has used the buffer, as all read, write, and reposition operations do. In some circumstances, repositioning alters the contents of the buffer. It is strongly recommended that you only use setbuf() and setvbuf() before any I/O, to conform with ANSI, and to avoid any dependency on the current implementation. If you use setvbuf(), z/OS XL C/C++ may or may not accept your buffer for its internal use. For a hiperspace memory file, if the size of the buffer specified to setvbuf() is 8K or more, it will affect the number of hiperspace blocks read or written on each call to the operating system; the size is rounded down to the nearest multiple of 4K.

Full buffering is the default except in the following cases:

  • If you are using an interactive terminal, z/OS XL C/C++ uses line buffering.
  • If you are running under CICS®, z/OS XL C/C++ also uses line buffering.
  • stderr is line-buffered by default.
  • If you are using a memory file, z/OS XL C/C++ does not use any buffering.

For terminals, because I/O is always unblocked, line buffering is equivalent to full buffering.

For record I/O files, buffering is meaningful only for blocked files or for record I/O files in z/OS® UNIX file system using full buffering. For unblocked files, the buffer is full after every write and is therefore written immediately, leaving nothing to flush. For blocked files or fully-buffered UNIX file system files, however, the buffer can contain one or more records that have not been flushed and that require a flush operation for them to go to the system.

You can flush buffers to the system in several different ways.

  • If you are using full buffering, z/OS XL C/C++ automatically flushes a buffer when it is filled.
  • If you are using line buffering for a text file or a UNIX file system file, z/OS XL C/C++ flushes a buffer when you complete it with a control character. Except for UNIX file system files, specifying line buffering for a record I/O or binary file has no effect; z/OS XL C/C++ treats the file as if you had specified full buffering.
  • z/OS XL C/C++ flushes buffers to the system when you close a file or end a program.
  • z/OS XL C/C++ flushes buffers to the system when you call the fflush() library function, with the following restrictions:
    • A file opened in text mode does not flush data if a record has not been completed with a new-line.
    • A file opened in fixed format does not flush incomplete records to the file.
    • An FBS file does not flush out a short block unless it is a DISK file opened without the NOSEEK parameter.
  • All streams are flushed across non-POSIX system() calls. Streams are not flushed across POSIX system() calls. For a POSIX system call, we recommend that you do a fflush() before the system() call.

If you are reading a record that another user is writing to at the same time, you can see the new data if you call fflush() to refresh the contents of the input buffer.

Note:
This is not supported for VSAM files.

You may not see output if a program that is using input and output fails, and the error handling routines cannot close all the open files.

Buffering of C streams的更多相关文章

  1. 标准输入输出 stdio 流缓冲 buffering in standard streams

    From : http://www.pixelbeat.org/programming/stdio_buffering/ 译者:李秋豪 我发现找出标准流用的是什么缓冲是一件困难的事. 例如下面这个使用 ...

  2. Gstreamer 中的playback插件

    1. PLAYBACK插件基本介绍 在早期的版本中同时存在playbin和playbin2,但是在最新的版本中,playbin2已经稳定,取代了playbin, playbin不再进行维护.下面是官网 ...

  3. pipe_wait问题_转

    转自:调用Process.waitfor导致的进程挂起 最近遇到pipe_wait问题,父进程调用子进程时,子进程阻塞,cat /proc/$child/wchan输出pipe_wait,进程阻塞在p ...

  4. 用 shell 脚本做自动化测试

    前言 项目中有一个功能,需要监控本地文件系统的变更,例如文件的增.删.改名.文件数据变动等等.之前只在 windows 上有实现,采用的是 iocp + ReadDirectoryChanges 方案 ...

  5. Streams and .NET

    http://www.codeguru.com/csharp/csharp/cs_data/streaming/article.php/c4223/Streams-and-NET.htm In thi ...

  6. Kafka Streams 剖析

    1.概述 Kafka Streams 是一个用来处理流式数据的库,属于Java类库,它并不是一个流处理框架,和Storm,Spark Streaming这类流处理框架是明显不一样的.那这样一个库是做什 ...

  7. What can Reactive Streams offer EE4J?

    https://developer.lightbend.com/blog/2018-02-06-reactive-streams-ee4j/index.html By James Roper (@jr ...

  8. C语言 流缓冲 Stream Buffering

    From : https://www.gnu.org/software/libc/manual/html_node/Stream-Buffering.html 译者:李秋豪 12.20 流缓冲 通常情 ...

  9. One SQL to Rule Them All – an Efficient and Syntactically Idiomatic Approach to Management of Streams and Tables(中英双语)

    文章标题 One SQL to Rule Them All – an Efficient and Syntactically Idiomatic Approach to Management of S ...

随机推荐

  1. C# mongoDB Driver 使用对象方式查询语法大全

    #region 查询方法 /// <summary> /// 获取单个对象 /// </summary> /// <typeparam name="T" ...

  2. [转]Mysql 存储过程和函数区别

    http://blog.csdn.net/wangsifu2009/article/details/6725213 存储过程是用户定义的一系列sql语句的集合,涉及特定表或其它对象的任务,用户可以调用 ...

  3. python全栈开发day49-jquery的位置信息、事件流、事件对象,事件委托,事件绑定和解绑

    一.昨日内容回顾    1. jQuery的属性操作 1) html属性操作:attr 2) DOM属性操作:prop 3) 类样式操作:addClass.removeClass.toggleClas ...

  4. python ThreadLocal

    ThreadLocal: 主要是为了解决各个线程引用全局变量,并且各个线程之间互不影响而设置的. 实例: import threading threadlocal = threading.local( ...

  5. <构建之法>阅读笔记6

    第九章:项目经理 是讲项目经理的作用功能和重要性,书里面主要讲的是微软的PM(Programe Manager)和其他团队PM(Project Manager)的区别,还介绍了PM的能力要求以及人物, ...

  6. 【Java】 剑指offer(27) 二叉树的镜像

    本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 请完成一个函数,输入一个二叉树,该函数输出它的镜像. 思路 画图可 ...

  7. input禁止输入空格

    <input name="" onkeyup="this.value=this.value.replace(/^\s+|\s+$/g,'')" value ...

  8. ESLint + lint-staged 禁用老项目中的es6

    前言 ESLint作为插件化的javascript代码检测工具,为我们的平时的开发保驾护航,好处就不多说了详情查看官网. 问题 有这么一个五年前开发的老项目,机缘巧合到了我们这边来维护. 项目是zep ...

  9. 使用perf工具导致系统hang死的原因

    [perf工具导致系统hang住的原因是触发了低版本kernel的bug] 今天在测试服务器做压测,运行perf record做性能分析时,系统再次hang住了,这次在系统日志中记录了一些有用的信息, ...

  10. RabbitMQ for CentOS安装教程

    一.下载并安装Erlang 下载地址:http://www.erlang.org/downloads otp_src_20.3.tar.gz ①解压otp_src_20.3.tar.gz ②安装各种驱 ...