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) 2000, 2001, 2002 Kern Sibbald and John Walker
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
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 GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 #include "bacula.h" /* pull in global headers */
33 extern char TERM_msg[];
38 * This routine does a bnet_recv(), then if a signal was
39 * sent, it handles it. The return codes are the same as
40 * bne_recv() except the BNET_SIGNAL messages that can
41 * be handled are done so without returning.
43 * Returns number of bytes read (may return zero)
44 * Returns -1 on signal (BNET_SIGNAL)
45 * Returns -2 on hard end of file (BNET_HARDEOF)
46 * Returns -3 on error (BNET_ERROR)
48 int bget_msg(BSOCK *sock)
53 if (n >= 0) { /* normal return */
56 if (is_bnet_stop(sock)) { /* error return */
60 /* BNET_SIGNAL (-1) return from bnet_recv() => network signal */
61 switch (sock->msglen) {
62 case BNET_EOD: /* end of data */
63 Dmsg0(msglvl, "Got BNET_EOD\n");
66 Dmsg0(msglvl, "Got BNET_EOD_POLL\n");
67 if (sock->terminated) {
68 bnet_fsend(sock, TERM_msg);
70 bnet_fsend(sock, OK_msg); /* send response */
72 return n; /* end of data */
74 Dmsg0(msglvl, "Got BNET_TERMINATE\n");
78 Dmsg0(msglvl, "Got BNET_POLL\n");
79 if (sock->terminated) {
80 bnet_fsend(sock, TERM_msg);
82 bnet_fsend(sock, OK_msg); /* send response */
86 case BNET_HB_RESPONSE:
89 /* *****FIXME***** Implement BNET_STATUS */
90 Dmsg0(msglvl, "Got BNET_STATUS\n");
91 bnet_fsend(sock, "Status OK\n");
92 bnet_sig(sock, BNET_EOD);
95 Emsg1(M_ERROR, 0, "bget_msg: unknown signal %d\n", sock->msglen);