bool MonitorItem::docmd(const char* command) { if (!doconnect()) { return false; } if (command[0] != 0) { writecmd(command); } emit clearText(get_name()); bool jobRunning = false; while (1) { int stat; if ((stat = bnet_recv(d->DSock)) >= 0) { strip_trailing_newline(d->DSock->msg); QString msg = QString::fromUtf8(d->DSock->msg); emit appendText(QString::fromUtf8(get_name()), msg); if (d->type == R_CLIENT) { if (msg.contains("Job started:")) jobRunning = true; } } else if (stat == BNET_SIGNAL) { if (d->DSock->msglen == BNET_EOD) { // qDebug() << "<< EOD >>"; if (d->type == R_CLIENT) emit jobIsRunning (jobRunning); return true; } else if (d->DSock->msglen == BNET_SUB_PROMPT) { // qDebug() << "<< PROMPT >>"; return false; } else if (d->DSock->msglen == BNET_HEARTBEAT) { bnet_sig(d->DSock, BNET_HB_RESPONSE); } else { qDebug() << bnet_sig_to_ascii(d->DSock); } } else { /* BNET_HARDEOF || BNET_ERROR */ d->DSock = NULL; d->state = MonitorItem::Error; emit statusChanged(get_name(), d->state); emit showStatusbarMessage("Error : BNET_HARDEOF or BNET_ERROR"); //fprintf(stderr, "<< ERROR >>\n")); return false; } /* if ((stat = bnet_recv(d->DSock)) >= 0) */ if (is_bnet_stop(d->DSock)) { d->DSock = NULL; d->state = MonitorItem::Error; emit statusChanged(get_name(), d->state); emit showStatusbarMessage("Error : Connection closed."); //fprintf(stderr, "<< STOP >>\n"); return false; /* error or term */ } /* if (is_bnet_stop(d->DSock) */ } /* while (1) */ }
static void close_sd_bsock(UAContext *ua) { if (ua->jcr->store_bsock) { bnet_sig(ua->jcr->store_bsock, BNET_TERMINATE); bnet_close(ua->jcr->store_bsock); ua->jcr->store_bsock = NULL; } }