[svn r460] fixed file_transfer trunk
authorrenatofilho
Tue Mar 27 15:35:49 2007 +0100 (2007-03-27)
branchtrunk
changeset 45510c21aebb0ff
parent 454 f76bb8743b22
child 456 96a51561bed6
[svn r460] fixed file_transfer
gmyth/src/gmyth_file_transfer.c
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Tue Mar 27 14:53:51 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Tue Mar 27 15:35:49 2007 +0100
     1.3 @@ -684,17 +684,14 @@
     1.4    g_string_append_printf ( query, "%d", transfer->file_id );
     1.5    gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str );
     1.6    
     1.7 -  /* send requests to the maximum number of REQUEST_BLOCK messages */
     1.8 -  guint max_tries = 5;
     1.9 -  
    1.10    myth_control_acquire_context( transfer, TRUE );
    1.11    
    1.12 -  while (total_read == 0 && --max_tries > 0) {
    1.13 +  while (total_read != size) {
    1.14      GMythStringList *strlist = gmyth_string_list_new();
    1.15  
    1.16      gmyth_string_list_append_char_array( strlist, query->str );
    1.17      gmyth_string_list_append_char_array( strlist, "REQUEST_BLOCK" );
    1.18 -    gmyth_string_list_append_int( strlist, size );
    1.19 +    gmyth_string_list_append_int( strlist, size - total_read);
    1.20  
    1.21      // Request the block to the backend
    1.22      gmyth_socket_write_stringlist (transfer->control_sock, strlist);
    1.23 @@ -708,37 +705,32 @@
    1.24  
    1.25      	if (bytes_sent > 0) {
    1.26              gchar *data_buffer = g_new0 (gchar, bytes_sent);
    1.27 -            while (bytes_sent > 0) { 
    1.28 -                io_status = g_io_channel_read_chars (io_channel, 
    1.29 -                                                     data_buffer,
    1.30 -                                                     (gsize) bytes_sent,
    1.31 -                                                     &bytes_read, 
    1.32 -                                                     &error);
    1.33 +            io_status = g_io_channel_read_chars (io_channel, 
    1.34 +                                                 data_buffer,
    1.35 +                                                 (gsize) bytes_sent,
    1.36 +                                                 &bytes_read, 
    1.37 +                                                 &error);
    1.38  
    1.39 -                if (io_status != G_IO_STATUS_NORMAL) {
    1.40 -                    gmyth_debug ("Error on io_channel");
    1.41 -                    g_free (data_buffer);
    1.42 -                    total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    1.43 -                    g_object_unref (strlist);
    1.44 -                    break;
    1.45 -                }
    1.46 +            if (io_status != G_IO_STATUS_NORMAL) {
    1.47 +                gmyth_debug ("Error on io_channel");
    1.48 +                g_free (data_buffer);
    1.49 +                total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    1.50 +                g_object_unref (strlist);
    1.51 +                break;
    1.52 +            }
    1.53  
    1.54 -                total_read += bytes_read;
    1.55 -                bytes_sent -= bytes_read;
    1.56 +            total_read += bytes_read;
    1.57  
    1.58 -                /* append new data to the increasing byte array */
    1.59 -                data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
    1.60 -                gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", total_read);
    1.61 -            }
    1.62 +            /* append new data to the increasing byte array */
    1.63 +            data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
    1.64 +            gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", total_read);
    1.65 +            
    1.66              g_free (data_buffer);
    1.67          } else if (!read_unlimited) {
    1.68        	    total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    1.69      		g_object_unref (strlist);
    1.70      		strlist = NULL;
    1.71      		break;
    1.72 -        } else {
    1.73 -            /* wait for more data */
    1.74 -            g_usleep (300);
    1.75          }
    1.76      } else { 
    1.77          /*if (!(transfer->priv != NULL && transfer->priv->recorder != NULL &&
    1.78 @@ -756,6 +748,12 @@
    1.79  	    g_object_unref (strlist);
    1.80  	    strlist = NULL;
    1.81      }
    1.82 +
    1.83 +    if ((total_read < size) && read_unlimited) {
    1.84 +        /* wait for more data */
    1.85 +        g_usleep (300);
    1.86 +    }
    1.87 +
    1.88    } /* while - iterates through bytes until reaches the end of stream */
    1.89  
    1.90    if (read_unlimited && (bytes_sent == 0) && (max_tries == 0) ) {