static int GetBytes(int id, void *buffer, size_t bytes_to_recv) { char *bptr = (char *)buffer; IoRoutines *io = GetConnectionIo(id); if (io) { int tries = 0; while (bytes_to_recv > 0 && (tries < 10)) { ssize_t bytes_recv; bytes_recv = io->recv(id, bptr, bytes_to_recv); if (bytes_recv <= 0) { if (errno != EINTR) return 0; tries++; } else { tries = 0; bytes_to_recv -= bytes_recv; bptr += bytes_recv; } } if (tries >= 10) { DisconnectConnection(id); fprintf(stderr,"\rrecv failed for connection %d: too many EINTR's",id); return 0; } return 1; } return 0; }
int FlushConnection(int id) { IoRoutines *io = GetConnectionIo(id); if (io) return io->flush ? io->flush(id) : 0; else return -1; }