2 * This is sample code generated by rpcgen.
3 * These are only templates and you can use them
4 * as a guideline for developing your own functions.
15 std::map< int, std::set< std::string > > sets;
17 enum { OK, NOT_FOUND, EXISTS };
21 get_file_name(int id, char* fname)
23 sprintf(fname, "cliente_%d", id);
28 open_file(int id, char* mode)
31 get_file_name(id, fname);
32 FILE* fp = fopen(fname, mode);
35 perror("Error al abrir archivo");
43 write_token(int id, const char* token)
45 FILE* fp = open_file(id, "a");
46 if (fprintf(fp, "%s ", token) != (signed)strlen(token)+1)
48 perror("Error al escribir archivo");
55 put_1_svc(char *payload, int id, int end, struct svc_req *rqstp)
60 write_token(id, payload);
61 print_msg(stdout, "%d: recibido PUT '%s', end=%d\n", id, payload, end);
64 FILE* fp = open_file(id, "r");
67 while (fscanf(fp, "%s", token) != EOF)
70 print_msg(stdout, "%d: procesando PUT '%s'\n", id, buffer.c_str());
71 if (sets[id].find(buffer) == sets[id].end())
72 sets[id].insert(buffer);
75 get_file_name(id, token);
76 remove(token); // Elimino archivo temporal
83 find_1_svc(char *payload, int id, int end, struct svc_req *rqstp)
88 write_token(id, payload);
89 print_msg(stdout, "%d: recibido FIND '%s', end=%d\n", id, payload, end);
92 FILE* fp = open_file(id, "r");
95 while (fscanf(fp, "%s", token) != EOF)
98 print_msg(stdout, "%d: procesando FIND '%s'\n", id, buffer.c_str());
99 if (sets[id].find(buffer) == sets[id].end())
101 get_file_name(id, token);
102 remove(token); // Elimino archivo temporal
109 del_1_svc(char *payload, int id, int end, struct svc_req *rqstp)
114 write_token(id, payload);
115 print_msg(stdout, "%d: recibido DEL '%s', end=%d\n", id, payload, end);
118 FILE* fp = open_file(id, "r");
121 while (fscanf(fp, "%s", token) != EOF)
124 print_msg(stdout, "%d: procesando DEL '%s'\n", id, buffer.c_str());
125 if (!sets[id].erase(buffer))
127 get_file_name(id, token);
128 remove(token); // Elimino archivo temporal
135 quit_1_svc(int id, struct svc_req *rqstp)
140 print_msg(stdout, "%d: recibido QUIT, limpiando set\n", id);
147 // vim: set et sw=4 sts=4 :