Mercurial > hg > Papers > 2021 > ikki-sigos
comparison 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 |
comparison
equal
deleted
inserted
replaced
18:f3112bbff428 | 19:2d91b4d2569c |
---|---|
1 #include <stdio.h> | |
2 #impl "Wc.h" as "WcChrsImpl.h" | |
3 | |
4 typedef struct UnixFileImpl <> ipml File { | |
5 int fd; // unix file descriptor | |
6 int mode; | |
7 Data *fileImpl ; | |
8 __code setOutput(UnixFileImpl* file, Output *output,__code next(...)) ; | |
9 __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) ; | |
10 __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) ; | |
11 } File; | |
12 | |
13 File* createUnixChrisFileImpl(struct Context* context) { | |
14 File *file = new File(); | |
15 file->ChrisFileImpl = (union Data*)new ChrisFileImpl(); | |
16 return file; | |
17 } | |
18 | |
19 // Topology manageres determins input / output connection | |
20 // | |
21 __code setOutput(Wc* wc, Output *output,__code next(...)) { | |
22 file->reader = output ; | |
23 goto next(...); | |
24 } | |
25 | |
26 int | |
27 putBlock(UnixFileImpl* file, Output *reader) { | |
28 Block *block = new Block(); | |
29 int len = read(fd, BUFSIZE, block->data); | |
30 if (len <=0 ) { | |
31 block->eof |= BLOCK_FLAG_EOF; | |
32 return 0; | |
33 } | |
34 reader->put(block); | |
35 return 1 ; | |
36 } | |
37 | |
38 __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) { | |
39 file->fd = open(key->path,unix_mode(key->modde)); | |
40 if (fd < 0) { | |
41 goto error("can't open"); | |
42 } | |
43 if (putBlock(file,reader)) { | |
44 putBlock(file,reader); | |
45 } | |
46 goto next(file,...); | |
47 } | |
48 | |
49 __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { | |
50 if (!ack->isOk) { | |
51 close(fd); | |
52 goto next(...); | |
53 } | |
54 putBlock(file,reader); | |
55 goto next(...); // file is automaticaly put into local dataGearManger/input | |
56 } |