12 int main(int argc, char *argv[])
15 int sockfd;/* socket que sirve como template */
16 pid_t pid; /* pid del server iterativo */
18 char fin = 0, fin_cmd = 0;
20 std::set< std::string > set;
25 /* Verifico parametros de linea de comando */
27 sockfd = atoi(argv[1]);
30 perror("Falta parametro con fd");
34 print_msg(stdout, "%s (%d): atendiendo a cliente por socket %d\n", pname, pid, sockfd);
42 int n = libtcp_receive_bin(sockfd, (char*) &proto, sizeof(Protocol));
45 print_msg(stdout, "%s (%d): error en recibir\n", pname, pid);
48 print_msg(stdout, "%s (%d): cliente %d envio operacion (%d, %d, %d)\n",
49 pname, pid, proto.client_id, proto.type, proto.end, proto.len);
51 n = libtcp_receive_bin(sockfd, linea, proto.len);
54 print_msg(stdout, "%s (%d): error en recibir\n", pname, pid);
57 linea[proto.len] = '\0';
58 print_msg(stdout, "%s (%d): se recibieron %d bytes de payload (%s)\n",
59 pname, pid, proto.len, linea);
61 print_msg(stdout, "%s (%d): buffer: %s\n", pname, pid, buffer.c_str());
68 if (set.find(buffer) == set.end())
71 result = Protocol::OK;
74 result = Protocol::EXISTS;
77 if (set.find(buffer) == set.end())
78 result = Protocol::NOT_FOUND;
80 result = Protocol::OK;
83 if (set.erase(buffer))
84 result = Protocol::OK;
86 result = Protocol::NOT_FOUND;
89 print_msg(stdout, "%s (%d): Say no more\n", pname, pid);
94 print_msg(stderr, "%s (%d): Operacion no soportada\n", pname, pid);
103 libtcp_send(sockfd, (char*) &result, sizeof(int));
104 print_msg(stdout, "%s (%d) FIN (resultado = %d)\n", pname, pid, result);
111 // vim: set et sw=4 sts=4 :