[svn r459] bug fix on file_transfer trunk
authorrenatofilho
Tue Mar 27 14:53:51 2007 +0100 (2007-03-27)
branchtrunk
changeset 454f76bb8743b22
parent 453 a806d8ad0ff0
child 455 10c21aebb0ff
[svn r459] bug fix on file_transfer
gmyth/configure.ac
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_file_transfer.h
gmyth/src/gmyth_livetv.c
     1.1 --- a/gmyth/configure.ac	Tue Mar 27 00:13:27 2007 +0100
     1.2 +++ b/gmyth/configure.ac	Tue Mar 27 14:53:51 2007 +0100
     1.3 @@ -81,8 +81,8 @@
     1.4  dnl Test if --disable-debug given
     1.5  AC_ARG_ENABLE(debug,
     1.6          [AC_HELP_STRING([--disable-debug], [disable debugging mode])],
     1.7 -        enable_debug="$enableval",
     1.8 -        enable_debug=no)
     1.9 +        enable_debug=no,
    1.10 +        enable_debug=yes)
    1.11  
    1.12  if test "x$enable_debug" = "xyes"; then
    1.13      CFLAGS="$CFLAGS -g -DGMYTH_USE_DEBUG"
     2.1 --- a/gmyth/src/gmyth_file_transfer.c	Tue Mar 27 00:13:27 2007 +0100
     2.2 +++ b/gmyth/src/gmyth_file_transfer.c	Tue Mar 27 14:53:51 2007 +0100
     2.3 @@ -638,12 +638,12 @@
     2.4   * @return The actual block size (in bytes) returned by REQUEST_BLOCK message,
     2.5   * 				or the error code. 
     2.6   */
     2.7 -gint 
     2.8 +gint64 
     2.9  gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited)
    2.10  {
    2.11    gint bytes_sent = 0;
    2.12    gsize bytes_read = 0;
    2.13 -  gsize total_read = 0;
    2.14 +  gint64 total_read = 0;
    2.15    
    2.16    GError *error = NULL;
    2.17    
    2.18 @@ -697,43 +697,58 @@
    2.19      gmyth_string_list_append_int( strlist, size );
    2.20  
    2.21      // Request the block to the backend
    2.22 -    gmyth_socket_write_stringlist( transfer->control_sock, strlist );
    2.23 +    gmyth_socket_write_stringlist (transfer->control_sock, strlist);
    2.24  
    2.25      // Receives the backand answer    
    2.26 -    gmyth_socket_read_stringlist( transfer->control_sock, strlist );
    2.27 +    gmyth_socket_read_stringlist (transfer->control_sock, strlist);
    2.28  
    2.29 -    if ( strlist != NULL && gmyth_string_list_length( strlist ) > 0 ) 
    2.30 -    { 
    2.31 -	    bytes_sent = gmyth_string_list_get_int( strlist,  0 ); // -1 on backend error
    2.32 +    if (strlist != NULL && gmyth_string_list_length (strlist) > 0) { 
    2.33 +	    bytes_sent = gmyth_string_list_get_int (strlist,  0); // -1 on backend error
    2.34  	    gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
    2.35  
    2.36 -    	if ( bytes_sent > 0 )
    2.37 -    	{
    2.38 -        gchar *data_buffer = g_new0 ( gchar, bytes_sent );    
    2.39 -   	    while ( 0 != bytes_sent ) 
    2.40 -   	    { 
    2.41 -          io_status = g_io_channel_read_chars( io_channel, data_buffer + total_read, 
    2.42 -	    				(gsize) bytes_sent,	&bytes_read, &error );
    2.43 +    	if (bytes_sent > 0) {
    2.44 +            gchar *data_buffer = g_new0 (gchar, bytes_sent);
    2.45 +            while (bytes_sent > 0) { 
    2.46 +                io_status = g_io_channel_read_chars (io_channel, 
    2.47 +                                                     data_buffer,
    2.48 +                                                     (gsize) bytes_sent,
    2.49 +                                                     &bytes_read, 
    2.50 +                                                     &error);
    2.51  
    2.52 -	        total_read += bytes_read;
    2.53 -          bytes_sent -= bytes_read;
    2.54 +                if (io_status != G_IO_STATUS_NORMAL) {
    2.55 +                    gmyth_debug ("Error on io_channel");
    2.56 +                    g_free (data_buffer);
    2.57 +                    total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    2.58 +                    g_object_unref (strlist);
    2.59 +                    break;
    2.60 +                }
    2.61  
    2.62 -            /* append new data to the increasing byte array */
    2.63 -	    		data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
    2.64 -	        gmyth_debug ("Total transfer data read: %d\n", total_read);
    2.65 -        }
    2.66 -        g_free (data_buffer);
    2.67 -      } else if ( bytes_sent <= 0 && !read_unlimited ) {
    2.68 -      	total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    2.69 +                total_read += bytes_read;
    2.70 +                bytes_sent -= bytes_read;
    2.71 +
    2.72 +                /* append new data to the increasing byte array */
    2.73 +                data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
    2.74 +                gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", total_read);
    2.75 +            }
    2.76 +            g_free (data_buffer);
    2.77 +        } else if (!read_unlimited) {
    2.78 +      	    total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    2.79      		g_object_unref (strlist);
    2.80      		strlist = NULL;
    2.81      		break;
    2.82 -    	}
    2.83 -    } else if ( !read_unlimited || !(transfer->priv != NULL && transfer->priv->recorder != NULL &&
    2.84 +        } else {
    2.85 +            /* wait for more data */
    2.86 +            g_usleep (300);
    2.87 +        }
    2.88 +    } else { 
    2.89 +        /*if (!(transfer->priv != NULL && transfer->priv->recorder != NULL &&
    2.90  					transfer->priv->do_next_program_chain) ) {
    2.91 +        */                    
    2.92      	total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
    2.93 -    	g_object_unref (strlist);
    2.94 -    	strlist = NULL;
    2.95 +        if (strlist != NULL) {
    2.96 +        	g_object_unref (strlist);
    2.97 +        	strlist = NULL;
    2.98 +        }
    2.99      	break;
   2.100      }
   2.101      if ( strlist!=NULL )
   2.102 @@ -743,19 +758,15 @@
   2.103      }
   2.104    } /* while - iterates through bytes until reaches the end of stream */
   2.105  
   2.106 -  if ( read_unlimited && ( bytes_sent == 0 ) && ( max_tries == 0 ) )
   2.107 -	{
   2.108 +  if (read_unlimited && (bytes_sent == 0) && (max_tries == 0) ) {
   2.109  		gmyth_debug( "Trying to move to the next program chain..." );
   2.110  		transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
   2.111  		
   2.112  		if ( transfer->priv != NULL && transfer->priv->recorder != NULL &&
   2.113  					transfer->priv->do_next_program_chain )
   2.114  		{
   2.115 -		
   2.116 -			  total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;	
   2.117 -		
   2.118 +		    total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;	
   2.119  	  		//g_mutex_lock( transfer->mutex );
   2.120 -	  		
   2.121  	  		//ret = gmyth_livetv_next_program_chain( transfer->priv->recorder );
   2.122  	  		GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info( transfer->priv->recorder );
   2.123  	  		
   2.124 @@ -775,7 +786,7 @@
   2.125  										transfer->filename );						
   2.126  		}
   2.127  
   2.128 -	} /* if */
   2.129 +  } /* if */
   2.130    
   2.131    myth_control_release_context( transfer );
   2.132    g_string_free (query, TRUE);
     3.1 --- a/gmyth/src/gmyth_file_transfer.h	Tue Mar 27 00:13:27 2007 +0100
     3.2 +++ b/gmyth/src/gmyth_file_transfer.h	Tue Mar 27 14:53:51 2007 +0100
     3.3 @@ -102,7 +102,7 @@
     3.4                                  					     const gchar* filename);
     3.5  void                gmyth_file_transfer_close           (GMythFileTransfer *transfer);
     3.6  gboolean            gmyth_file_transfer_is_open         (GMythFileTransfer *transfer);
     3.7 -gint                gmyth_file_transfer_read            (GMythFileTransfer *transfer, 
     3.8 +gint64              gmyth_file_transfer_read            (GMythFileTransfer *transfer, 
     3.9                                                           GByteArray *data, 
    3.10                                                           gint size, 
    3.11                                                           gboolean read_unlimited);
     4.1 --- a/gmyth/src/gmyth_livetv.c	Tue Mar 27 00:13:27 2007 +0100
     4.2 +++ b/gmyth/src/gmyth_livetv.c	Tue Mar 27 14:53:51 2007 +0100
     4.3 @@ -470,7 +470,7 @@
     4.4  	
     4.5  		} /* if - changes the channel number */
     4.6  		
     4.7 -    //sleep (6);                  /* FIXME: this is evil (tpm) */
     4.8 +    sleep (6);                  /* FIXME: this is evil (tpm) */
     4.9    }
    4.10    
    4.11    /* DEBUG message */