mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
catch read/write errors and exit if they occur (issue #6721)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@12893 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
Rawplayer.c simple raw file stdout player
|
Rawplayer.c simple raw file stdout player
|
||||||
(c) Anthony C Minessale II <anthmct@yahoo.com>
|
(c) Anthony C Minessale II <anthmct@yahoo.com>
|
||||||
|
|
||||||
|
2006-03-10: Bruno Rocha <bruno@3gnt.net>
|
||||||
|
- include <stdlib.h> to remove compiler warning on some platforms
|
||||||
|
- check for read/write errors (avoid 100% CPU usage in some asterisk failures)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BUFLEN 320
|
#define BUFLEN 320
|
||||||
@@ -8,21 +12,25 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
static int deliver_file(char *path, int fdout) {
|
static int deliver_file(char *path, int fdout) {
|
||||||
int fd = 0, bytes = 0;
|
int fd = 0, bytes = 0, error = 0;
|
||||||
short buf[BUFLEN];
|
short buf[BUFLEN];
|
||||||
|
|
||||||
if ((fd = open(path,O_RDONLY))) {
|
if ((fd = open(path,O_RDONLY))) {
|
||||||
while ((bytes=read(fd, buf, BUFLEN))) {
|
while ((bytes=read(fd, buf, BUFLEN)) > 0) {
|
||||||
write(fdout, buf, bytes);
|
if(write(fdout, buf, bytes) < 0){
|
||||||
|
error = -2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(fd)
|
if(fd)
|
||||||
close(fd);
|
close(fd);
|
||||||
} else
|
} else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user