Mercurial > hg > Members > ikki > CbC_log
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:d6911fe00127 | 5:7599728af8ba |
---|---|
1 #include <stdio.h> | |
2 #impl "UnixCharImpl.h" as "UnixCharImpl.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 // Topology manageres determins input / output connection | |
22 // | |
23 __code gearsConnect(Wc* wc, Input *input, Output *output,__code next(...)) { | |
24 file->reader = output ; | |
25 input->add(&file->ack,"ack"); | |
26 goto next(...); | |
27 } | |
28 | |
29 int | |
30 putBlock(UnixFileImpl* file, Output *reader) { | |
31 Block *block = new Block(); | |
32 int len = read(fd, BUFSIZE, block->data); | |
33 if (len <=0 ) { | |
34 block->eof |= BLOCK_FLAG_EOF; | |
35 close(file->fd); | |
36 return 0; | |
37 } | |
38 reader->put(block); | |
39 return 1 ; | |
40 } | |
41 | |
42 __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) { | |
43 file->fd = open(key->path,unix_mode(key->modde)); | |
44 if (fd < 0) { | |
45 goto error("can't open"); | |
46 } | |
47 if (putBlock(file,reader)) { | |
48 putBlock(file,reader); | |
49 } | |
50 goto next(...); | |
51 } | |
52 | |
53 __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { | |
54 if (!ack->isOk) { | |
55 close(file->fd); | |
56 goto next(...); | |
57 } | |
58 putBlock(file,reader); | |
59 goto next(...); // file is automaticaly put into local dataGearManger/input | |
60 } | |
61 |