# HG changeset patch # User renatofilho # Date 1175006149 -3600 # Node ID 10c21aebb0ffd783bbb58e2629aa93c8ab6861e9 # Parent f76bb8743b22c15e8cd109c71c79c68990f453bd [svn r460] fixed file_transfer diff -r f76bb8743b22 -r 10c21aebb0ff gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Tue Mar 27 14:53:51 2007 +0100 +++ b/gmyth/src/gmyth_file_transfer.c Tue Mar 27 15:35:49 2007 +0100 @@ -684,17 +684,14 @@ g_string_append_printf ( query, "%d", transfer->file_id ); gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str ); - /* send requests to the maximum number of REQUEST_BLOCK messages */ - guint max_tries = 5; - myth_control_acquire_context( transfer, TRUE ); - while (total_read == 0 && --max_tries > 0) { + while (total_read != size) { GMythStringList *strlist = gmyth_string_list_new(); gmyth_string_list_append_char_array( strlist, query->str ); gmyth_string_list_append_char_array( strlist, "REQUEST_BLOCK" ); - gmyth_string_list_append_int( strlist, size ); + gmyth_string_list_append_int( strlist, size - total_read); // Request the block to the backend gmyth_socket_write_stringlist (transfer->control_sock, strlist); @@ -708,37 +705,32 @@ if (bytes_sent > 0) { gchar *data_buffer = g_new0 (gchar, bytes_sent); - while (bytes_sent > 0) { - io_status = g_io_channel_read_chars (io_channel, - data_buffer, - (gsize) bytes_sent, - &bytes_read, - &error); + io_status = g_io_channel_read_chars (io_channel, + data_buffer, + (gsize) bytes_sent, + &bytes_read, + &error); - if (io_status != G_IO_STATUS_NORMAL) { - gmyth_debug ("Error on io_channel"); - g_free (data_buffer); - total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR; - g_object_unref (strlist); - break; - } + if (io_status != G_IO_STATUS_NORMAL) { + gmyth_debug ("Error on io_channel"); + g_free (data_buffer); + total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR; + g_object_unref (strlist); + break; + } - total_read += bytes_read; - bytes_sent -= bytes_read; + total_read += bytes_read; - /* append new data to the increasing byte array */ - data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); - gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", total_read); - } + /* append new data to the increasing byte array */ + data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); + gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", total_read); + g_free (data_buffer); } else if (!read_unlimited) { total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR; g_object_unref (strlist); strlist = NULL; break; - } else { - /* wait for more data */ - g_usleep (300); } } else { /*if (!(transfer->priv != NULL && transfer->priv->recorder != NULL && @@ -756,6 +748,12 @@ g_object_unref (strlist); strlist = NULL; } + + if ((total_read < size) && read_unlimited) { + /* wait for more data */ + g_usleep (300); + } + } /* while - iterates through bytes until reaches the end of stream */ if (read_unlimited && (bytes_sent == 0) && (max_tries == 0) ) {