Changeset ef6d059 for benchmark/io/sendfile
- Timestamp:
- Feb 15, 2022, 2:49:43 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 1a0b600
- Parents:
- da81b849
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/sendfile/consumer.c
rda81b849 ref6d059 86 86 printf( "actial port: %d\n", ntohs(address.sin_port) ); 87 87 88 ret = listen( listenfd, 0);88 ret = listen( listenfd, 1 ); 89 89 if(ret < 0) { 90 90 fprintf( stderr, "listen error: (%d) %s\n", (int)errno, strerror(errno) ); … … 92 92 } 93 93 94 struct sockaddr_in cli_addr; 95 __socklen_t clilen = sizeof(cli_addr); 96 int fd = accept( listenfd, (struct sockaddr *) &cli_addr, &clilen ); 97 if(fd < 0) { 98 fprintf( stderr, "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 99 exit( ACCEPT_ERROR ); 94 for(int i = 0; i < 2; i++) { 95 struct sockaddr_in cli_addr; 96 __socklen_t clilen = sizeof(cli_addr); 97 int fd = accept( listenfd, (struct sockaddr *) &cli_addr, &clilen ); 98 if(fd < 0) { 99 fprintf( stderr, "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 100 exit( ACCEPT_ERROR ); 101 } 102 103 int error = 0; 104 size_t calls = 0; 105 size_t bytes = 0; 106 107 struct timespec after, before; 108 109 clock_gettime(CLOCK_MONOTONIC, &before); 110 111 for(;;) { 112 ret = recv(fd, buffer, buffer_len, 0); 113 if(ret == 0 ) goto EXIT; 114 if(ret < 0 ) { 115 if( errno == EAGAIN || errno == EWOULDBLOCK) continue; 116 if( errno == ECONNRESET ) { printf("Connection reset\n"); goto EXIT; } 117 if( errno == EPIPE ) { printf("Pipe closed\n"); goto EXIT; } 118 fprintf( stderr, "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 119 error = READ_ERROR; 120 goto EXIT; 121 } 122 calls++; 123 bytes += ret; 124 } 125 EXIT:; 126 127 clock_gettime(CLOCK_MONOTONIC, &after); 128 129 uint64_t tb = ((int64_t)before.tv_sec * TIMEGRAN) + before.tv_nsec; 130 uint64_t ta = ((int64_t)after.tv_sec * TIMEGRAN) + after.tv_nsec; 131 double secs = ((double)ta - tb) / TIMEGRAN; 132 133 printf("Received %'zu bytes in %'zu reads, %f seconds\n", bytes, calls, secs); 134 printf(" - %'3.3f bytes per second\n", (((double)bytes) / secs)); 135 printf(" - %'3.3f bytes per calls\n", (((double)bytes) / calls)); 136 137 close(fd); 138 if(error != 0) exit( error ); 100 139 } 101 102 int error = 0;103 size_t calls = 0;104 size_t bytes = 0;105 106 struct timespec after, before;107 108 clock_gettime(CLOCK_MONOTONIC, &before);109 110 for(;;) {111 ret = recv(fd, buffer, buffer_len, 0);112 if(ret == 0 ) goto EXIT;113 if(ret < 0 ) {114 if( errno == EAGAIN || errno == EWOULDBLOCK) continue;115 if( errno == ECONNRESET ) { printf("Connection reset\n"); goto EXIT; }116 if( errno == EPIPE ) { printf("Pipe closed\n"); goto EXIT; }117 fprintf( stderr, "accept error: (%d) %s\n", (int)errno, strerror(errno) );118 error = READ_ERROR;119 goto EXIT;120 }121 calls++;122 bytes += ret;123 }124 EXIT:;125 126 clock_gettime(CLOCK_MONOTONIC, &after);127 128 uint64_t tb = ((int64_t)before.tv_sec * TIMEGRAN) + before.tv_nsec;129 uint64_t ta = ((int64_t)after.tv_sec * TIMEGRAN) + after.tv_nsec;130 double secs = ((double)ta - tb) / TIMEGRAN;131 132 printf("Received %'zu bytes in %'zu reads, %f seconds\n", bytes, calls, secs);133 printf(" - %'3.3f bytes per second\n", (((double)bytes) / secs));134 printf(" - %'3.3f bytes per calls\n", (((double)bytes) / calls));135 136 140 close(listenfd); 137 close(fd); 138 return error; 141 return 0; 139 142 }
Note: See TracChangeset
for help on using the changeset viewer.