diff --git a/c/ServerNBTHR/ClientSideProc.c b/c/ServerNBTHR/ClientSideProc.c index 3009aa5..cc8b768 100644 --- a/c/ServerNBTHR/ClientSideProc.c +++ b/c/ServerNBTHR/ClientSideProc.c @@ -28,7 +28,8 @@ int main(int argc, char **argv) } in.arg1 = atol(argv[2]); if (squareproc_2(&in, &out, cl) != RPC_SUCCESS) { - printf("%s\n", clnt_perror(cl, argv[1])); + clnt_perror(cl, argv[1]); + //printf("%s\n", clnt_perror(cl, argv[1])); exit(1); } printf("result: %ld\n", out.res1); diff --git a/c/ServerNBTHR/Makefile.square b/c/ServerNBTHR/Makefile.square new file mode 100644 index 0000000..6d19768 --- /dev/null +++ b/c/ServerNBTHR/Makefile.square @@ -0,0 +1,47 @@ + +# This is a template Makefile generated by rpcgen + +# Parameters + +CLIENT = square_client +SERVER = square_server + +SOURCES_CLNT.c = +SOURCES_CLNT.h = +SOURCES_SVC.c = +SOURCES_SVC.h = +SOURCES.x = square.x + +TARGETS_SVC.c = square_svc.c square_server.c square_xdr.c +TARGETS_CLNT.c = square_clnt.c square_client.c square_xdr.c +TARGETS = square.h square_xdr.c square_clnt.c square_svc.c square_client.c square_server.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 + +CPPFLAGS += -D_REENTRANT +CFLAGS += -g +LDLIBS += -lnsl -lpthread + RPCGENFLAGS = + +# 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) + diff --git a/c/ServerNBTHR/ServerSideProc.c b/c/ServerNBTHR/ServerSideProc.c index fe83a1a..71e0800 100644 --- a/c/ServerNBTHR/ServerSideProc.c +++ b/c/ServerNBTHR/ServerSideProc.c @@ -14,13 +14,13 @@ int request = 0; bool_t squareproc_2_svc(square_in * inp, square_out * outp, struct svc_req *rqstp) { - printf("Thread id = '%ld' started, arg = %d\n", pthread_self(), inp->arg1); + printf("Thread id = '%ld' started, arg = %ld\n", pthread_self(), inp->arg1); /* Имитация работы процедуры , выполняемой потоками сервера */ sleep(5); outp->res1 = inp->arg1 * inp->arg1; - printf("Thread id = '%ld' is done %d \n", pthread_self(), outp->res1); + printf("Thread id = '%ld' is done %ld \n", pthread_self(), outp->res1); return (TRUE); } diff --git a/c/ServerNBTHR/run.sh b/c/ServerNBTHR/run.sh index 21ab9d2..21db7bd 100755 --- a/c/ServerNBTHR/run.sh +++ b/c/ServerNBTHR/run.sh @@ -1,7 +1,7 @@ #!/bin/sh -rpcgen -a -M square.x +# rpcgen -a -M square.x gcc -o ServerSQUARE ServerSideProc.c square_svc.c square_xdr.c -lpthread -lnsl -gcc -o ClientSQUARE ClientSideProc.c square_clnt.c square_xdr.c -lprthread -lnsl +gcc -o ClientSQUARE ClientSideProc.c square_clnt.c square_xdr.c -lpthread -lnsl diff --git a/c/ServerNBTHR/square.h b/c/ServerNBTHR/square.h new file mode 100644 index 0000000..813f1e9 --- /dev/null +++ b/c/ServerNBTHR/square.h @@ -0,0 +1,60 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _SQUARE_H_RPCGEN +#define _SQUARE_H_RPCGEN + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +struct square_in { + long arg1; +}; +typedef struct square_in square_in; + +struct square_out { + long res1; +}; +typedef struct square_out square_out; + +#define SQUARE_PROG 0x31230000 +#define SQUARE_VERS 2 + +#if defined(__STDC__) || defined(__cplusplus) +#define SQUAREPROC 1 +extern enum clnt_stat squareproc_2(square_in *, square_out *, CLIENT *); +extern bool_t squareproc_2_svc(square_in *, square_out *, struct svc_req *); +extern int square_prog_2_freeresult (SVCXPRT *, xdrproc_t, caddr_t); + +#else /* K&R C */ +#define SQUAREPROC 1 +extern enum clnt_stat squareproc_2(); +extern bool_t squareproc_2_svc(); +extern int square_prog_2_freeresult (); +#endif /* K&R C */ + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_square_in (XDR *, square_in*); +extern bool_t xdr_square_out (XDR *, square_out*); + +#else /* K&R C */ +extern bool_t xdr_square_in (); +extern bool_t xdr_square_out (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_SQUARE_H_RPCGEN */ diff --git a/c/ServerNBTHR/square.x b/c/ServerNBTHR/square.x new file mode 100644 index 0000000..7a38e93 --- /dev/null +++ b/c/ServerNBTHR/square.x @@ -0,0 +1,11 @@ +struct square_in { + long arg1; +}; +struct square_out { + long res1; +}; +program SQUARE_PROG { + version SQUARE_VERS { + square_out SQUAREPROC(square_in) = 1; + } = 2; +} = 0x31230000; diff --git a/c/ServerNBTHR/square_client.c b/c/ServerNBTHR/square_client.c new file mode 100644 index 0000000..dcf8ef9 --- /dev/null +++ b/c/ServerNBTHR/square_client.c @@ -0,0 +1,48 @@ +/* + * 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 "square.h" + + +void +square_prog_2(char *host) +{ + CLIENT *clnt; + enum clnt_stat retval_1; + square_out result_1; + square_in squareproc_2_arg; + +#ifndef DEBUG + clnt = clnt_create (host, SQUARE_PROG, SQUARE_VERS, "udp"); + if (clnt == NULL) { + clnt_pcreateerror (host); + exit (1); + } +#endif /* DEBUG */ + + retval_1 = squareproc_2(&squareproc_2_arg, &result_1, clnt); + if (retval_1 != RPC_SUCCESS) { + clnt_perror (clnt, "call failed"); + } +#ifndef DEBUG + clnt_destroy (clnt); +#endif /* DEBUG */ +} + + +int +main (int argc, char *argv[]) +{ + char *host; + + if (argc < 2) { + printf ("usage: %s server_host\n", argv[0]); + exit (1); + } + host = argv[1]; + square_prog_2 (host); +exit (0); +} diff --git a/c/ServerNBTHR/square_clnt.c b/c/ServerNBTHR/square_clnt.c new file mode 100644 index 0000000..41f7575 --- /dev/null +++ b/c/ServerNBTHR/square_clnt.c @@ -0,0 +1,19 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include /* for memset */ +#include "square.h" + +/* Default timeout can be changed using clnt_control() */ +static struct timeval TIMEOUT = { 25, 0 }; + +enum clnt_stat +squareproc_2(square_in *argp, square_out *clnt_res, CLIENT *clnt) +{ + return (clnt_call(clnt, SQUAREPROC, + (xdrproc_t) xdr_square_in, (caddr_t) argp, + (xdrproc_t) xdr_square_out, (caddr_t) clnt_res, + TIMEOUT)); +} diff --git a/c/ServerNBTHR/square_server.c b/c/ServerNBTHR/square_server.c new file mode 100644 index 0000000..a618f20 --- /dev/null +++ b/c/ServerNBTHR/square_server.c @@ -0,0 +1,31 @@ +/* + * 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 "square.h" + +bool_t +squareproc_2_svc(square_in *argp, square_out *result, struct svc_req *rqstp) +{ + bool_t retval; + + /* + * insert server code here + */ + + return retval; +} + +int +square_prog_2_freeresult (SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) +{ + xdr_free (xdr_result, result); + + /* + * Insert additional freeing code here, if needed + */ + + return 1; +} diff --git a/c/ServerNBTHR/square_svc.c b/c/ServerNBTHR/square_svc.c index e10fe8b..198416b 100644 --- a/c/ServerNBTHR/square_svc.c +++ b/c/ServerNBTHR/square_svc.c @@ -110,7 +110,7 @@ static void square_prog_2(struct svc_req *rqstp, register SVCXPRT * transp) struct data_str { struct svc_req *rqstp; SVCXPRT *transp; - } *data_ptr = (struct data_str *)malloc(sizeof(struct data_str); { + } *data_ptr = (struct data_str *)malloc(sizeof(struct data_str)); { /* Упаковка данных в структуру для передачи ссылки на нее, diff --git a/c/ServerNBTHR/square_xdr.c b/c/ServerNBTHR/square_xdr.c new file mode 100644 index 0000000..0c2fabe --- /dev/null +++ b/c/ServerNBTHR/square_xdr.c @@ -0,0 +1,26 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "square.h" + +bool_t +xdr_square_in (XDR *xdrs, square_in *objp) +{ + register int32_t *buf; + + if (!xdr_long (xdrs, &objp->arg1)) + return FALSE; + return TRUE; +} + +bool_t +xdr_square_out (XDR *xdrs, square_out *objp) +{ + register int32_t *buf; + + if (!xdr_long (xdrs, &objp->res1)) + return FALSE; + return TRUE; +}