comparison Paper/codes/wc/UnixFileImpl.cpp @ 21:218abc95edeb

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 06 May 2021 15:49:36 +0900
parents
children
comparison
equal deleted inserted replaced
20:5b8d3386f939 21:218abc95edeb
1 #include <stdio.h>
2 #impl UnixFileImp as "UnixFileImpl.h"
3
4
5 File* createUnixFileImpl(struct Context* context) {
6 File *file = new File();
7 file->FileImpl = (union Data*)new FileImpl();
8 return file;
9 }
10
11 readBlock(UnixFileImpl* file) {
12 Block *block = new Block();
13 int len = read(fd, BUFSIZE, block->data);
14 block->eof &= ~BLOCK_FLAG_EOF;
15 if (len <=0 ) {
16 block->eof |= BLOCK_FLAG_EOF;
17 close(file->fd);
18 }
19 return block ;
20 }
21
22 __code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...));
23 file->fd = open(key->path,unix_mode(key->modde));
24 if (fd < 0) {
25 goto error("can't open");
26 }
27 goto next(readBlock(file), ...);
28 }
29
30 __code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...));
31 if (!ack->isOk) {
32 close(file->fd);
33 goto next(...);
34 }
35 goto next(readBlock(file), ...); // file is automaticaly put into local dataGearManger/input
36 }
37