+/** @brief Flush the OSS output buffer
+ * @return 0 on success, non-0 on error
+ */
+static int playrtp_oss_flush(void) {
+ int nbyteswritten;
+
+ if(!playrtp_oss_bufused)
+ return 0; /* nothing to do */
+ /* 0 out the unused portion of the buffer */
+ memset(playrtp_oss_buffer + playrtp_oss_bufused, 0,
+ playrtp_oss_bufsize - playrtp_oss_bufused);
+ for(;;) {
+ nbyteswritten = write(playrtp_oss_fd,
+ playrtp_oss_buffer, playrtp_oss_bufsize);
+ if(nbyteswritten < 0) {
+ switch(errno) {
+ case EINTR:
+ break; /* try again */
+ case EAGAIN:
+ return 0; /* try later */
+ default:
+ error(errno, "error writing to %s", device);
+ return -1;
+ }
+ } else {
+ if(nbyteswritten < playrtp_oss_bufsize)
+ error(0, "%s: short write (%d/%d)",
+ device, nbyteswritten, playrtp_oss_bufsize);
+ playrtp_oss_bufused = 0;
+ return 0;
+ }
+ }
+}
+