Mercurial > hg > Members > ikki > CbC_log
view wc_sigos/UnixChrisFileImpl.cpp @ 5:7599728af8ba default tip
add wc
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 19 Jun 2021 07:24:43 +0900 |
parents | |
children |
line wrap: on
line source
#include <stdio.h> #impl "UnixCharImpl.h" as "UnixCharImpl.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 // // Topology manageres determins input / output connection // __code gearsConnect(Wc* wc, Input *input, Output *output,__code next(...)) { file->reader = output ; input->add(&file->ack,"ack"); 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; close(file->fd); 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(...); } __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { if (!ack->isOk) { close(file->fd); goto next(...); } putBlock(file,reader); goto next(...); // file is automaticaly put into local dataGearManger/input }