| 112 | } |
| 113 | |
| 114 | static void run(const char *local_addr, const char *peer_addr, |
| 115 | int count, int dlen, int inter, int need_read, int mio_on, int quit) |
| 116 | { |
| 117 | int i; |
| 118 | double spent; |
| 119 | char data[4096]; |
| 120 | struct timeval begin, end; |
| 121 | SOCK_UDP *sock = udp_client_open(local_addr, peer_addr); |
| 122 | |
| 123 | (void) quit; |
| 124 | |
| 125 | if (sock == NULL) { |
| 126 | printf("open_sock error!\r\n"); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | if (dlen > (int) sizeof(data) - 1) |
| 131 | dlen = (int) sizeof(data) - 1; |
| 132 | for (i = 0; i < dlen; i++) |
| 133 | data[i] = 'X'; |
| 134 | data[dlen] = 0; |
| 135 | |
| 136 | gettimeofday(&begin, NULL); |
| 137 | |
| 138 | if (mio_on) |
| 139 | i = mio(sock, peer_addr, dlen, count, inter, need_read); |
| 140 | else |
| 141 | i = sio(sock, data, dlen, count, inter, need_read); |
| 142 | |
| 143 | gettimeofday(&end, NULL); |
| 144 | spent = stamp_sub(&end, &begin); |
| 145 | |
| 146 | printf("thread: %lu, total: %d, curr: %d, spent: %.2f, speed: %.2f\r\n", |
| 147 | (unsigned long) acl_pthread_self(), count, i, spent, |
| 148 | (i * 1000) / (spent > 1 ? spent : 1)); |
| 149 | |
| 150 | printf("thread: %lu, peer addr: %s\r\n", |
| 151 | (unsigned long) acl_pthread_self(), peer_addr); |
| 152 | |
| 153 | udp_close(sock); |
| 154 | } |
| 155 | |
| 156 | typedef struct { |
| 157 | char local[64]; |
no test coverage detected