- // update the central counter after every 1MB (8ms
- // at gigabit speeds, should be enough) of received data
- if (bytes_received > 1048576) {
- pthread_mutex_lock(&receive_mutex);
- total_bytes_received += bytes_received;
- pthread_mutex_unlock(&receive_mutex);
+ ret = read(sock, buf, 65536);
+ if (ret == 0) {
+ if (epoll_ctl(ep_fd, EPOLL_CTL_DEL, sock, NULL) == -1) {
+ perror("EPOLL_CTL_DEL");
+ exit(1);
+ }
+ close(sock);
+ continue;
+ }
+
+ bytes_received += ret;
+
+ // update the central counter after every 1MB (8ms
+ // at gigabit speeds, should be enough) of received data
+ if (bytes_received > update_frequency) {
+ pthread_mutex_lock(&receive_mutex);
+ total_bytes_received += bytes_received;
+ pthread_mutex_unlock(&receive_mutex);