Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/writer.c @ 841:2432c7fe291c
dynamic loading demo bug fix
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Jun 2010 01:39:15 +0900 |
parents | 0decff4e867b |
children |
rev | line source |
---|---|
583 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <unistd.h> | |
5 #include <arpa/inet.h> | |
584 | 6 #include <sys/stat.h> |
7 #include <sys/mman.h> | |
583 | 8 |
9 #include "lindaapi.h" | |
10 | |
11 #define PORT 10000 | |
12 | |
584 | 13 #define SERIAL_REGIST_TUPLE_NO 1 |
583 | 14 |
15 void | |
584 | 16 mainLoop(int tid, int write_id, int fd) |
583 | 17 { |
584 | 18 void *addr; |
19 struct stat sb; | |
583 | 20 |
584 | 21 if (fstat(fd, &sb) == -1) { |
22 perror("fstat"); | |
23 exit(1); | |
24 } | |
25 addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | |
26 if (addr==NULL) { | |
27 perror("mmap"); | |
28 exit(1); | |
583 | 29 } |
30 | |
584 | 31 printf("file size=%lld\n", sb.st_size); |
583 | 32 |
584 | 33 psx_out(tid, write_id, (unsigned char *)addr, sb.st_size); |
34 psx_sync_n(); | |
583 | 35 |
36 return; | |
37 } | |
38 | |
584 | 39 int get_serial_id(int tid) { |
40 char *data; | |
41 int serial; | |
42 int seq; | |
43 | |
44 seq = psx_in(tid, 65535); | |
45 do { | |
46 psx_sync_n(); | |
47 data = (char *)psx_reply(seq); | |
48 } while(data==0); | |
49 serial = atoi(data + LINDA_HEADER_SIZE); | |
50 psx_free(data); | |
51 | |
52 return serial; | |
53 } | |
54 | |
55 void send_serial_id(int tid, int serial_id) { | |
56 int safe_id = htonl(serial_id); | |
57 | |
58 psx_out(tid, SERIAL_REGIST_TUPLE_NO, (unsigned char *)&safe_id, sizeof(safe_id)); | |
59 psx_sync_n(); | |
60 } | |
583 | 61 |
62 int | |
63 main(int argc, char *argv[]) { | |
64 int tspace; | |
584 | 65 int serial; |
66 int xml_id; | |
841
2432c7fe291c
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
67 char *linda_serv = (char *)"localhost"; |
584 | 68 if (argc > 1) |
69 linda_serv = argv[1]; | |
583 | 70 init_linda(); |
584 | 71 tspace = open_linda_java(linda_serv, PORT); |
583 | 72 printf("open socket (tupple space id) = %d\n", tspace); |
584 | 73 serial = get_serial_id(tspace); |
74 xml_id = serial * 10; | |
75 mainLoop(tspace, xml_id, fileno(stdin)); | |
76 sleep(1); | |
77 send_serial_id(tspace, serial); | |
78 printf("send xml_id = %d, seciral = %d\n",xml_id, serial); | |
583 | 79 exit(EXIT_SUCCESS); |
80 } | |
81 | |
82 /* end */ |