static int rep_send_all_packets(replication *r,uint32_t msecto) { uint8_t i,l; struct timeval tvb,tv; uint32_t msec; gettimeofday(&tvb,NULL); for (;;) { l=1; for (i=0 ; i<r->srccnt ; i++) { if (r->repsources[i].bytesleft>0) { r->fds[i].events = POLLOUT; l=0; } else { r->fds[i].events = 0; } } if (l) { // finished return 0; } gettimeofday(&tv,NULL); if (tv.tv_usec < tvb.tv_usec) { tv.tv_usec+=1000000; tv.tv_sec--; } tv.tv_sec-=tvb.tv_sec; tv.tv_usec-=tvb.tv_usec; msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; if (msec>=msecto) { syslog(LOG_NOTICE,"replicator: send timed out"); return -1; // timed out } if (poll(r->fds,r->srccnt,msecto-msec)<0) { if (errno!=EINTR && errno!=EAGAIN) { mfs_errlog_silent(LOG_NOTICE,"replicator: poll error"); return -1; } continue; } for (i=0 ; i<r->srccnt ; i++) { if (r->fds[i].revents & POLLHUP) { syslog(LOG_NOTICE,"replicator: connection lost"); return -1; } if (r->fds[i].revents & POLLOUT) { if (rep_write(r->repsources+i)<0) { return -1; } } } } }
static int rep_send_all_packets(replication *r,uint32_t msecto) { uint8_t i,l; uint64_t st; uint32_t msec; st = monotonic_useconds(); for (;;) { l=1; for (i=0 ; i<r->srccnt ; i++) { if (r->repsources[i].bytesleft>0) { r->fds[i].events = POLLOUT; l=0; } else { r->fds[i].events = 0; } } if (l) { // finished return 0; } msec = (monotonic_useconds()-st)/1000; if (msec>=msecto) { syslog(LOG_NOTICE,"replicator: send timed out"); return -1; // timed out } if (poll(r->fds,r->srccnt,msecto-msec)<0) { if (errno!=EINTR && ERRNO_ERROR) { mfs_errlog_silent(LOG_NOTICE,"replicator: poll error"); return -1; } continue; } for (i=0 ; i<r->srccnt ; i++) { if (r->fds[i].revents & POLLHUP) { syslog(LOG_NOTICE,"replicator: connection lost"); return -1; } if (r->fds[i].revents & POLLOUT) { if (rep_write(r->repsources+i)<0) { return -1; } } } } }