~ubuntu-branches/ubuntu/quantal/libdmapsharing/quantal

« back to all changes in this revision

Viewing changes to libdmapsharing/dmap-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2011-03-29 19:52:57 UTC
  • mfrom: (0.1.2 experimental) (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110329195257-0zas0lq4c03gwo46
Tags: 2.9.7-1
Initial release. (Closes: #620060)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Utility functions used throughout libdmapsharing
 
3
 *
 
4
 * Copyright (C) 2010 W. Michael Petullo <mike@flyn.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include <string.h>
 
22
 
 
23
#include "dmap-utils.h"
 
24
 
 
25
#define DMAP_SHARE_CHUNK_SIZE 16384
 
26
 
 
27
void
 
28
dmap_write_next_chunk (SoupMessage * message, ChunkData * cd)
 
29
{
 
30
        gssize read_size;
 
31
        GError *error = NULL;
 
32
        gchar *chunk = g_malloc (DMAP_SHARE_CHUNK_SIZE);
 
33
 
 
34
        read_size = g_input_stream_read (cd->stream,
 
35
                                         chunk,
 
36
                                         DMAP_SHARE_CHUNK_SIZE, NULL, &error);
 
37
        if (read_size > 0) {
 
38
                soup_message_body_append (message->response_body,
 
39
                                          SOUP_MEMORY_TAKE, chunk, read_size);
 
40
        } else {
 
41
                if (error != NULL) {
 
42
                        g_warning ("Error reading from input stream: %s",
 
43
                                   error->message);
 
44
                        g_error_free (error);
 
45
                }
 
46
                g_free (chunk);
 
47
                g_debug ("Wrote 0 bytes, sending message complete.");
 
48
                soup_message_body_complete (message->response_body);
 
49
        }
 
50
        soup_server_unpause_message (cd->server, message);
 
51
}
 
52
 
 
53
void
 
54
dmap_chunked_message_finished (SoupMessage * message, ChunkData * cd)
 
55
{
 
56
        g_debug ("Finished sending chunked file.");
 
57
        g_input_stream_close (cd->stream, NULL, NULL);
 
58
        g_free (cd);
 
59
}