]> granicus.if.org Git - transmission/commitdiff
(libT) eliminating tr_errno, part 1: make tr_ioTestPiece return an int instead of...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 2 Oct 2008 20:30:29 +0000 (20:30 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 2 Oct 2008 20:30:29 +0000 (20:30 +0000)
libtransmission/inout.c
libtransmission/inout.h
libtransmission/peer-mgr.c
libtransmission/verify.c

index 3cd670c41b295c1a2e76dfb1ff37437269157d71..f03bd3793f51e91957eb35e55e8826f446908b89 100644 (file)
@@ -266,22 +266,12 @@ recalculateHash( const tr_torrent * tor,
     return err;
 }
 
-tr_errno
+int
 tr_ioTestPiece( const tr_torrent * tor,
                 int                pieceIndex )
 {
-    int     err;
     uint8_t hash[SHA_DIGEST_LENGTH];
-
-    err  = recalculateHash( tor, pieceIndex, hash );
-
-    if( !err && memcmp( hash, tor->info.pieces[pieceIndex].hash,
-                        SHA_DIGEST_LENGTH ) )
-        err = TR_ERROR_IO_CHECKSUM;
-
-    tr_tordbg ( tor, "piece %d hash check: %s",
-               pieceIndex, ( err ? "FAILED" : "OK" ) );
-
-    return err;
+    const tr_errno err = recalculateHash( tor, pieceIndex, hash );
+    return !err && !memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH );
 }
 
index ac3a73ef160342019403a8c3e436d3d7d8e3c39e..4b25292e3a6b5eba21123f8bd12e25a0ac0eda9a 100644 (file)
@@ -50,12 +50,10 @@ tr_errno tr_ioWrite( const struct tr_torrent * tor,
                      const uint8_t *           writeme );
 
 /**
- * returns 0 if the piece matches its metainfo's SHA1 checksum,
- * or TR_ERROR_IO_* if there was a problem reading the piece,
- * or TR_ERROR if the checksum didn't match.
+ * returns nonzero if the piece matches its metainfo's SHA1 checksum.
  */
-tr_errno tr_ioTestPiece( const tr_torrent*,
-                         int   piece );
+int tr_ioTestPiece( const tr_torrent*,
+                    int   piece );
 
 
 /**
index 995078072c0a67a4a450557f963a4bb62b5bdca7..ba1692eb32ebcee5119ae60c10a8abb2ac2e4b2e 100644 (file)
@@ -959,22 +959,20 @@ peerCallbackFunc( void * vpeer,
             if( tr_cpPieceIsComplete( tor->completion, e->pieceIndex ) )
             {
                 const tr_piece_index_t p = e->pieceIndex;
-                const tr_errno         err = tr_ioTestPiece( tor, p );
+                const int              ok = tr_ioTestPiece( tor, p );
 
-                if( err )
+                if( !ok )
                 {
                     tr_torerr( tor,
-                              _(
-                                  "Piece %lu, which was just downloaded, failed its checksum test: %s" ),
-                              (unsigned long)p, tr_errorString( err ) );
+                              _( "Piece %lu, which was just downloaded, failed its checksum test" ),
+                              (unsigned long)p );
                 }
 
-                tr_torrentSetHasPiece( tor, p, !err );
+                tr_torrentSetHasPiece( tor, p, ok );
                 tr_torrentSetPieceChecked( tor, p, TRUE );
-                tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p,
-                                    !err );
+                tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p, ok );
 
-                if( err )
+                if( !ok )
                     gotBadPiece( t, p );
                 else
                 {
index 39fbb71715d982159bb07d4cb675f5d166a50717..c3c2ded7f9842758eff4842425575a419c9e8dad 100644 (file)
@@ -85,9 +85,8 @@ checkFile( tr_torrent *    tor,
         {
             const int      wasComplete = tr_cpPieceIsComplete(
                 tor->completion, i );
-            const tr_errno err = tr_ioTestPiece( tor, i );
 
-            if( !err ) /* yay */
+            if( tr_ioTestPiece( tor, i ) ) /* yay */
             {
                 tr_torrentSetHasPiece( tor, i, TRUE );
                 if( !wasComplete )