summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
authorerdgeist <>2006-12-08 22:53:32 +0000
committererdgeist <>2006-12-08 22:53:32 +0000
commit932242eee7d99559bf8e0b4cec2b140f567a8149 (patch)
treedfd076af04012effb9f98d19363e8299d14a042c /trackerlogic.c
parentdc025776dd77e2f8da1e2ee0667962115bf90bc8 (diff)
Logic now actually initialized and deinitialized
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index ab1f419..1407522 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -212,7 +212,7 @@ void heal_torrent( ot_torrent torrent ) {
212} 212}
213 213
214void dispose_torrent( ot_torrent torrent ) { 214void dispose_torrent( ot_torrent torrent ) {
215 unmap_file( "", torrent->peer_list, 0 ); 215 unmap_file( NULL, torrent->peer_list, 0 );
216 unlink( to_hex( torrent->hash ) ); 216 unlink( to_hex( torrent->hash ) );
217 MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) ); 217 MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) );
218 torrents_count--; 218 torrents_count--;
@@ -229,11 +229,11 @@ void *map_file( char *file_name ) {
229 int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644); 229 int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644);
230 if( file_desc < 0) return 0; 230 if( file_desc < 0) return 0;
231 lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET ); 231 lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET );
232 232 write( file_desc, "_", 1 );
233 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_SHARED,file_desc,0); 233 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_SHARED,file_desc,0);
234 close(file_desc); 234 close(file_desc);
235 } else 235 } else
236 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_ANON,-1,0); 236 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_ANON|MAP_PRIVATE,-1,0);
237 237
238 return (map == (char*)-1) ? 0 : map; 238 return (map == (char*)-1) ? 0 : map;
239} 239}
@@ -259,13 +259,15 @@ int init_logic( char *directory ) {
259 if( directory ) 259 if( directory )
260 chdir( directory ); 260 chdir( directory );
261 261
262 scratch_space = map_file( "" ); 262 scratch_space = map_file( NULL );
263 torrents_list = map_file( "" ); 263 torrents_list = map_file( NULL );
264 torrents_count = 0; 264 torrents_count = 0;
265 265
266 printf( "%08x %08x\n", scratch_space, torrents_list );
267
266 if( !scratch_space || !torrents_list ) { 268 if( !scratch_space || !torrents_list ) {
267 if( scratch_space || torrents_list ) 269 if( scratch_space || torrents_list )
268 unmap_file( "", scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 ); 270 unmap_file( NULL, scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 );
269 return -1; 271 return -1;
270 } 272 }
271 273
@@ -308,6 +310,6 @@ void deinit_logic( ) {
308 // For all torrents... blablabla 310 // For all torrents... blablabla
309 while( torrents_count-- ) 311 while( torrents_count-- )
310 unmap_file( to_hex(torrents_list[torrents_count].hash), torrents_list[torrents_count].peer_list, torrents_list[torrents_count].peer_count * sizeof(struct ot_peer) ); 312 unmap_file( to_hex(torrents_list[torrents_count].hash), torrents_list[torrents_count].peer_list, torrents_list[torrents_count].peer_count * sizeof(struct ot_peer) );
311 unmap_file( "", torrents_list, 0 ); 313 unmap_file( NULL, torrents_list, 0 );
312 unmap_file( "", scratch_space, 0 ); 314 unmap_file( NULL, scratch_space, 0 );
313} 315}