source: trunk/libtransmission/torrent.c @ 1579

Last change on this file since 1579 was 1579, checked in by joshe, 15 years ago

Merge PEX branch, I hope this works.

  • Property svn:keywords set to Date Rev Author Id
File size: 20.7 KB
Line 
1/******************************************************************************
2 * $Id: torrent.c 1579 2007-03-23 08:28:01Z joshe $
3 *
4 * Copyright (c) 2005-2007 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#include "transmission.h"
26#include "shared.h"
27
28/***********************************************************************
29 * Local prototypes
30 **********************************************************************/
31static tr_torrent_t * torrentRealInit( tr_handle_t *, tr_torrent_t * tor,
32                                       uint8_t *, int flags, int * error );
33static void torrentReallyStop( tr_torrent_t * );
34static void downloadLoop( void * );
35
36void tr_setUseCustomUpload( tr_torrent_t * tor, int limit )
37{
38    tor->customUploadLimit = limit;
39}
40
41void tr_setUseCustomDownload( tr_torrent_t * tor, int limit )
42{
43    tor->customDownloadLimit = limit;
44}
45
46void tr_setUploadLimit( tr_torrent_t * tor, int limit )
47{
48    tr_rcSetLimit( tor->upload, limit );
49}
50
51void tr_setDownloadLimit( tr_torrent_t * tor, int limit )
52{
53    tr_rcSetLimit( tor->download, limit );
54}
55
56tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path,
57                               uint8_t * hash, int flags, int * error )
58{
59    tr_torrent_t  * tor = calloc( sizeof( tr_torrent_t ), 1 );
60    int             saveCopy = ( TR_FLAG_SAVE & flags );
61
62    /* Parse torrent file */
63    if( tr_metainfoParse( &tor->info, h->tag, path, NULL, saveCopy ) )
64    {
65        *error = TR_EINVALID;
66        free( tor );
67        return NULL;
68    }
69
70    return torrentRealInit( h, tor, hash, flags, error );
71}
72
73tr_torrent_t * tr_torrentInitSaved( tr_handle_t * h, const char * hashStr,
74                                    int flags, int * error )
75{
76    tr_torrent_t  * tor = calloc( sizeof( tr_torrent_t ), 1 );
77
78    /* Parse torrent file */
79    if( tr_metainfoParse( &tor->info, h->tag, NULL, hashStr, 0 ) )
80    {
81        *error = TR_EINVALID;
82        free( tor );
83        return NULL;
84    }
85
86    return torrentRealInit( h, tor, NULL, ( TR_FLAG_SAVE | flags ), error );
87}
88
89/***********************************************************************
90 * tr_torrentInit
91 ***********************************************************************
92 * Allocates a tr_torrent_t structure, then relies on tr_metainfoParse
93 * to fill it.
94 **********************************************************************/
95static tr_torrent_t * torrentRealInit( tr_handle_t * h, tr_torrent_t * tor,
96                                       uint8_t * hash, int flags, int * error )
97{
98    tr_torrent_t  * tor_tmp;
99    tr_info_t     * inf;
100    int             i;
101   
102    inf         = &tor->info;
103    inf->flags |= flags;
104
105    tr_sharedLock( h->shared );
106
107    /* Make sure this torrent is not already open */
108    for( tor_tmp = h->torrentList; tor_tmp; tor_tmp = tor_tmp->next )
109    {
110        if( !memcmp( tor->info.hash, tor_tmp->info.hash,
111                     SHA_DIGEST_LENGTH ) )
112        {
113            if( NULL != hash )
114            {
115                memcpy( hash, tor->info.hash, SHA_DIGEST_LENGTH );
116            }
117            *error = TR_EDUPLICATE;
118            tr_metainfoFree( &tor->info );
119            free( tor );
120            tr_sharedUnlock( h->shared );
121            return NULL;
122        }
123    }
124
125    tor->handle   = h;
126    tor->status   = TR_STATUS_PAUSE;
127    tor->id       = h->id;
128    tor->key      = h->key;
129    tor->azId     = h->azId;
130    tor->finished = 0;
131
132    /* Escaped info hash for HTTP queries */
133    for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
134    {
135        snprintf( &tor->escapedHashString[3*i],
136                  sizeof( tor->escapedHashString ) - 3 * i,
137                  "%%%02x", inf->hash[i] );
138    }
139
140    /* Block size: usually 16 ko, or less if we have to */
141    tor->blockSize  = MIN( inf->pieceSize, 1 << 14 );
142    tor->blockCount = ( inf->totalSize + tor->blockSize - 1 ) /
143                        tor->blockSize;
144    tor->completion = tr_cpInit( tor );
145
146    tr_lockInit( &tor->lock );
147    tr_condInit( &tor->cond );
148
149    tor->upload         = tr_rcInit();
150    tor->download       = tr_rcInit();
151    tor->swarmspeed     = tr_rcInit();
152 
153    /* We have a new torrent */
154    tor->publicPort = tr_sharedGetPublicPort( h->shared );
155    tor->prev       = NULL;
156    tor->next       = h->torrentList;
157    if( tor->next )
158    {
159        tor->next->prev = tor;
160    }
161    h->torrentList = tor;
162    (h->torrentCount)++;
163
164    tr_sharedUnlock( h->shared );
165
166    if( !h->isPortSet )
167    {
168        tr_setBindPort( h, TR_DEFAULT_PORT );
169    }
170
171    return tor;
172}
173
174tr_info_t * tr_torrentInfo( tr_torrent_t * tor )
175{
176    return &tor->info;
177}
178
179/***********************************************************************
180 * tr_torrentScrape     
181 **********************************************************************/
182int tr_torrentScrape( tr_torrent_t * tor, int * s, int * l, int * d )
183{
184    return tr_trackerScrape( tor, s, l, d );
185}
186
187void tr_torrentSetFolder( tr_torrent_t * tor, const char * path )
188{
189    tor->destination = strdup( path );
190    tr_ioLoadResume( tor );
191}
192
193char * tr_torrentGetFolder( tr_torrent_t * tor )
194{
195    return tor->destination;
196}
197
198void tr_torrentStart( tr_torrent_t * tor )
199{
200    char name[32];
201
202    if( tor->status & ( TR_STATUS_STOPPING | TR_STATUS_STOPPED ) )
203    {
204        /* Join the thread first */
205        torrentReallyStop( tor );
206    }
207
208    tr_lockLock( &tor->lock );
209
210    tor->downloadedPrev += tor->downloadedCur;
211    tor->downloadedCur   = 0;
212    tor->uploadedPrev   += tor->uploadedCur;
213    tor->uploadedCur     = 0;
214
215    tor->status  = TR_STATUS_CHECK;
216    tor->error   = TR_OK;
217    tor->tracker = tr_trackerInit( tor );
218
219    tor->date = tr_date();
220    tor->die = 0;
221    snprintf( name, sizeof( name ), "torrent %p", tor );
222
223    tr_lockUnlock( &tor->lock );
224
225    tr_threadCreate( &tor->thread, downloadLoop, tor, name );
226}
227
228static void torrentStop( tr_torrent_t * tor )
229{
230    tr_trackerStopped( tor->tracker );
231    tr_rcReset( tor->download );
232    tr_rcReset( tor->upload );
233    tr_rcReset( tor->swarmspeed );
234    tor->status = TR_STATUS_STOPPING;
235    tor->stopDate = tr_date();
236}
237
238void tr_torrentStop( tr_torrent_t * tor )
239{
240    tr_lockLock( &tor->lock );
241    torrentStop( tor );
242
243    /* Don't return until the files are closed, so the UI can trash
244     * them if requested */
245    tr_condWait( &tor->cond, &tor->lock );
246    tr_lockUnlock( &tor->lock );
247}
248
249/***********************************************************************
250 * torrentReallyStop
251 ***********************************************************************
252 * Joins the download thread and frees/closes everything related to it.
253 **********************************************************************/
254static void torrentReallyStop( tr_torrent_t * tor )
255{
256    int i;
257
258    tor->die = 1;
259    tr_threadJoin( &tor->thread );
260
261    tr_trackerClose( tor->tracker );
262    tor->tracker = NULL;
263
264    tr_lockLock( &tor->lock );
265    for( i = 0; i < tor->peerCount; i++ )
266    {
267        tr_peerDestroy( tor->peers[i] );
268    }
269    tor->peerCount = 0;
270    tr_lockUnlock( &tor->lock );
271}
272
273int tr_getFinished( tr_torrent_t * tor )
274{
275    if( tor->finished )
276    {
277        tor->finished = 0;
278        return 1;
279    }
280    return 0;
281}
282
283void tr_manualUpdate( tr_torrent_t * tor )
284{
285    int peerCount;
286    uint8_t * peerCompact;
287
288    if( !( tor->status & TR_STATUS_ACTIVE ) )
289        return;
290   
291    tr_lockLock( &tor->lock );
292    tr_trackerAnnouncePulse( tor->tracker, &peerCount, &peerCompact, 1 );
293    if( peerCount > 0 )
294    {
295        tr_torrentAddCompact( tor, TR_PEER_FROM_TRACKER,
296                              peerCompact, peerCount );
297        free( peerCompact );
298    }
299    tr_lockUnlock( &tor->lock );
300}
301
302tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
303{
304    tr_stat_t * s;
305    tr_peer_t * peer;
306    tr_info_t * inf = &tor->info;
307    tr_tracker_t * tc;
308    int i;
309
310    tor->statCur = ( tor->statCur + 1 ) % 2;
311    s = &tor->stats[tor->statCur];
312
313    if( ( tor->status & TR_STATUS_STOPPED ) ||
314        ( ( tor->status & TR_STATUS_STOPPING ) &&
315          tr_date() > tor->stopDate + 60000 ) )
316    {
317        torrentReallyStop( tor );
318        tor->status = TR_STATUS_PAUSE;
319    }
320
321    tr_lockLock( &tor->lock );
322
323    s->status = tor->status;
324    s->error  = tor->error;
325    memcpy( s->errorString, tor->errorString,
326            sizeof( s->errorString ) );
327
328    tc = tor->tracker;
329    s->cannotConnect = tr_trackerCannotConnect( tc );
330    s->tracker = ( tc ? tr_trackerGet( tc ) : &inf->trackerList[0].list[0] );
331
332    s->peersTotal       = 0;
333    memset( s->peersFrom, 0, sizeof( s->peersFrom ) );
334    s->peersUploading   = 0;
335    s->peersDownloading = 0;
336   
337    for( i = 0; i < tor->peerCount; i++ )
338    {
339        peer = tor->peers[i];
340   
341        if( tr_peerIsConnected( peer ) )
342        {
343            (s->peersTotal)++;
344            (s->peersFrom[ tr_peerIsFrom( peer ) ])++;
345            if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
346            {
347                (s->peersUploading)++;
348            }
349            if( !tr_peerAmChoking( peer ) )
350            {
351                (s->peersDownloading)++;
352            }
353        }
354    }
355
356    s->progress = tr_cpCompletionAsFloat( tor->completion );
357    if( tor->status & TR_STATUS_DOWNLOAD )
358    {
359        s->rateDownload = tr_rcRate( tor->download );
360    }
361    else
362    {
363        /* tr_rcRate() doesn't make the difference between 'piece'
364           messages and other messages, which causes a non-zero
365           download rate even tough we are not downloading. So we
366           force it to zero not to confuse the user. */
367        s->rateDownload = 0.0;
368    }
369    s->rateUpload = tr_rcRate( tor->upload );
370   
371    s->seeders  = tr_trackerSeeders( tc );
372    s->leechers = tr_trackerLeechers( tc );
373    s->completedFromTracker = tr_trackerDownloaded( tc );
374
375    s->swarmspeed = tr_rcRate( tor->swarmspeed );
376
377    if( s->rateDownload < 0.1 )
378    {
379        s->eta = -1;
380    }
381    else
382    {
383        s->eta = ( 1.0 - s->progress ) *
384            (float) inf->totalSize / s->rateDownload / 1024.0;
385    }
386
387    s->downloaded = tor->downloadedCur + tor->downloadedPrev;
388    s->uploaded   = tor->uploadedCur   + tor->uploadedPrev;
389   
390    if( s->downloaded == 0 )
391    {
392        s->ratio = s->uploaded == 0 ? TR_RATIO_NA : TR_RATIO_INF;
393    }
394    else
395    {
396        s->ratio = (float)s->uploaded / (float)s->downloaded;
397    }
398   
399    tr_lockUnlock( &tor->lock );
400
401    return s;
402}
403
404tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount )
405{
406    tr_peer_stat_t * peers;
407
408    tr_lockLock( &tor->lock );
409
410    *peerCount = tor->peerCount;
411   
412    peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) );
413    if (peers != NULL)
414    {
415        tr_peer_t * peer;
416        struct in_addr * addr;
417        int i;
418        for( i = 0; i < tor->peerCount; i++ )
419        {
420            peer = tor->peers[i];
421           
422            addr = tr_peerAddress( peer );
423            if( NULL != addr )
424            {
425                tr_netNtop( addr, peers[i].addr,
426                           sizeof( peers[i].addr ) );
427            }
428           
429            peers[i].client = tr_clientForId(tr_peerId(peer));
430           
431            peers[i].isConnected   = tr_peerIsConnected( peer );
432            peers[i].from          = tr_peerIsFrom( peer );
433            peers[i].progress      = tr_peerProgress( peer );
434            peers[i].port          = tr_peerPort( peer );
435           
436            if( ( peers[i].isDownloading = !tr_peerAmChoking( peer ) ) )
437            {
438                peers[i].uploadToRate = tr_peerUploadRate( peer );
439            }
440            if( ( peers[i].isUploading = ( tr_peerAmInterested( peer ) &&
441                                           !tr_peerIsChoking( peer ) ) ) )
442            {
443                peers[i].downloadFromRate = tr_peerDownloadRate( peer );
444            }
445        }
446    }
447   
448    tr_lockUnlock( &tor->lock );
449   
450    return peers;
451}
452
453void tr_torrentPeersFree( tr_peer_stat_t * peers, int peerCount )
454{
455    int i;
456
457    if (peers == NULL)
458        return;
459
460    for (i = 0; i < peerCount; i++)
461        free( peers[i].client );
462
463    free( peers );
464}
465
466void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
467{
468    int i, j, piece;
469    float interval;
470
471    tr_lockLock( &tor->lock );
472    interval = (float)tor->info.pieceCount / (float)size;
473    for( i = 0; i < size; i++ )
474    {
475        piece = i * interval;
476
477        if( tr_cpPieceIsComplete( tor->completion, piece ) )
478        {
479            tab[i] = -1;
480            continue;
481        }
482
483        tab[i] = 0;
484        for( j = 0; j < tor->peerCount; j++ )
485        {
486            if( tr_peerBitfield( tor->peers[j] ) &&
487                tr_bitfieldHas( tr_peerBitfield( tor->peers[j] ), piece ) )
488            {
489                (tab[i])++;
490            }
491        }
492    }
493    tr_lockUnlock( &tor->lock );
494}
495
496float * tr_torrentCompletion( tr_torrent_t * tor )
497{
498    tr_info_t * inf = &tor->info;
499    int         piece, file;
500    float     * ret, prog, weight;
501    uint64_t    piecemax, piecesize;
502    uint64_t    filestart, fileoff, filelen, blockend, blockused;
503
504    tr_lockLock( &tor->lock );
505
506    ret       = calloc( inf->fileCount, sizeof( float ) );
507    file      = 0;
508    piecemax  = inf->pieceSize;
509    filestart = 0;
510    fileoff   = 0;
511    piece     = 0;
512    while( inf->pieceCount > piece )
513    {
514        assert( file < inf->fileCount );
515        assert( filestart + fileoff < inf->totalSize );
516        filelen    = inf->files[file].length;
517        piecesize  = tr_pieceSize( piece );
518        blockend   = MIN( filestart + filelen, piecemax * piece + piecesize );
519        blockused  = blockend - ( filestart + fileoff );
520        weight     = ( filelen ? ( float )blockused / ( float )filelen : 1.0 );
521        prog       = tr_cpPercentBlocksInPiece( tor->completion, piece );
522        ret[file] += prog * weight;
523        fileoff   += blockused;
524        assert( -0.1 < prog   && 1.1 > prog );
525        assert( -0.1 < weight && 1.1 > weight );
526        if( fileoff == filelen )
527        {
528            ret[file] = MIN( 1.0, ret[file] );
529            ret[file] = MAX( 0.0, ret[file] );
530            filestart += fileoff;
531            fileoff    = 0;
532            file++;
533        }
534        if( filestart + fileoff >= piecemax * piece + piecesize )
535        {
536            piece++;
537        }
538    }
539
540    tr_lockUnlock( &tor->lock );
541
542    return ret;
543}
544
545void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size )
546{
547    int i, piece;
548    float interval;
549
550    tr_lockLock( &tor->lock );
551    interval = (float)tor->info.pieceCount / (float)size;
552    for( i = 0; i < size; i++ )
553    {
554        piece = i * interval;
555        tab[i] = tr_cpPercentBlocksInPiece( tor->completion, piece );
556    }
557    tr_lockUnlock( &tor->lock );
558}
559
560void tr_torrentRemoveSaved( tr_torrent_t * tor )
561{
562    tr_metainfoRemoveSaved( tor->info.hashString, tor->handle->tag );
563}
564
565/***********************************************************************
566 * tr_torrentClose
567 ***********************************************************************
568 * Frees memory allocated by tr_torrentInit.
569 **********************************************************************/
570void tr_torrentClose( tr_handle_t * h, tr_torrent_t * tor )
571{
572    tr_info_t * inf = &tor->info;
573
574    if( tor->status & ( TR_STATUS_STOPPING | TR_STATUS_STOPPED ) )
575    {
576        /* Join the thread first */
577        torrentReallyStop( tor );
578    }
579
580    tr_sharedLock( h->shared );
581
582    h->torrentCount--;
583
584    tr_lockClose( &tor->lock );
585    tr_condClose( &tor->cond );
586    tr_cpClose( tor->completion );
587
588    tr_rcClose( tor->upload );
589    tr_rcClose( tor->download );
590    tr_rcClose( tor->swarmspeed );
591
592    if( tor->destination )
593    {
594        free( tor->destination );
595    }
596
597    tr_metainfoFree( inf );
598
599    if( tor->prev )
600    {
601        tor->prev->next = tor->next;
602    }
603    else
604    {
605        h->torrentList = tor->next;
606    }
607    if( tor->next )
608    {
609        tor->next->prev = tor->prev;
610    }
611    free( tor );
612
613    tr_sharedUnlock( h->shared );
614}
615
616void tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * peer )
617{
618    int i;
619    tr_peer_t * otherPeer;
620
621    if( tor->peerCount >= TR_MAX_PEER_COUNT )
622    {
623        tr_peerDestroy(  peer );
624        return;
625    }
626
627    /* Don't accept two connections from the same IP */
628    for( i = 0; i < tor->peerCount; i++ )
629    {
630        otherPeer = tor->peers[i];
631        if( !memcmp( tr_peerAddress( peer ), tr_peerAddress( otherPeer ), 4 ) )
632        {
633            tr_peerDestroy(  peer );
634            return;
635        }
636    }
637
638    tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE );
639    tr_peerSetTorrent( peer, tor );
640    tor->peers[tor->peerCount++] = peer;
641}
642
643void tr_torrentAddCompact( tr_torrent_t * tor, int from,
644                           uint8_t * buf, int count )
645{
646    struct in_addr addr;
647    in_port_t port;
648    int i;
649    tr_peer_t * peer;
650
651    for( i = 0; i < count; i++ )
652    {
653        memcpy( &addr, buf, 4 ); buf += 4;
654        memcpy( &port, buf, 2 ); buf += 2;
655
656        peer = tr_peerInit( addr, port, -1, from );
657        tr_torrentAttachPeer( tor, peer );
658    }
659}
660
661/***********************************************************************
662 * downloadLoop
663 **********************************************************************/
664static void downloadLoop( void * _tor )
665{
666    tr_torrent_t * tor = _tor;
667    int            i, ret;
668    int            peerCount;
669    uint8_t      * peerCompact;
670    tr_peer_t    * peer;
671
672    tr_lockLock( &tor->lock );
673
674    tr_cpReset( tor->completion );
675    tor->io     = tr_ioInit( tor );
676    tor->status = tr_cpIsSeeding( tor->completion ) ?
677                      TR_STATUS_SEED : TR_STATUS_DOWNLOAD;
678
679    while( !tor->die )
680    {
681        tr_lockUnlock( &tor->lock );
682        tr_wait( 20 );
683        tr_lockLock( &tor->lock );
684
685        /* Are we finished ? */
686        if( ( tor->status & TR_STATUS_DOWNLOAD ) &&
687            tr_cpIsSeeding( tor->completion ) )
688        {
689            /* Done */
690            tor->status = TR_STATUS_SEED;
691                        tor->finished = 1;
692            tr_trackerCompleted( tor->tracker );
693            tr_ioSync( tor->io );
694        }
695
696        /* Try to get new peers or to send a message to the tracker */
697        tr_trackerPulse( tor->tracker, &peerCount, &peerCompact );
698        if( peerCount > 0 )
699        {
700            tr_torrentAddCompact( tor, TR_PEER_FROM_TRACKER,
701                                  peerCompact, peerCount );
702            free( peerCompact );
703        }
704        if( tor->status & TR_STATUS_STOPPED )
705        {
706            break;
707        }
708
709        /* Stopping: make sure all files are closed and stop talking
710           to peers */
711        if( tor->status & TR_STATUS_STOPPING )
712        {
713            if( tor->io )
714            {
715                tr_ioClose( tor->io ); tor->io = NULL;
716                tr_condSignal( &tor->cond );
717            }
718            continue;
719        }
720
721        /* Shuffle peers */
722        if( tor->peerCount > 1 )
723        {
724            peer = tor->peers[0];
725            memmove( &tor->peers[0], &tor->peers[1],
726                    ( tor->peerCount - 1 ) * sizeof( void * ) );
727            tor->peers[tor->peerCount - 1] = peer;
728        }
729
730        /* Receive/send messages */
731        for( i = 0; i < tor->peerCount; )
732        {
733            peer = tor->peers[i];
734
735            ret = tr_peerPulse( peer );
736            if( ret & TR_ERROR_IO_MASK )
737            {
738                tr_err( "Fatal error, stopping download (%d)", ret );
739                torrentStop( tor );
740                tor->error = ret;
741                snprintf( tor->errorString, sizeof( tor->errorString ),
742                          "%s", tr_errorString( ret ) );
743                break;
744            }
745            if( ret )
746            {
747                tr_peerDestroy( peer );
748                tor->peerCount--;
749                memmove( &tor->peers[i], &tor->peers[i+1],
750                         ( tor->peerCount - i ) * sizeof( void * ) );
751                continue;
752            }
753            i++;
754        }
755    }
756
757    tr_lockUnlock( &tor->lock );
758
759    if( tor->io )
760    {
761        tr_ioClose( tor->io ); tor->io = NULL;
762        tr_condSignal( &tor->cond );
763    }
764
765    tor->status = TR_STATUS_STOPPED;
766}
767
Note: See TracBrowser for help on using the repository browser.