#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()
*/
* 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);