--- /dev/null
+#!/usr/bin/env python
+# vim: set encoding=utf-8 :
+
+iteraciones = 10
+palabras = ('hola', 'chau', 'bueno', 'malo', 'cosa', 'prueba', 'socket')
+operaciones = ('put', 'find', 'del')
+
+from random import randint, shuffle
+from sys import argv
+
+try:
+ iteraciones = int(argv[1])
+except:
+ pass
+
+for i in xrange(iteraciones):
+ p = list(palabras)
+ shuffle(p)
+ p = p[0:randint(1, len(p)-1)]
+ print operaciones[randint(0, len(operaciones)-1)],
+ for pal in p:
+ print pal,
+ print
+
--- /dev/null
+#!/bin/sh
+
+./gentest.py | ./client &
+./gentest.py | ./client &
+./gentest.py | ./client &
+./gentest.py | ./client &
--- /dev/null
+
+# This is a template Makefile generated by rpcgen
+
+# Parameters
+
+CLIENT = set_client
+SERVER = set_server
+
+SOURCES_CLNT.c =
+SOURCES_CLNT.h =
+SOURCES_SVC.c =
+SOURCES_SVC.h =
+SOURCES.x = set.x
+
+TARGETS_SVC.c = set_svc.c set_server.cpp set_xdr.c
+TARGETS_CLNT.c = set_clnt.c set_client.cpp set_xdr.c
+TARGETS = set.h set_xdr.c set_clnt.c set_svc.c set_server.c set_client.c
+
+OBJECTS_CLNT = $(SOURCES_CLNT.c:%.c=%.o) $(TARGETS_CLNT.c:%.c=%.o)
+OBJECTS_SVC = $(SOURCES_SVC.c:%.c=%.o) $(TARGETS_SVC.c:%.c=%.o)
+# Compiler flags
+
+CFLAGS += -g -Wall -I../common
+LDLIBS += -lnsl ../common/common.a
+CC=g++
+RPCGENFLAGS = -a -N
+
+# Targets
+
+all : $(CLIENT) $(SERVER)
+
+$(TARGETS) : $(SOURCES.x)
+ rpcgen $(RPCGENFLAGS) $(SOURCES.x)
+
+$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) $(TARGETS_CLNT.c)
+
+$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) $(TARGETS_SVC.c)
+
+$(CLIENT) : $(OBJECTS_CLNT)
+ $(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS)
+
+$(SERVER) : $(OBJECTS_SVC)
+ $(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)
+
+#clean:
+# $(RM) core $(TARGETS) $(OBJECTS_CLNT) $(OBJECTS_SVC) $(CLIENT) $(SERVER)
+
--- /dev/null
+#!/usr/bin/env python
+# vim: set encoding=utf-8 :
+
+iteraciones = 10
+palabras = ('hola', 'chau', 'bueno', 'malo', 'cosa', 'prueba', 'socket')
+operaciones = ('put', 'find', 'del')
+
+from random import randint, shuffle
+from sys import argv
+
+try:
+ iteraciones = int(argv[1])
+except:
+ pass
+
+for i in xrange(iteraciones):
+ p = list(palabras)
+ shuffle(p)
+ p = p[0:randint(1, len(p)-1)]
+ print operaciones[randint(0, len(operaciones)-1)],
+ for pal in p:
+ print pal,
+ print
+
--- /dev/null
+/*
+ * Programa para manipular un set con RPC
+ */
+program SETPRG {
+ version SETVERS {
+ /* importa solo el retorno del ultimo mensaje */
+ int PUT(string payload, int id, int end) = 1;
+ int FIND(string payload, int id, int end) = 2;
+ int DEL(string payload, int id, int end) = 3;
+ int QUIT(int id) = 4;
+ } = 1;
+} = 0x20000099;
--- /dev/null
+/*
+ * This is sample code generated by rpcgen.
+ * These are only templates and you can use them
+ * as a guideline for developing your own functions.
+ */
+
+#include "set.h"
+#include "common.h"
+#include <string>
+#include <sstream>
+#include <iostream>
+
+enum { OK, NOT_FOUND, EXISTS };
+
+int
+main(int argc, char *argv[])
+{
+ int client_id;
+ char *server_name;
+ char *localhost = "localhost";
+ pid_t pid;
+ CLIENT* cl;
+ const char *pname = argv[0];
+
+ // mostrar el pid del cliente
+ pid = getpid();
+ print_msg(stdout, "%s Cliente con pid = %d\n", pname, pid);
+
+ if (argc > 1)
+ server_name = argv[1];
+ else
+ server_name = localhost;
+
+ // id del cliente, por default calculado en base al pid
+ if (argc > 2)
+ client_id = atoi(argv[2]);
+ else
+ client_id = pid % 32;
+
+
+ /* Crear el "handle" del cliente para llamar MESSAGEPROG en el
+ * server. Usamos "udp" para la comunicacion. */
+ cl = clnt_create(server_name, SETPRG, SETVERS, "udp");
+ if (cl == NULL)
+ {
+ /* No se pudo hacer contacto error y adios. */
+ clnt_pcreateerror(server_name);
+ exit(1);
+ }
+
+ std::string line;
+ int* (*rem_proc)(char*, int, int, CLIENT*);
+ while (std::getline(std::cin, line))
+ {
+ std::istringstream iss(line);
+ std::string token;
+ if (!(iss >> token)) return 0;
+ if (token == "put")
+ {
+ rem_proc = put_1;
+ print_msg(stdout, "%s (%d): llamando a PUT:", pname, pid);
+ }
+ else if (token == "find")
+ {
+ rem_proc = find_1;
+ print_msg(stdout, "%s (%d): llamando a FIND:", pname, pid);
+ }
+ else if (token == "del")
+ {
+ rem_proc = del_1;
+ print_msg(stdout, "%s (%d): llamando a DEL:", pname, pid);
+ }
+ else
+ {
+ print_msg(stderr, "%s (%d): Invalid token %s!\n", pname, pid, token.c_str());
+ exit(1);
+ }
+ while (iss >> token)
+ {
+ /* llamar al procedure en el server */
+ int* r = rem_proc((char*)token.c_str(), client_id, 0, cl);
+ if (r == NULL)
+ {
+ /* error durante la comunicacion. */
+ clnt_perror(cl, server_name);
+ exit(1);
+ }
+ print_msg(stdout, " %s", token.c_str());
+ }
+ print_msg(stdout, "\n");
+ int* r = rem_proc("", client_id, 1, cl);
+ if (r == NULL)
+ {
+ /* error durante la comunicacion. */
+ clnt_perror(cl, server_name);
+ exit(1);
+ }
+ print_msg(stdout, "%s (%d): el server responde %d\n", pname, pid, *r);
+ }
+
+ int* r = quit_1(client_id, cl);
+ if (r == NULL)
+ {
+ /* error durante la comunicacion. */
+ clnt_perror(cl, server_name);
+ exit(1);
+ }
+
+ exit (0);
+}
+
+// vim: set et sw=4 sts=4 :
--- /dev/null
+/*
+ * This is sample code generated by rpcgen.
+ * These are only templates and you can use them
+ * as a guideline for developing your own functions.
+ */
+
+#include "set.h"
+#include "common.h"
+#include <set>
+#include <map>
+#include <string>
+#include <cstdlib>
+#include <cstdio>
+
+std::map< int, std::set< std::string > > sets;
+
+enum { OK, NOT_FOUND, EXISTS };
+
+static
+void
+get_file_name(int id, char* fname)
+{
+ sprintf(fname, "cliente_%d", id);
+}
+
+static
+FILE*
+open_file(int id, char* mode)
+{
+ char fname[32];
+ get_file_name(id, fname);
+ FILE* fp = fopen(fname, mode);
+ if (!fp)
+ {
+ perror("Error al abrir archivo");
+ exit(1);
+ }
+ return fp;
+}
+
+static
+void
+write_token(int id, const char* token)
+{
+ FILE* fp = open_file(id, "a");
+ if (fprintf(fp, "%s ", token) != (signed)strlen(token)+1)
+ {
+ perror("Error al escribir archivo");
+ exit(1);
+ }
+ fclose(fp);
+}
+
+int *
+put_1_svc(char *payload, int id, int end, struct svc_req *rqstp)
+{
+ static int result;
+
+ result = OK;
+ write_token(id, payload);
+ print_msg(stdout, "%d: recibido PUT '%s', end=%d\n", id, payload, end);
+ if (end)
+ {
+ FILE* fp = open_file(id, "r");
+ std::string buffer;
+ char token[256];
+ while (fscanf(fp, "%s", token) != EOF)
+ buffer += token;
+ fclose(fp);
+ print_msg(stdout, "%d: procesando PUT '%s'\n", id, buffer.c_str());
+ if (sets[id].find(buffer) == sets[id].end())
+ sets[id].insert(buffer);
+ else
+ result = EXISTS;
+ get_file_name(id, token);
+ remove(token); // Elimino archivo temporal
+ }
+
+ return &result;
+}
+
+int *
+find_1_svc(char *payload, int id, int end, struct svc_req *rqstp)
+{
+ static int result;
+
+ result = OK;
+ write_token(id, payload);
+ print_msg(stdout, "%d: recibido FIND '%s', end=%d\n", id, payload, end);
+ if (end)
+ {
+ FILE* fp = open_file(id, "r");
+ std::string buffer;
+ char token[256];
+ while (fscanf(fp, "%s", token) != EOF)
+ buffer += token;
+ fclose(fp);
+ print_msg(stdout, "%d: procesando FIND '%s'\n", id, buffer.c_str());
+ if (sets[id].find(buffer) == sets[id].end())
+ result = NOT_FOUND;
+ get_file_name(id, token);
+ remove(token); // Elimino archivo temporal
+ }
+
+ return &result;
+}
+
+int *
+del_1_svc(char *payload, int id, int end, struct svc_req *rqstp)
+{
+ static int result;
+
+ result = OK;
+ write_token(id, payload);
+ print_msg(stdout, "%d: recibido DEL '%s', end=%d\n", id, payload, end);
+ if (end)
+ {
+ FILE* fp = open_file(id, "r");
+ std::string buffer;
+ char token[256];
+ while (fscanf(fp, "%s", token) != EOF)
+ buffer += token;
+ fclose(fp);
+ print_msg(stdout, "%d: procesando DEL '%s'\n", id, buffer.c_str());
+ if (!sets[id].erase(buffer))
+ result = NOT_FOUND;
+ get_file_name(id, token);
+ remove(token); // Elimino archivo temporal
+ }
+
+ return &result;
+}
+
+int *
+quit_1_svc(int id, struct svc_req *rqstp)
+{
+ static int result;
+
+ result = OK;
+ print_msg(stdout, "%d: recibido QUIT, limpiando set\n", id);
+ if (!sets.erase(id))
+ result = NOT_FOUND;
+
+ return &result;
+}
+
+// vim: set et sw=4 sts=4 :
--- /dev/null
+#!/bin/sh
+
+./gentest.py | ./set_client &
+./gentest.py | ./set_client &
+./gentest.py | ./set_client &
+./gentest.py | ./set_client &