spacing, remove redundant debug

This commit is contained in:
Isaac Connor 2022-01-18 13:43:56 -05:00
parent 3241fa59c5
commit d2d9721c4e
1 changed files with 5 additions and 7 deletions

View File

@ -1096,35 +1096,33 @@ void EventStream::runStream() {
bool EventStream::send_file(const std::string &filepath) { bool EventStream::send_file(const std::string &filepath) {
FILE *fdj = nullptr; FILE *fdj = nullptr;
fdj = fopen(filepath.c_str(), "rb"); fdj = fopen(filepath.c_str(), "rb");
if ( !fdj ) { if (!fdj) {
Error("Can't open %s: %s", filepath.c_str(), strerror(errno)); Error("Can't open %s: %s", filepath.c_str(), strerror(errno));
std::string error_message = stringtf("Can't open %s: %s", filepath.c_str(), strerror(errno)); std::string error_message = stringtf("Can't open %s: %s", filepath.c_str(), strerror(errno));
return sendTextFrame(error_message.c_str()); return sendTextFrame(error_message.c_str());
} }
#if HAVE_SENDFILE #if HAVE_SENDFILE
static struct stat filestat; static struct stat filestat;
if ( fstat(fileno(fdj), &filestat) < 0 ) { if (fstat(fileno(fdj), &filestat) < 0) {
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
Error("Failed getting information about file %s: %s", filepath.c_str(), strerror(errno)); Error("Failed getting information about file %s: %s", filepath.c_str(), strerror(errno));
return false; return false;
} }
if ( !filestat.st_size ) { if (!filestat.st_size) {
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
Info("File size is zero. Unable to send raw frame %ld: %s", curr_frame_id, strerror(errno)); Info("File size is zero. Unable to send raw frame %ld: %s", curr_frame_id, strerror(errno));
return false; return false;
} }
if ( 0 > fprintf(stdout, "Content-Length: %d\r\n\r\n", (int)filestat.st_size) ) { if (0 > fprintf(stdout, "Content-Length: %d\r\n\r\n", (int)filestat.st_size)) {
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
Info("Unable to send raw frame %ld: %s", curr_frame_id, strerror(errno)); Info("Unable to send raw frame %ld: %s", curr_frame_id, strerror(errno));
return false; return false;
} }
int rc = zm_sendfile(fileno(stdout), fileno(fdj), 0, (int)filestat.st_size); int rc = zm_sendfile(fileno(stdout), fileno(fdj), 0, (int)filestat.st_size);
if ( rc == (int)filestat.st_size ) { if (rc == (int)filestat.st_size) {
// Success // Success
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
return true; return true;
} else {
Debug(1, "Failed to sendfile?");
} }
Warning("Unable to send raw frame %ld: %s rc %d != %d", Warning("Unable to send raw frame %ld: %s rc %d != %d",
curr_frame_id, strerror(errno), rc, (int)filestat.st_size); curr_frame_id, strerror(errno), rc, (int)filestat.st_size);