Logo Search packages:      
Sourcecode: libmpdclient version File versions  Download package

mpd_malloc char* mpd_async_recv_line ( struct mpd_async async  ) 

Receives a line from the input buffer. The result will be null-terminated, without the newline character. The pointer is only valid until the next async function is called.

Parameters:
async the connection
Returns:
a line on success, NULL otherwise

Definition at line 350 of file async.c.

References mpd_async::error, mpd_async::input, mpd_async_recv_line(), and MPD_ERROR_MALFORMED.

Referenced by mpd_async_recv_line(), and mpd_sync_recv_line().

{
      size_t size;
      char *src, *newline;

      assert(async != NULL);

      size = mpd_buffer_size(&async->input);
      if (size == 0)
            return NULL;

      src = mpd_buffer_read(&async->input);
      assert(src != NULL);
      newline = memchr(src, '\n', size);
      if (newline == NULL) {
            /* line is not finished yet */
            if (mpd_buffer_full(&async->input)) {
                  /* .. but the buffer is full - line is too
                     long, abort connection and bail out */
                  mpd_error_code(&async->error, MPD_ERROR_MALFORMED);
                  mpd_error_message(&async->error,
                                "Response line too large");
            }

            return NULL;
      }

      *newline = 0;
      mpd_buffer_consume(&async->input, newline + 1 - src);

      return src;
}


Generated by  Doxygen 1.6.0   Back to index