#define ENODATA EPIPE
#endif
-
+#ifdef HAVE_WIN32
+#define socketRead(fd, buf, len) recv(fd, buf, len, 0)
+#define socketWrite(fd, buf, len) send(fd, buf, len, 0)
+#else
+#define socketRead(fd, buf, len) read(fd, buf, len)
+#define socketWrite(fd, buf, len) write(fd, buf, len)
+#endif
/*
while (nleft > 0) {
do {
errno = 0;
- nread = read(bsock->fd, ptr, nleft);
+ nread = socketRead(bsock->fd, ptr, nleft);
if (bsock->timed_out || bsock->terminated) {
return nread;
}
while (nleft > 0) {
do {
errno = 0;
- nwritten = write(bsock->fd, ptr, nleft);
+ nwritten = socketWrite(bsock->fd, ptr, nleft);
if (bsock->timed_out || bsock->terminated) {
return nwritten;
}
/*
- * Transmit spooled data now
+ * Transmit spooled data now to a BSOCK
*/
-int bnet_despool(BSOCK *bsock)
+int bnet_despool_to_bsock(BSOCK *bsock)
{
int32_t pktsiz;
size_t nbytes;
int32_t pktsiz;
int32_t msglen;
- if (bsock->errors || bsock->terminated) {
+ if (bsock->errors || bsock->terminated || bsock->msglen > 1000000) {
return 0;
}
msglen = bsock->msglen;
- ASSERT(bsock->msglen < 1000000);
pktsiz = htonl((int32_t)bsock->msglen);
/* send int32_t containing size of data packet */
bsock->timer_start = watchdog_time; /* start timer */
bsock->out_msg_no++; /* increment message number */
if (bsock->msglen <= 0) { /* length only? */
- ASSERT(msglen == bsock->msglen);
return 1; /* yes, no data */
}
}
return 0;
}
- ASSERT(msglen == bsock->msglen);
return 1;
}
#define NO_DATA 4 /* Valid name, no data record of requested type. */
#endif
+#ifndef HAVE_WIN32
extern int h_errno; /* On error has one of the above */
-
+#endif
/*
* Get human readable error for gethostbyname()
*/
-static char *gethost_strerror()
+static const char *gethost_strerror()
{
switch (h_errno) {
case NETDB_INTERNAL:
} else {
P(ip_mutex);
if ((hp = gethostbyname(host)) == NULL) {
- Jmsg2(jcr, M_ERROR, 0, "gethostbyname() for %s failed: ERR=%s\n",
+ Jmsg2(jcr, M_ERROR, 0, "gethostbyname() for host \"%s\" failed: ERR=%s\n",
host, gethost_strerror());
V(ip_mutex);
return NULL;
* ***FIXME*** implement service from /etc/services
*/
static BSOCK *
-bnet_open(JCR *jcr, char *name, char *host, char *service, int port, int *fatal)
+bnet_open(JCR *jcr, const char *name, char *host, char *service, int port, int *fatal)
{
int sockfd;
struct sockaddr_in tcp_serv_addr; /* socket information */
close(sockfd);
return NULL;
}
- return init_bsock(jcr, sockfd, name, host, port);
+ return init_bsock(jcr, sockfd, name, host, port, &tcp_serv_addr);
}
/*
* Try to connect to host for max_retry_time at retry_time intervals.
*/
BSOCK *
-bnet_connect(JCR *jcr, int retry_interval, int max_retry_time, char *name,
+bnet_connect(JCR *jcr, int retry_interval, int max_retry_time, const char *name,
char *host, char *service, int port, int verbose)
{
int i;
* 1 on success
*/
int
-bnet_fsend(BSOCK *bs, char *fmt, ...)
+bnet_fsend(BSOCK *bs, const char *fmt, ...)
{
va_list arg_ptr;
int maxlen;
*/
int bnet_set_buffer_size(BSOCK *bs, uint32_t size, int rw)
{
- uint32_t dbuf_size;
+ uint32_t dbuf_size, start_size;
#if defined(IP_TOS) && defined(IPTOS_THROUGHPUT)
int opt;
setsockopt(bs->fd, IPPROTO_IP, IP_TOS, (sockopt_val_t)&opt, sizeof(opt));
#endif
- dbuf_size = size;
+ if (size != 0) {
+ dbuf_size = size;
+ } else {
+ dbuf_size = DEFAULT_NETWORK_BUFFER_SIZE;
+ }
+ start_size = dbuf_size;
if ((bs->msg = realloc_pool_memory(bs->msg, dbuf_size+100)) == NULL) {
Jmsg0(bs->jcr, M_FATAL, 0, _("Could not malloc BSOCK data buffer\n"));
return 0;
dbuf_size -= TAPE_BSIZE;
}
Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
- if (dbuf_size != MAX_NETWORK_BUFFER_SIZE)
+ if (dbuf_size != start_size) {
Jmsg1(bs->jcr, M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
+ }
if (dbuf_size % TAPE_BSIZE != 0) {
Jmsg1(bs->jcr, M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"),
dbuf_size);
}
}
- dbuf_size = size;
+ if (size != 0) {
+ dbuf_size = size;
+ } else {
+ dbuf_size = DEFAULT_NETWORK_BUFFER_SIZE;
+ }
+ start_size = dbuf_size;
if (rw & BNET_SETBUF_WRITE) {
while ((dbuf_size > TAPE_BSIZE) &&
(setsockopt(bs->fd, SOL_SOCKET, SO_SNDBUF, (sockopt_val_t)&dbuf_size, sizeof(dbuf_size)) < 0)) {
dbuf_size -= TAPE_BSIZE;
}
Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
- if (dbuf_size != MAX_NETWORK_BUFFER_SIZE)
+ if (dbuf_size != start_size) {
Jmsg1(bs->jcr, M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
+ }
if (dbuf_size % TAPE_BSIZE != 0) {
Jmsg1(bs->jcr, M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"),
dbuf_size);
* This probably should be done in net_open
*/
BSOCK *
-init_bsock(JCR *jcr, int sockfd, char *who, char *host, int port)
+init_bsock(JCR *jcr, int sockfd, const char *who, char *host, int port,
+ struct sockaddr_in *client_addr)
{
BSOCK *bsock = (BSOCK *)malloc(sizeof(BSOCK));
memset(bsock, 0, sizeof(BSOCK));
bsock->who = bstrdup(who);
bsock->host = bstrdup(host);
bsock->port = port;
+ memcpy(&bsock->client_addr, client_addr, sizeof(bsock->client_addr));
/*
* ****FIXME**** reduce this to a few hours once
* heartbeats are implemented