home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / test / io / bmi / test-bmi-s2s-b.c < prev    next >
C/C++ Source or Header  |  2009-08-14  |  3KB  |  154 lines

  1. /*
  2.  * (C) 2001 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <errno.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include "pvfs2.h"
  14. #include "bmi.h"
  15. #include "test-bmi.h"
  16. #include "gossip.h"
  17.  
  18. /**************************************************************
  19.  * Data structures 
  20.  */
  21.  
  22. /**************************************************************/
  23.  
  24. int main(
  25.     int argc,
  26.     char **argv)
  27. {
  28.     char in_buf, out_buf;
  29.     int ret = -1;
  30.     PVFS_BMI_addr_t server_addr;
  31.     bmi_op_id_t client_ops[2];
  32.     int outcount = 0;
  33.     bmi_error_code_t error_code;
  34.     bmi_size_t actual_size;
  35.     bmi_context_id context;
  36.  
  37.     /* set debugging stuff */
  38.     gossip_enable_stderr();
  39.     gossip_set_debug_mask(1, GOSSIP_BMI_DEBUG_ALL);
  40.  
  41.     /* initialize local interface */
  42.     ret = BMI_initialize("bmi_tcp", "tcp://localhost:3381", BMI_INIT_SERVER);
  43.     if (ret < 0)
  44.     {
  45.     errno = -ret;
  46.     perror("BMI_initialize");
  47.     return (-1);
  48.     }
  49.  
  50.     ret = BMI_open_context(&context);
  51.     if (ret < 0)
  52.     {
  53.     errno = -ret;
  54.     perror("BMI_open_context()");
  55.     return (-1);
  56.     }
  57.  
  58.     /* get a bmi_addr for the server */
  59.     ret = BMI_addr_lookup(&server_addr, "tcp://localhost:3380");
  60.     if (ret < 0)
  61.     {
  62.     errno = -ret;
  63.     perror("BMI_addr_lookup");
  64.     return (-1);
  65.     }
  66.  
  67.     /* sleep to let the other instance come up */
  68.     sleep(5);
  69.  
  70.     /* send the initial request on its way */
  71.     ret = BMI_post_send(&(client_ops[1]), server_addr, &out_buf,
  72.                   1, BMI_EXT_ALLOC,
  73.                   0, NULL, context, NULL);
  74.     if (ret < 0)
  75.     {
  76.     errno = -ret;
  77.     perror("BMI_post_send");
  78.     return (-1);
  79.     }
  80.     if (ret == 0)
  81.     {
  82.     /* turning this into a blocking call for testing :) */
  83.     /* check for completion of request */
  84.     do
  85.     {
  86.         ret = BMI_test(client_ops[1], &outcount, &error_code, &actual_size,
  87.                NULL, 10, context);
  88.     } while (ret == 0 && outcount == 0);
  89.  
  90.     if (ret < 0 || error_code != 0)
  91.     {
  92.         fprintf(stderr, "Request send failed.\n");
  93.         if (ret < 0)
  94.         {
  95.         errno = -ret;
  96.         perror("BMI_test");
  97.         }
  98.         return (-1);
  99.     }
  100.     }
  101.  
  102.     /* post a recv for the server acknowledgement */
  103.     ret = BMI_post_recv(&(client_ops[0]), server_addr, &in_buf,
  104.             1, &actual_size, BMI_EXT_ALLOC,
  105.             0, NULL, context, NULL);
  106.     if (ret < 0)
  107.     {
  108.     errno = -ret;
  109.     perror("BMI_post_recv");
  110.     return (-1);
  111.     }
  112.     if (ret == 0)
  113.     {
  114.     /* turning this into a blocking call for testing :) */
  115.     /* check for completion of ack recv */
  116.     do
  117.     {
  118.         ret = BMI_test(client_ops[0], &outcount, &error_code,
  119.                &actual_size, NULL, 10, context);
  120.     } while (ret == 0 && outcount == 0);
  121.  
  122.     if (ret < 0 || error_code != 0)
  123.     {
  124.         fprintf(stderr, "Ack recv failed.\n");
  125.         return (-1);
  126.     }
  127.     }
  128.  
  129.     /* shutdown the local interface */
  130.     BMI_close_context(context);
  131.     ret = BMI_finalize();
  132.     if (ret < 0)
  133.     {
  134.     errno = -ret;
  135.     perror("BMI_finalize");
  136.     return (-1);
  137.     }
  138.  
  139.     /* turn off debugging stuff */
  140.     gossip_disable();
  141.  
  142.     return (0);
  143. }
  144.  
  145.  
  146. /*
  147.  * Local variables:
  148.  *  c-indent-level: 4
  149.  *  c-basic-offset: 4
  150.  * End:
  151.  *
  152.  * vim: ts=8 sts=4 sw=4 expandtab
  153.  */
  154.