[svn r510] fixed file_read trunk
authorrenatofilho
Thu Apr 05 15:15:12 2007 +0100 (2007-04-05)
branchtrunk
changeset 505b90373d8534b
parent 504 2b5355061b66
child 506 4fcd764b21a6
[svn r510] fixed file_read
gmyth/src/gmyth_file_transfer.c
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Wed Apr 04 23:30:44 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Thu Apr 05 15:15:12 2007 +0100
     1.3 @@ -631,6 +631,7 @@
     1.4      GIOStatus io_status_control = G_IO_STATUS_NORMAL;
     1.5  
     1.6      GMythStringList *strlist;
     1.7 +    GMythStringList *ret_strlist = NULL;
     1.8      gboolean ret = TRUE;
     1.9      GString *query;
    1.10  
    1.11 @@ -671,62 +672,69 @@
    1.12      gmyth_string_list_append_char_array (strlist, "REQUEST_BLOCK" );
    1.13      gmyth_string_list_append_int (strlist, size - total_read);
    1.14  
    1.15 -    // Request the block to the backend
    1.16 -    gmyth_socket_write_stringlist (priv->control_sock, strlist);
    1.17 +    do {
    1.18 +        bytes_sent = 0;
    1.19 +        
    1.20 +        // Request the block to the backend
    1.21 +        gmyth_socket_write_stringlist (priv->control_sock, strlist);
    1.22  
    1.23 -    // Receives the backand answer    
    1.24 -    gmyth_socket_read_stringlist (priv->control_sock, strlist);
    1.25 +        if (ret_strlist != NULL)
    1.26 +            g_object_unref (ret_strlist);
    1.27  
    1.28 -    if (strlist != NULL && gmyth_string_list_length (strlist) > 0) { 
    1.29 -        bytes_sent = gmyth_string_list_get_int (strlist,  0); // -1 on backend error
    1.30 -	    gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
    1.31 +        ret_strlist = gmyth_string_list_new ();
    1.32 +        // Receives the backand answer    
    1.33 +        gmyth_socket_read_stringlist (priv->control_sock, ret_strlist);
    1.34 +        
    1.35 +        if (ret_strlist != NULL && gmyth_string_list_length (ret_strlist) > 0) { 
    1.36 +            bytes_sent = gmyth_string_list_get_int (ret_strlist,  0); // -1 on backend error
    1.37 +	        gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
    1.38 +        }
    1.39  
    1.40 -    	if (bytes_sent > 0) {
    1.41 -            gchar *data_buffer = g_new0 (gchar, bytes_sent);
    1.42 -            io_status = g_io_channel_read_chars (io_channel, 
    1.43 -                                                 data_buffer,
    1.44 -                                                 (gsize) bytes_sent,
    1.45 -                                                 &bytes_read, 
    1.46 -                                                 &error);
    1.47 +    } while (read_unlimited && (bytes_sent == 0));
    1.48  
    1.49 -            if (io_status != G_IO_STATUS_NORMAL) {
    1.50 -                gmyth_debug ("Error on io_channel");
    1.51 -                g_free (data_buffer);
    1.52 -                g_object_unref (strlist);
    1.53 -                retval = GMYTH_FILE_TRANSFER_READ_ERROR;
    1.54 -                goto error;
    1.55 -            }
    1.56 +   	if (bytes_sent > 0) {
    1.57 +        gchar *data_buffer = g_new0 (gchar, bytes_sent);
    1.58 +        io_status = g_io_channel_read_chars (io_channel, 
    1.59 +                                             data_buffer,
    1.60 +                                             (gsize) bytes_sent,
    1.61 +                                             &bytes_read, 
    1.62 +                                             &error);
    1.63  
    1.64 -            /* append new data to the increasing byte array */
    1.65 -            data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
    1.66 -            priv->offset += bytes_read;
    1.67 -
    1.68 -            if ((priv->filesize > 0) && (priv->offset == priv->filesize)) {
    1.69 -                retval = GMYTH_FILE_TRANSFER_READ_EOF;
    1.70 -                goto error;
    1.71 -            }
    1.72 -            
    1.73 +        if (io_status != G_IO_STATUS_NORMAL) {
    1.74 +            gmyth_debug ("Error on io_channel");
    1.75              g_free (data_buffer);
    1.76 -        } else if (!read_unlimited) {
    1.77 -    		g_object_unref (strlist);
    1.78 -    		strlist = NULL;
    1.79 +            g_object_unref (strlist);
    1.80              retval = GMYTH_FILE_TRANSFER_READ_ERROR;
    1.81              goto error;
    1.82          }
    1.83 +
    1.84 +        /* append new data to the increasing byte array */
    1.85 +        data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
    1.86 +        priv->offset += bytes_read;
    1.87 +
    1.88 +        if (!read_unlimited && (priv->filesize > 0) && (priv->offset == priv->filesize)) {
    1.89 +            retval = GMYTH_FILE_TRANSFER_READ_EOF;
    1.90 +            goto error;
    1.91 +        }
    1.92 +        
    1.93 +        g_free (data_buffer);
    1.94      } else { 
    1.95          retval = GMYTH_FILE_TRANSFER_READ_ERROR;
    1.96 -        if (strlist != NULL) {
    1.97 -        	g_object_unref (strlist);
    1.98 -        	strlist = NULL;
    1.99 -        }
   1.100      }
   1.101  
   1.102 -    if ( strlist!=NULL )
   1.103 +    if (strlist!=NULL)
   1.104      {
   1.105  	    g_object_unref (strlist);
   1.106  	    strlist = NULL;
   1.107      }
   1.108  
   1.109 +    if (ret_strlist!=NULL)
   1.110 +    {
   1.111 +	    g_object_unref (ret_strlist);
   1.112 +	    ret_strlist = NULL;
   1.113 +    }
   1.114 +
   1.115 +
   1.116      if (read_unlimited && (bytes_sent == 0)) {
   1.117  		gmyth_debug( "Trying to move to the next program chain..." );
   1.118  		if (priv->recorder != NULL &&