2 * Subroutines to receive network data and handle
3 * network signals for the FD and the SD.
5 * Kern Sibbald, May MMI previously in src/stored/fdmsg.c
11 Copyright (C) 2001-2005 Kern Sibbald
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 version 2 as amended with additional clauses defined in the
16 file LICENSE in the main source directory.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 the file LICENSE for additional details.
25 #include "bacula.h" /* pull in global headers */
28 extern char TERM_msg[];
33 * This routine does a bnet_recv(), then if a signal was
34 * sent, it handles it. The return codes are the same as
35 * bne_recv() except the BNET_SIGNAL messages that can
36 * be handled are done so without returning.
38 * Returns number of bytes read (may return zero)
39 * Returns -1 on signal (BNET_SIGNAL)
40 * Returns -2 on hard end of file (BNET_HARDEOF)
41 * Returns -3 on error (BNET_ERROR)
43 int bget_msg(BSOCK *sock)
48 if (n >= 0) { /* normal return */
51 if (is_bnet_stop(sock)) { /* error return */
55 /* BNET_SIGNAL (-1) return from bnet_recv() => network signal */
56 switch (sock->msglen) {
57 case BNET_EOD: /* end of data */
58 Dmsg0(msglvl, "Got BNET_EOD\n");
61 Dmsg0(msglvl, "Got BNET_EOD_POLL\n");
62 if (sock->terminated) {
63 bnet_fsend(sock, TERM_msg);
65 bnet_fsend(sock, OK_msg); /* send response */
67 return n; /* end of data */
69 Dmsg0(msglvl, "Got BNET_TERMINATE\n");
73 Dmsg0(msglvl, "Got BNET_POLL\n");
74 if (sock->terminated) {
75 bnet_fsend(sock, TERM_msg);
77 bnet_fsend(sock, OK_msg); /* send response */
81 case BNET_HB_RESPONSE:
84 /* *****FIXME***** Implement BNET_STATUS */
85 Dmsg0(msglvl, "Got BNET_STATUS\n");
86 bnet_fsend(sock, _("Status OK\n"));
87 bnet_sig(sock, BNET_EOD);
90 Emsg1(M_ERROR, 0, _("bget_msg: unknown signal %d\n"), sock->msglen);