In APUE, in figure 16-11, the code is as follows:
#include "apue.h"
#include <sys/socket.h>
#define MAXSLEEP 128
int connect_retry(int domain, int type, int protocol, const struct sockaddr *addr, socklen_t alen) {
int numsec, fd;
/* Try to connect with exponential backoff. */
for (numsec = 1; numsec <= MAXSLEEP; numsec <<= 1) {
if ((fd = socket(domain, type, protocol)) < 0)
return(-1);
if (connect(fd, addr, alen) == 0) {
/* Connection accepted. */
return(fd);
}
close(fd);
/* Delay before trying again.*/
if (numsec <= MAXSLEEP/2) -- question line
sleep(numsec);
}
return(-1);
}
My question is: Why MAXSLEEP
is define as 128 and It’s division by 2 is evaluated, and not defined 64 without any division?