This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
- version 2 as ammended with additional clauses defined in the
+ version 2 as amended with additional clauses defined in the
file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
nleft = nbytes;
while (nleft > 0) {
- do {
- errno = 0;
- nread = socketRead(bsock->fd, ptr, nleft);
- if (bsock->timed_out || bsock->terminated) {
- return nread;
+ errno = 0;
+ nread = socketRead(bsock->fd, ptr, nleft);
+ if (bsock->timed_out || bsock->terminated) {
+ return nread;
+ }
+ if (nread == -1) {
+ if (errno == EINTR) {
+ continue;
+ }
+ if (errno == EAGAIN) {
+ bmicrosleep(0, 200000); /* try again in 200ms */
+ continue;
}
- } while (nread == -1 && (errno == EINTR || errno == EAGAIN));
+ }
if (nread <= 0) {
return nread; /* error, or EOF */
}
int32_t nbytes;
int32_t pktsiz;
- ASSERT(bsock != NULL);
+ if (!bsock) {
+ return BNET_HARDEOF;
+ }
bsock->msg[0] = 0;
bsock->msglen = 0;
if (bsock->errors || bsock->terminated) {
}
} else {
Qmsg5(bsock->jcr, M_ERROR, 0,
- _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), bsock->who,
- bsock->host, bsock->port, bsock->msglen, rc);
+ _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
+ sizeof(int32_t), bsock->who,
+ bsock->host, bsock->port, rc);
}
return false;
}
FD_ZERO(&fdset);
FD_SET((unsigned)bsock->fd, &fdset);
- tv.tv_sec = sec;
- tv.tv_usec = 0;
for (;;) {
+ tv.tv_sec = sec;
+ tv.tv_usec = 0;
switch (select(bsock->fd + 1, &fdset, NULL, NULL, &tv)) {
case 0: /* timeout */
bsock->b_errno = 0;
return 0;
case -1:
bsock->b_errno = errno;
- if (errno == EINTR || errno == EAGAIN) {
+ if (errno == EINTR) {
continue;
}
return -1; /* error return */
msg = be.strerror();
break;
case NETDB_SUCCESS:
- msg = "No problem.";
+ msg = _("No problem.");
break;
case HOST_NOT_FOUND:
- msg = "Authoritative answer for host not found.";
+ msg = _("Authoritative answer for host not found.");
break;
case TRY_AGAIN:
- msg = "Non-authoritative for host not found, or ServerFail.";
+ msg = _("Non-authoritative for host not found, or ServerFail.");
break;
case NO_RECOVERY:
- msg = "Non-recoverable errors, FORMERR, REFUSED, or NOTIMP.";
+ msg = _("Non-recoverable errors, FORMERR, REFUSED, or NOTIMP.");
break;
case NO_DATA:
- msg = "Valid name, no data record of resquested type.";
+ msg = _("Valid name, no data record of resquested type.");
break;
default:
- msg = "Unknown error.";
+ msg = _("Unknown error.");
}
return msg;
}
*/
if ((addr_list = bnet_host2ipaddrs(host, 0, &errstr)) == NULL) {
/* Note errstr is not malloc'ed */
- Qmsg2(jcr, M_ERROR, 0, "gethostbyname() for host \"%s\" failed: ERR=%s\n",
+ Qmsg2(jcr, M_ERROR, 0, _("gethostbyname() for host \"%s\" failed: ERR=%s\n"),
host, errstr);
Dmsg2(100, "bnet_host2ipaddrs() for host %s failed: ERR=%s\n",
host, errstr);
berrno be;
save_errno = errno;
*fatal = 1;
- Pmsg3(000, "Socket open error. proto=%d port=%d. ERR=%s\n",
+ Pmsg3(000, _("Socket open error. proto=%d port=%d. ERR=%s\n"),
ipaddr->get_family(), ipaddr->get_port_host_order(), be.strerror());
continue;
}
/* connect to server */
if (connect(sockfd, ipaddr->get_sockaddr(), ipaddr->get_sockaddr_len()) < 0) {
save_errno = errno;
- close(sockfd);
+ socketClose(sockfd);
continue;
}
*fatal = 0;
if (i < 0) {
i = 60 * 5; /* complain again in 5 minutes */
if (verbose)
- Qmsg4(jcr, M_WARNING, 0, "Could not connect to %s on %s:%d. ERR=%s\n"
-"Retrying ...\n", name, host, port, be.strerror());
+ Qmsg4(jcr, M_WARNING, 0, _(
+ "Could not connect to %s on %s:%d. ERR=%s\n"
+ "Retrying ...\n"), name, host, port, be.strerror());
}
bmicrosleep(retry_interval, 0);
max_retry_time -= retry_interval;
int oflags;
/* Get current flags */
- if((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
+ if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
berrno be;
- Emsg1(M_ABORT, 0, "fcntl F_GETFL error. ERR=%s\n", be.strerror());
+ Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror());
}
/* Set O_NONBLOCK flag */
- if((fcntl(bsock->fd, F_SETFL, oflags|O_NONBLOCK)) < 0) {
+ if ((fcntl(bsock->fd, F_SETFL, oflags|O_NONBLOCK)) < 0) {
berrno be;
- Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", be.strerror());
+ Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror());
}
bsock->blocking = 0;
ioctlsocket(bsock->fd, FIONBIO, &ioctlArg);
bsock->blocking = 0;
- return (flags);
+ return flags;
#endif
}
* Set socket blocking
* Returns previous socket flags
*/
-int bnet_set_blocking (BSOCK *bsock) {
+int bnet_set_blocking (BSOCK *bsock)
+{
#ifndef WIN32
int oflags;
/* Get current flags */
- if((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
+ if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
berrno be;
- Emsg1(M_ABORT, 0, "fcntl F_GETFL error. ERR=%s\n", be.strerror());
+ Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror());
}
/* Set O_NONBLOCK flag */
- if((fcntl(bsock->fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) {
+ if ((fcntl(bsock->fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) {
berrno be;
- Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", be.strerror());
+ Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror());
}
bsock->blocking = 1;
- return (oflags);
+ return oflags;
#else
int flags;
u_long ioctlArg = 0;
ioctlsocket(bsock->fd, FIONBIO, &ioctlArg);
bsock->blocking = 1;
- return (flags);
+ return flags;
#endif
}
/*
* Restores socket flags
*/
-void bnet_restore_blocking (BSOCK *bsock, int flags) {
+void bnet_restore_blocking (BSOCK *bsock, int flags)
+{
#ifndef WIN32
- if((fcntl(bsock->fd, F_SETFL, flags)) < 0) {
+ if ((fcntl(bsock->fd, F_SETFL, flags)) < 0) {
berrno be;
- Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", be.strerror());
+ Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror());
}
bsock->blocking = (flags & O_NONBLOCK);
case BNET_PROMPT:
return "BNET_PROMPT";
default:
- sprintf(buf, "Unknown sig %d", (int)bs->msglen);
+ sprintf(buf, _("Unknown sig %d"), (int)bs->msglen);
return buf;
}
}