Optimize vm storage (bug #3605)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5035 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 21 years ago
parent f9222e7e4b
commit b0863c5e31

@ -743,23 +743,15 @@ static int retrieve_file(char *dir, int msgnum)
goto yuck; goto yuck;
} }
if (!strcmp(coltitle, "recording")) { if (!strcmp(coltitle, "recording")) {
res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
fdlen = colsize; fdlen = colsize;
fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770); fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
if (fd > -1) { if (fd > -1) {
/* Ugh, gotta fill it so we can mmap */ char tmp[1]="";
char tmp[1024]=""; lseek(fd, fdlen - 1, SEEK_SET);
size_t left = 0, bytes = 0; if (write(fd, tmp, 1) != 1) {
left = fdlen; close(fd);
while(left) { fd = -1;
bytes = left;
if (bytes > sizeof(tmp))
bytes = sizeof(tmp);
if (write(fd, tmp, bytes) != bytes) {
close(fd);
fd = -1;
break;
}
left -= bytes;
} }
if (fd > -1) if (fd > -1)
fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
@ -772,8 +764,6 @@ static int retrieve_file(char *dir, int msgnum)
SQLFreeHandle (SQL_HANDLE_STMT, stmt); SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck; goto yuck;
} }
fdlen = colsize;
ftruncate(fd, fdlen);
} }
} else { } else {
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);

Loading…
Cancel
Save