12 int main(int argc, char *argv[])
15 int sockfd;/* socket que sirve como template */
16 pid_t pid; /* pid del server iterativo */
17 char fin = 0, fin_cmd = 0;
19 std::set< std::string > set;
24 /* Verifico parametros de linea de comando */
26 sockfd = atoi(argv[1]);
29 perror("Falta parametro con fd");
33 print_msg(stdout, "%s (%d): atendiendo a cliente por socket %d\n", pname, pid, sockfd);
41 int n = libtcp_receive_bin(sockfd, (char*) &proto, sizeof(Protocol));
44 print_msg(stdout, "%s (%d): error en recibir\n", pname, pid);
47 print_msg(stdout, "%s (%d): cliente %d envio operacion (%d, %d, %s)\n",
48 pname, pid, proto.client_id, proto.type, proto.end, proto.payload);
50 buffer += proto.payload;
51 print_msg(stdout, "%s (%d): buffer: %s\n", pname, pid, buffer.c_str());
58 if (set.find(buffer) == set.end())
61 result = Protocol::OK;
64 result = Protocol::EXISTS;
67 if (set.find(buffer) == set.end())
68 result = Protocol::NOT_FOUND;
70 result = Protocol::OK;
73 if (set.erase(buffer))
74 result = Protocol::OK;
76 result = Protocol::NOT_FOUND;
79 result = Protocol::OK;
80 print_msg(stdout, "%s (%d): Say no more\n", pname, pid);
85 print_msg(stderr, "%s (%d): Operacion no soportada\n", pname, pid);
94 libtcp_send(sockfd, (char*) &result, sizeof(int));
95 print_msg(stdout, "%s (%d) FIN (resultado = %d)\n", pname, pid, result);
102 // vim: set et sw=4 sts=4 :