linux-scalability-benchmarks / libowfat / test / io2.c

The default branch has multiple heads

#include "io.h"

char buf[65536];
int64 readpos = 0;
int64 writepos = 0;
int flageof = 0;

int main()
{
  int64 r;

  if (!io_fd(0)) return 111;
  if (!io_fd(1)) return 111;

  for (;;) {
    if (flageof && writepos >= readpos) return 0;

    if (!flageof && readpos < sizeof buf) io_wantread(0);
    if (writepos < readpos) io_wantwrite(1);
    io_wait();
    if (!flageof && readpos < sizeof buf) io_dontwantread(0);
    if (writepos < readpos) io_dontwantwrite(1);

    if (!flageof && readpos < sizeof buf) {
      r = io_tryread(0,buf + readpos,sizeof buf - readpos);
      if (r <= -2) return 111; /* read error other than EAGAIN */
      if (r == 0) flageof = 1;
      if (r > 0) readpos += r;
    }

    if (writepos < readpos) {
      r = io_trywrite(1,buf + writepos,readpos - writepos);
      if (r <= -2) return 111; /* write error other than EAGAIN */
      if (r > 0) {
	writepos += r;
	if (writepos == readpos) readpos = writepos = 0;
	/* if writepos is big, might want to left-shift buffer here */
      }
    }
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.