# HG changeset patch # User renatofilho # Date 1175782512 -3600 # Node ID b90373d8534b6f2cb3cd42b4a463007d3c1095d5 # Parent 2b5355061b667ece2711683c0654a1957ac0a100 [svn r510] fixed file_read diff -r 2b5355061b66 -r b90373d8534b gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Wed Apr 04 23:30:44 2007 +0100 +++ b/gmyth/src/gmyth_file_transfer.c Thu Apr 05 15:15:12 2007 +0100 @@ -631,6 +631,7 @@ GIOStatus io_status_control = G_IO_STATUS_NORMAL; GMythStringList *strlist; + GMythStringList *ret_strlist = NULL; gboolean ret = TRUE; GString *query; @@ -671,62 +672,69 @@ gmyth_string_list_append_char_array (strlist, "REQUEST_BLOCK" ); gmyth_string_list_append_int (strlist, size - total_read); - // Request the block to the backend - gmyth_socket_write_stringlist (priv->control_sock, strlist); + do { + bytes_sent = 0; + + // Request the block to the backend + gmyth_socket_write_stringlist (priv->control_sock, strlist); - // Receives the backand answer - gmyth_socket_read_stringlist (priv->control_sock, strlist); + if (ret_strlist != NULL) + g_object_unref (ret_strlist); - if (strlist != NULL && gmyth_string_list_length (strlist) > 0) { - bytes_sent = gmyth_string_list_get_int (strlist, 0); // -1 on backend error - gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent ); + ret_strlist = gmyth_string_list_new (); + // Receives the backand answer + gmyth_socket_read_stringlist (priv->control_sock, ret_strlist); + + if (ret_strlist != NULL && gmyth_string_list_length (ret_strlist) > 0) { + bytes_sent = gmyth_string_list_get_int (ret_strlist, 0); // -1 on backend error + gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent ); + } - if (bytes_sent > 0) { - gchar *data_buffer = g_new0 (gchar, bytes_sent); - io_status = g_io_channel_read_chars (io_channel, - data_buffer, - (gsize) bytes_sent, - &bytes_read, - &error); + } while (read_unlimited && (bytes_sent == 0)); - if (io_status != G_IO_STATUS_NORMAL) { - gmyth_debug ("Error on io_channel"); - g_free (data_buffer); - g_object_unref (strlist); - retval = GMYTH_FILE_TRANSFER_READ_ERROR; - goto error; - } + if (bytes_sent > 0) { + gchar *data_buffer = g_new0 (gchar, bytes_sent); + io_status = g_io_channel_read_chars (io_channel, + data_buffer, + (gsize) bytes_sent, + &bytes_read, + &error); - /* append new data to the increasing byte array */ - data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); - priv->offset += bytes_read; - - if ((priv->filesize > 0) && (priv->offset == priv->filesize)) { - retval = GMYTH_FILE_TRANSFER_READ_EOF; - goto error; - } - + if (io_status != G_IO_STATUS_NORMAL) { + gmyth_debug ("Error on io_channel"); g_free (data_buffer); - } else if (!read_unlimited) { - g_object_unref (strlist); - strlist = NULL; + g_object_unref (strlist); retval = GMYTH_FILE_TRANSFER_READ_ERROR; goto error; } + + /* append new data to the increasing byte array */ + data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); + priv->offset += bytes_read; + + if (!read_unlimited && (priv->filesize > 0) && (priv->offset == priv->filesize)) { + retval = GMYTH_FILE_TRANSFER_READ_EOF; + goto error; + } + + g_free (data_buffer); } else { retval = GMYTH_FILE_TRANSFER_READ_ERROR; - if (strlist != NULL) { - g_object_unref (strlist); - strlist = NULL; - } } - if ( strlist!=NULL ) + if (strlist!=NULL) { g_object_unref (strlist); strlist = NULL; } + if (ret_strlist!=NULL) + { + g_object_unref (ret_strlist); + ret_strlist = NULL; + } + + if (read_unlimited && (bytes_sent == 0)) { gmyth_debug( "Trying to move to the next program chain..." ); if (priv->recorder != NULL &&