![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbTransfer/BdbPTRemoteCopySend.cc
Go to the documentation of this file.00001 //------------------------------------------------------------------------------ 00002 // File and Version Information: 00003 // $Id: BdbPTRemoteCopySend.cc,v 1.10 1999/07/27 00:03:55 svarovsk Exp $ 00004 // 00005 // Description: 00006 // 'sender' class derived from 'transfer' class 00007 // gets data from file, calculate checksum and writes to socket 00008 // file and socket must be opened and connected by caller 00009 // 00010 // Environment: 00011 // Software developed for the BaBar Detector at the SLAC B-Factory 00012 // 00013 // Author: 00014 // Gennadi S. Svarovski (svarovsk@slac.stanford.edu) 00015 // original author 00016 // 00017 // Copyright Information: 00018 // Copyright (C) 1999 Stanford Linear Accelerator Center 00019 // 00020 //------------------------------------------------------------------------------ 00021 00022 #include "BaBar/BaBar.hh" 00023 #include <sys/types.h> 00024 #include <unistd.h> 00025 #include <stdio.h> 00026 #include <stdlib.h> 00027 #include <string.h> 00028 #include <assert.h> 00029 00030 #include "BdbTransfer/BdbPTosSpecific.h" 00031 #include "BdbTransfer/BdbPTChecksumSum.h" 00032 #include "BdbTransfer/BdbPTRemoteCopyError.h" 00033 #include "BdbTransfer/BdbPTVerbose.h" 00034 #include "BdbTransfer/BdbPTRemoteCopySend.h" 00035 00036 static char cvsid[]="$Id: BdbPTRemoteCopySend.cc,v 1.10 1999/07/27 00:03:55 svarovsk Exp $"; 00037 00038 void* BdbPTRemoteCopySend::run( void ) { 00039 unsigned blocknum; 00040 char *buffer; 00041 int returnstatus = 0; 00042 BdbPTChecksumSum sum; 00043 00044 VERBOSEMSG( 3, ( "sender started ( number=%2d, total=%2d, started=%2d, bufsize=%d )\n", 00045 num, total, started, bufsize ) ); 00046 00047 buffer = new char [bufsize]; 00048 assert( buffer != NULL ); 00049 00050 // main loop across all blocks for this thread 00051 for( blocknum = num; blocknum < total; blocknum += started ) { 00052 off_t offset = (off_t)bufsize * blocknum; 00053 00054 fileMutex().lock(); 00055 offset = lseek( (int)fd, (off_t)offset, (int)SEEK_SET ); 00056 ssize_t len = read( (int)fd, (void*)buffer, (size_t)bufsize ); 00057 fileMutex().unlock(); 00058 00059 if( len < 0 ) { 00060 perror( "read" ); 00061 returnstatus = 1; 00062 break; 00063 } 00064 00065 if( !(transferOptions & BDBTRANSFER_NOCHECKSUM ) ) 00066 sum = BdbPTChecksumSum::calculate( buffer, len, NULL ); 00067 else 00068 sum = 0; 00069 00070 VERBOSEMSG( 2, ( "sending ( thread=%2d, block=%d, size=%d, checksum=%08X )\n", 00071 num, blocknum, len, sum.value() ) ); 00072 00073 // writing block number and checksum 00074 socket.writeInt( blocknum ); 00075 socket.writeInt( len ); 00076 socket.writeInt( sum.value() ); 00077 if( socket.write( buffer, len ) < len ) { 00078 perror( "sending buffer" ); 00079 returnstatus = 1; 00080 break; 00081 } 00082 00083 BdbPTRemoteCopyResult result = GOOD; 00084 socket.readInt( (int*)&result ); 00085 if( result != GOOD ) { 00086 fprintf( stderr, "error from receiver: %s\n", 00087 (const char*)BdbPTRemoteCopyError( result ) ); 00088 returnstatus = (int)result; 00089 break; 00090 } 00091 } 00092 00093 socket.close(); 00094 delete[] buffer; 00095 00096 VERBOSEMSG( 3, ( "finished ( sender=%2d, status=%d )\n", num, returnstatus ) ); 00097 00098 if( returnstatus != 0 ) // on error cancel execution of all threads 00099 ::exit( returnstatus ); 00100 00101 return (void*)returnstatus; 00102 }
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002