pcm: ioplug: Implement proper drain behavior
pcm: ioplug: Implement proper drain behavior

This patch fixes the draining behavior of ioplug in the following
ways:

- When no draining ioplug callback is defined, implement the draining
  loop using snd_pcm_wait*() and sync with the drain finishes.
  This is equivalent with the implementation in the kernel write().
  Similarly as in kernel code, for non-blocking mode, it returns
  immediately after setting DRAINING state.

- The hw_ptr update function checks the PCM state and stops the stream
  if the draining finishes.

- When draining ioplug callback is defined, leave the whole draining
  operation to it.  The callback is supposed to return -EAGAIN for
  non-blocking case, too.

- When an error happens during draining, it drops the stream, for a
  safety reason.

Signed-off-by: Takashi Iwai <4596b3305151c7ee743192a95d394341e3d3b644@suse.de>

alsa-project/alsa-lib,alsa-project/alsa-lib,takaswie/alsa-lib,takaswie/alsa-lib,tiwai/alsa-lib,takaswie/alsa-lib,alsa-project/alsa-lib,tiwai/alsa-lib,tiwai/alsa-lib,takaswie/alsa-lib,alsa-project/alsa-lib,takaswie/alsa-lib,tiwai/alsa-lib