This server binary has the following problems:
 * uses the "bottom level" API with RPC_ANYFD parameter (it violates the API)
 * the clients of tirpc_svc_5 use not only the UDP protocol, but TCP too. But 
the
   server does not listen a TCP port.

Fixed them.

Signed-off-by: Stanislav Kholmanskikh <[email protected]>
---
 .../rpc-tirpc/tests_pack/tirpc_svc_5/tirpc_svc_5.c |   80 ++++++++++++++++----
 1 files changed, 66 insertions(+), 14 deletions(-)

diff --git 
a/testcases/network/rpc/rpc-tirpc/tests_pack/tirpc_svc_5/tirpc_svc_5.c 
b/testcases/network/rpc/rpc-tirpc/tests_pack/tirpc_svc_5/tirpc_svc_5.c
index d75e2eb..c899d0f 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/tirpc_svc_5/tirpc_svc_5.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/tirpc_svc_5/tirpc_svc_5.c
@@ -1,5 +1,6 @@
 /*
 * Copyright (c) Bull S.A.  2007 All Rights Reserved.
+* Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
@@ -34,42 +35,93 @@
 #include <tirpc/rpc/svc.h>
 #include <errno.h>
 #include <netinet/in.h>
+#include <unistd.h>
+#include "librpc-tirpc.h"
 
 #define VERSNUM 1
 #define PROCSIMPLEPING 1
 
+struct server_def_t {
+       SVCXPRT *transp;
+       struct netconfig *nconf;
+       char netid[4];
+       int domain;
+       int type;
+       int sock;
+       SVCXPRT *(*svc_func)(const int, const u_int, const u_int);
+};
+
+static struct server_def_t server_defs[] = {
+       { NULL, NULL, "tcp", AF_INET, SOCK_STREAM, -1, svc_vc_create },
+       { NULL, NULL, "udp", AF_INET, SOCK_DGRAM, -1, svc_dg_create },
+};
+
+static int server_instances = sizeof(server_defs) / sizeof(*server_defs);
+
 static void exm_proc(struct svc_req *rqstp, SVCXPRT *transp);
 
 int main(int argn, char *argc[])
 {
        int progNum = atoi(argc[1]);
-       SVCXPRT *transp = NULL;
-       struct netconfig *nconf;
+       int i;
+       struct server_def_t *this;
 
        svc_unreg(progNum, VERSNUM);
 
-       if ((nconf = getnetconfigent("udp")) == NULL) {
-               fprintf(stderr, "Cannot get netconfig entry for UDP\n");
-               exit(1);
-       }
+       for (i = 0; i < server_instances; i++) {
+               this = &(server_defs[i]);
 
-       transp = svc_vc_create(RPC_ANYFD, 1024, 1024);
+               this->nconf = getnetconfigent(this->netid);
+               if (this->nconf == NULL) {
+                       fprintf(stderr, "Cannot get a netconfig entry for %s",
+                               this->netid);
+                       goto cleanup;
+               }
 
-       if (transp == NULL) {
-               fprintf(stderr, "Cannot create service.\n");
-               exit(1);
-       }
+               this->sock = bound_socket(this->domain, this->type);
+               if (this->sock < 0) {
+                       perror("bound_socket() failed");
+                       goto cleanup;
+               }
 
-       if (!svc_reg(transp, progNum, VERSNUM, exm_proc, nconf)) {
-               fprintf(stderr, "svc_reg failed!!\n");
-               exit(1);
+               if (this->type == SOCK_STREAM) {
+                       if (listen(this->sock, 10) < 0) {
+                               perror("listen() failed");
+                               goto cleanup;
+                       }
+               }
+
+               this->transp = this->svc_func(this->sock, 1024, 1024);
+               if (this->transp == NULL) {
+                       fprintf(stderr, "Cannot create service.\n");
+                       goto cleanup;
+               }
+
+               if (!svc_reg(this->transp, progNum, VERSNUM,
+                               exm_proc, this->nconf)) {
+                       fprintf(stderr, "svc_reg failed!!\n");
+                       goto cleanup;
+               }
        }
 
+
        svc_run();
 
        fprintf(stderr, "svc_run() returned.  ERROR has occurred.\n");
+
+cleanup:
        svc_unreg(progNum, VERSNUM);
 
+       for (i = 0; i < server_instances; i++) {
+               this = &(server_defs[i]);
+
+               if (this->transp != NULL)
+                       svc_destroy(this->transp);
+
+               if (this->sock >= 0)
+                       close(this->sock);
+       }
+
        return 1;
 }
 
-- 
1.7.1


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to