home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / pipes < prev    next >
Encoding:
Text File  |  1991-08-27  |  2.9 KB  |  106 lines

  1. Path: wugate!wucs1!uunet!allbery
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Newsgroups: comp.sources.misc
  4. Subject: v06i069: bug fix in pipes.c of byte benchmark
  5. Message-ID: <328@ssp2.idca.tds.philips.nl>
  6. Date: 21 Mar 89 01:51:07 GMT
  7. Sender: allbery@uunet.UU.NET
  8. Reply-To: pb@idca.tds.PHILIPS.nl (Peter Brouwer)
  9. Organization: Philips Telecommunication and Data Systems, The Netherlands
  10. Lines: 93
  11. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  12.  
  13. Posting-number: Volume 6, Issue 69
  14. Submitted-by: pb@idca.tds.PHILIPS.nl (Peter Brouwer)
  15. Archive-name: pipes
  16.  
  17. A few month a received a set of sources of the second byte benchmark.
  18. One of the tests is a pipe throughput test.
  19. This source file contains a bug. 
  20. The test was done as follows:
  21.  
  22.         open pipe;
  23.         fork;
  24.         if child ( read n times x bytes )
  25.         if parent ( write n times x byte )
  26.  
  27. This may not always work. When reading from a pipe not the same number of bytes
  28. may be received as is written on the other side in one write read pair.
  29. So we changed the receive loop so that the total number of bytes to be received
  30. is used in the receive loop.
  31. Below is the modified source.
  32.  
  33. #  Peter Brouwer,                     ##
  34. #  Philips TDS, Dept SSP-V2           ## voice +31 55 432523
  35. #  P.O. Box 245                       ## UUCP address ..!mcvax!philapd!pb
  36. #  7300 AE Apeldoorn, The Netherlands ## Internet pb@idca.tds.philips.nl
  37. -----Cut Here-----Cut Here-----Cut Here-----Cut Here-----
  38. : #!/bin/sh
  39. : # shar:    Shell Archiver
  40. : #    Run the following text with /bin/sh to create:
  41. : #    pipes.c
  42. echo shar extracting: pipes.c
  43. sed 's/^X//' << '!FUNKY!FUNKY!STUFF!' > pipes.c
  44. X/* File: pipes.c - created by Marty Leisner */
  45. X/* leisner.Henr         1-Dec-87  8:55:04 */
  46. X
  47. X/* Copyright (C) 1987 by Martin Leisner. All rights reserved. */
  48. X
  49. X#ifndef    BLOCK_SIZE
  50. X#define BLOCK_SIZE     1000
  51. X#endif    /* BLOCK_SIZE */
  52. X
  53. X#define NUM_BLOCKS    1000
  54. Xchar buffer[BLOCK_SIZE];
  55. X
  56. Xmain()
  57. X{
  58. X    int pipefd[2];
  59. X    register int i;
  60. X    register int j;
  61. X    register int k;
  62. X    pipe(&pipefd);
  63. X    
  64. X    
  65. X    
  66. X    switch(fork()) {
  67. X        case 0:
  68. X            /* child code */
  69. X            for(i = 0, j=BLOCK_SIZE*NUM_BLOCKS; j>0 ; i++) {
  70. X                if((k = read(pipefd[0], &buffer, BLOCK_SIZE)) < 0)
  71. X                    break;
  72. X                j -= k;
  73. X            }
  74. X            printf("child done, i = %d\n", i);
  75. X            exit();
  76. X            break;
  77. X        case -1:
  78. X            perror("fork broke");
  79. X            exit();
  80. X        default:
  81. X            /* parent code */
  82. X            for(i = 0; i < NUM_BLOCKS; i++)
  83. X                if    (write(pipefd[1], &buffer, BLOCK_SIZE) != BLOCK_SIZE)
  84. X                    break;
  85. X                
  86. X            puts("parent done");
  87. X            wait((char *) 0);
  88. X            break;
  89. X    }
  90. X    return 0;
  91. X}
  92. X
  93. !FUNKY!FUNKY!STUFF!
  94. echo 'Orignal Sum -> 60843 2 pipes.c'
  95. echo -n 'Current Sum -> '
  96. sum pipes.c
  97. exit 0
  98. -- 
  99. #  Peter Brouwer,                     ##
  100. #  Philips TDS, Dept SSP-V2           ## voice +31 55 432523
  101. #  P.O. Box 245                       ## UUCP address ..!mcvax!philapd!pb
  102. #  7300 AE Apeldoorn, The Netherlands ## Internet pb@idca.tds.philips.nl
  103.  
  104.  
  105. ----- End Forwarded Message -----
  106.