mirror of https://github.com/ericonr/sndio.git
Refresh current position before reading/writing data, to keep the
current position always consistent with read & write pointers.
This commit is contained in:
parent
c9d4272377
commit
d06df743db
|
@ -302,7 +302,7 @@ sio_read(struct sio_hdl *hdl, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
char *data = buf;
|
char *data = buf;
|
||||||
size_t todo = len;
|
size_t todo = len, maxread;
|
||||||
|
|
||||||
if (hdl->eof) {
|
if (hdl->eof) {
|
||||||
DPRINTF("sio_read: eof\n");
|
DPRINTF("sio_read: eof\n");
|
||||||
|
@ -317,10 +317,13 @@ sio_read(struct sio_hdl *hdl, void *buf, size_t len)
|
||||||
DPRINTF("sio_read: zero length read ignored\n");
|
DPRINTF("sio_read: zero length read ignored\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
while (todo > 0) {
|
||||||
if (!sio_rdrop(hdl))
|
if (!sio_rdrop(hdl))
|
||||||
return 0;
|
return 0;
|
||||||
while (todo > 0) {
|
maxread = hdl->rused;
|
||||||
n = hdl->ops->read(hdl, data, todo);
|
if (maxread > todo)
|
||||||
|
maxread = todo;
|
||||||
|
n = maxread > 0 ? hdl->ops->read(hdl, data, maxread) : 0;
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
if (hdl->nbio || hdl->eof || todo < len)
|
if (hdl->nbio || hdl->eof || todo < len)
|
||||||
break;
|
break;
|
||||||
|
@ -340,7 +343,7 @@ sio_write(struct sio_hdl *hdl, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
const unsigned char *data = buf;
|
const unsigned char *data = buf;
|
||||||
size_t todo = len;
|
size_t todo = len, maxwrite;
|
||||||
|
|
||||||
if (hdl->eof) {
|
if (hdl->eof) {
|
||||||
DPRINTF("sio_write: eof\n");
|
DPRINTF("sio_write: eof\n");
|
||||||
|
@ -355,10 +358,14 @@ sio_write(struct sio_hdl *hdl, const void *buf, size_t len)
|
||||||
DPRINTF("sio_write: zero length write ignored\n");
|
DPRINTF("sio_write: zero length write ignored\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
while (todo > 0) {
|
||||||
if (!sio_wsil(hdl))
|
if (!sio_wsil(hdl))
|
||||||
return 0;
|
return 0;
|
||||||
while (todo > 0) {
|
maxwrite = hdl->par.bufsz * hdl->par.pchan * hdl->par.bps -
|
||||||
n = hdl->ops->write(hdl, data, todo);
|
hdl->wused;
|
||||||
|
if (maxwrite > todo)
|
||||||
|
maxwrite = todo;
|
||||||
|
n = maxwrite > 0 ? hdl->ops->write(hdl, data, maxwrite) : 0;
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
if (hdl->nbio || hdl->eof)
|
if (hdl->nbio || hdl->eof)
|
||||||
break;
|
break;
|
||||||
|
@ -500,6 +507,11 @@ _sio_onmove_cb(struct sio_hdl *hdl, int delta)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (_sndio_debug >= 3)
|
if (_sndio_debug >= 3)
|
||||||
_sio_printpos(hdl);
|
_sio_printpos(hdl);
|
||||||
|
if ((hdl->mode & SIO_PLAY) && hdl->wused < 0) {
|
||||||
|
DPRINTFN(1, "sndio: h/w failure: negative buffer usage\n");
|
||||||
|
hdl->eof = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (hdl->move_cb)
|
if (hdl->move_cb)
|
||||||
hdl->move_cb(hdl->move_addr, delta);
|
hdl->move_cb(hdl->move_addr, delta);
|
||||||
|
|
Loading…
Reference in New Issue