Mercurial > hg > Papers > 2021 > ikki-sigos
view Paper/codes/wc/UnixChrisFileImpl.cpp @ 19:2d91b4d2569c
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 05 May 2021 18:43:47 +0900 |
parents | |
children | 218abc95edeb |
line wrap: on
line source
#include <stdio.h> #impl "Wc.h" as "WcChrsImpl.h" typedef struct UnixFileImpl <> ipml File { int fd; // unix file descriptor int mode; Data *fileImpl ; __code setOutput(UnixFileImpl* file, Output *output,__code next(...)) ; __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) ; __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) ; } File; File* createUnixChrisFileImpl(struct Context* context) { File *file = new File(); file->ChrisFileImpl = (union Data*)new ChrisFileImpl(); return file; } // Topology manageres determins input / output connection // __code setOutput(Wc* wc, Output *output,__code next(...)) { file->reader = output ; goto next(...); } int putBlock(UnixFileImpl* file, Output *reader) { Block *block = new Block(); int len = read(fd, BUFSIZE, block->data); if (len <=0 ) { block->eof |= BLOCK_FLAG_EOF; return 0; } reader->put(block); return 1 ; } __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) { file->fd = open(key->path,unix_mode(key->modde)); if (fd < 0) { goto error("can't open"); } if (putBlock(file,reader)) { putBlock(file,reader); } goto next(file,...); } __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { if (!ack->isOk) { close(fd); goto next(...); } putBlock(file,reader); goto next(...); // file is automaticaly put into local dataGearManger/input }