2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation plus additions
11 that are listed in the file LICENSE.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Network Utility Routines
33 * Version $Id: bnet.c 3670 2006-11-21 16:13:58Z kerns $
42 * Send a message over the network. The send consists of
43 * two network packets. The first is sends a 32 bit integer containing
44 * the length of the data packet which follows.
46 * Returns: false on failure
55 if (errors || terminated || msglen > 1000000) {
58 /* Compute total packet length */
60 pktsiz = sizeof(pktsiz); /* signal, no data */
62 pktsiz = msglen + sizeof(pktsiz); /* data */
64 /* Store packet length at head of message -- note, we
65 * have reserved an int32_t just before msg, so we can
68 hdr = (int32_t *)(msg - (int)sizeof(pktsiz));
69 *hdr = htonl(msglen); /* store signal/length */
71 out_msg_no++; /* increment message number */
73 /* send data packet */
74 timer_start = watchdog_time; /* start timer */
76 /* Full I/O done in one write */
77 rc = write_nbytes(this, (char *)hdr, pktsiz);
78 timer_start = 0; /* clear timer */
87 if (!suppress_error_msgs) {
88 Qmsg5(jcr, M_ERROR, 0,
89 _("Write error sending %d bytes to %s:%s:%d: ERR=%s\n"),
91 host, port, bnet_strerror(this));
94 Qmsg5(jcr, M_ERROR, 0,
95 _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
96 msglen, who, host, port, rc);
104 * Format and send a message
105 * Returns: false on error
108 bool BSOCK::fsend(const char *fmt, ...)
113 if (errors || terminated) {
116 /* This probably won't work, but we vsnprintf, then if we
117 * get a negative length or a length greater than our buffer
118 * (depending on which library is used), the printf was truncated, so
119 * get a bigger buffer and try again.
122 maxlen = sizeof_pool_memory(msg) - 1;
123 va_start(arg_ptr, fmt);
124 msglen = bvsnprintf(msg, maxlen, fmt, arg_ptr);
126 if (msglen > 0 && msglen < (maxlen - 5)) {
129 msg = realloc_pool_memory(msg, maxlen + maxlen / 2);
137 bool BSOCK::signal(int signal)
140 if (signal == BNET_TERMINATE) {
141 suppress_error_msgs = true;