ServerNBTHR готов =) и собирается успешно гы-гы-гы))
This commit is contained in:
parent
3a281d5581
commit
d0047d5a11
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _SQUARE_H_RPCGEN
|
||||
#define _SQUARE_H_RPCGEN
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#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 */
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#include <memory.h> /* 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));
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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)); {
|
||||
|
||||
/*
|
||||
Упаковка данных в структуру для передачи ссылки на нее,
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue