annotate Paper/src/LocalDGMQueue.cbc @ 9:cc4cb64f9af9

add impl
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Tue, 25 Jan 2022 22:27:11 +0900
parents 25cf5b9b74a2
children a3cda2aa18aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 __code getDataLocalDGMQueue(struct LocalDGMQueue* cQueue, __code next(...), __code whenEOF(...), __code whenError(...)){
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 int recv_size, send_size;
9
cc4cb64f9af9 add impl
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
3 char send_buf;
8
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 union Data* recv_data;
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 recv_size = recv(cQueue->socket, recv_data, sizeof(union Data), 0);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 if (recv_size == -1) {
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 printf("recv error\n");
9
cc4cb64f9af9 add impl
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
9 goto whenEOF(...);
8
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 }
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 if (recv_size == 0) {
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 printf("connection ended\n");
9
cc4cb64f9af9 add impl
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
13 goto next(...);
8
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 }
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 FileString* fileString = NEW(FileString);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 fileString = recv_data;
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 if (fileString->EoF) == 1) {
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 send_buf = 0;
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 send_size = send(cQueue->socket, &send_buf, 1, 0);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if (send_size == -1) {
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 printf("send error\n");
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 }
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 close(cQueue->buffer);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 goto whenEOF(...);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 } else {
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 send_buf = 1;
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 send_size = send(cQueue->socket, &send_buf, 1, 0);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 if (send_size == -1) {
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 printf("send error\n");
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 goto whenError(...);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 Gearef(context, cQueue)->data = recv_data;
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 goto putLocalDGMQueue(recv_data, next);
25cf5b9b74a2 add GearsDGM
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 }