Changeset 356
- Timestamp:
- 04/16/05 18:54:21 (8 years ago)
- Location:
- trunk/splitpipe
- Files:
-
- 2 modified
-
Makefile (modified) (2 diffs)
-
splitpipe.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/splitpipe/Makefile
r353 r356 3 3 OUTPUTDIR=splitpipe-$(VERSION) 4 4 5 all: splitpipe 5 all: splitpipe joinpipe 6 6 7 7 clean: 8 8 rm -rf *~ *.o splitpipe 9 9 10 splitpipe_OBJECTS=splitpipe.o 10 common_OBJECTS=misc.o 11 splitpipe_OBJECTS=splitpipe.o $(common_OBJECTS) 12 joinpipe_OBJECTS=joinpipe.o $(common_OBJECTS) 11 13 12 14 splitpipe: $(splitpipe_OBJECTS) 13 15 g++ $(splitpipe_OBJECTS) -o $@ 16 17 joinpipe: $(joinpipe_OBJECTS) 18 g++ $(joinpipe_OBJECTS) -o $@ 19 14 20 15 21 check: … … 23 29 tar cvzf $(OUTPUTDIR).tar.gz $(OUTPUTDIR)/ 24 30 rm -rf $(OUTPUTDIR) 25 26 -
trunk/splitpipe/splitpipe.cc
r354 r356 21 21 #include <fcntl.h> 22 22 #include <sys/select.h> 23 #include <netinet/in.h> 23 24 #include <time.h> 24 25 #include <sys/time.h> … … 26 27 #include <stdint.h> 27 28 #include <signal.h> 28 29 #include "misc.hh" 29 30 #include "ringbuffer.hh" 30 31 … … 53 54 uint64_t getSize(const char* desc) 54 55 { 55 56 56 for(struct predef* p=predefinedSizes; p->name; ++p) { 57 57 if(!strcasecmp(p->name, desc)) … … 69 69 } 70 70 71 void unixDie(const string& during) 72 { 73 throw runtime_error("during "+string(during)+": "+strerror(errno)); 74 } 75 76 77 void setNonBlocking(int fd) 78 { 79 int flags=fcntl(fd,F_GETFL,0); 80 if(flags<0 || fcntl(fd, F_SETFL,flags|O_NONBLOCK) <0) 81 unixDie("Setting filedescriptor to nonblocking failed"); 82 } 83 84 double getTime() 85 { 86 struct timeval tv; 87 gettimeofday(&tv, 0); 88 return tv.tv_sec + tv.tv_usec/1000000.0; 89 } 90 71 pid_t g_pid; 72 void waitForOutputCommandToDie() 73 { 74 int status; 75 if(waitpid(g_pid, &status, 0) < 0) 76 unixDie("wait on child process"); 77 78 if(WIFEXITED(status)) 79 cerr<<"\nsplitpipe: output command exited with status "<<WEXITSTATUS(status)<<endl; 80 else { 81 cerr<<"\nsplitpipe: output command exited abnormally"; 82 if(WIFSIGNALED(status)) 83 cerr<<", by signal "<<WTERMSIG(status); 84 cerr<<endl; 85 } 86 } 87 88 89 void outputGaveEof(int outputfd) 90 { 91 cerr<<"\nsplitpipe: output command gave EOF, waiting for it to exit"<<endl; 92 close(outputfd); 93 waitForOutputCommandToDie(); 94 cerr<<"\nsplitpipe: future versions of splitpipe may allow you to continue, but for now.. exit\n"; 95 exit(EXIT_FAILURE); 96 } 91 97 92 98 void usage() … … 150 156 } 151 157 152 pid_t g_pid; 158 153 159 154 160 int spawnOutputThread() … … 196 202 } 197 203 198 void waitForOutputCommandToDie()199 {200 int status;201 if(waitpid(g_pid, &status, 0) < 0)202 unixDie("wait on child process");203 204 if(WIFEXITED(status))205 cerr<<"\nsplitpipe: output command exited with status "<<WEXITSTATUS(status)<<endl;206 else {207 cerr<<"\nsplitpipe: output command exited abnormally";208 if(WIFSIGNALED(status))209 cerr<<", by signal "<<WTERMSIG(status);210 cerr<<endl;211 }212 }213 204 214 205 int main(int argc, char** argv) … … 260 251 int outputfd; 261 252 uint64_t amountOutput=0; 253 uint16_t leftInStretch=0; 254 int numStretches=0; 262 255 263 256 char *buffer = new char[parameters.bufferSize]; … … 266 259 cerr<<"Prebuffering before starting output script.."; 267 260 268 bool d_firstchunk=true; 261 bool d_firstchunk=true; // first chunk does not get the 'press enter' stuff 269 262 270 263 while(1) { … … 278 271 cerr<<"splitpipe: reload media, if necessary, and press enter to continue"<<endl; 279 272 waitForUser(); 280 281 273 } 282 274 … … 332 324 rb.get(&rbuffer, &lenAvailable); 333 325 326 if(!leftInStretch) { 327 leftInStretch=min((size_t)0xffff, lenAvailable); 328 329 if(parameters.debug) 330 cerr<<"splitpipe: starting a stretch of "<<leftInStretch<<" bytes"<<endl; 331 uint16_t amount=htons(leftInStretch); 332 ret=writen(outputfd, &amount, sizeof(amount),"write of meta-data to output command"); 333 if(!ret) 334 outputGaveEof(outputfd); 335 336 numStretches++; 337 break; // go past select again, not sure if this is needed 338 } 339 334 340 uint64_t leftInChunk=parameters.chunkSize - amountOutput; 335 341 336 342 size_t len=min((uint64_t)lenAvailable, leftInChunk); 337 343 344 len=min(len, (size_t)leftInStretch); 345 338 346 if(!len) { 339 347 cerr<<"\nsplitpipe: output a full chunk, waiting for output command to exit..\n"; … … 357 365 358 366 if(!ret) { 359 cerr<<"\nsplitpipe: output command gave EOF, waiting for it to exit"<<endl; 360 close(outputfd); 361 waitForOutputCommandToDie(); 362 cerr<<"\nsplitpipe: future versions of splitpipe may allow you to continue, but for now.. exit\n"; 363 exit(EXIT_FAILURE); 367 outputGaveEof(outputfd); 364 368 } 365 369 if(parameters.debug) … … 367 371 rb.advance(ret); 368 372 369 amountOutput +=ret;370 371 totalBytesOutput +=ret;373 amountOutput += ret; 374 leftInStretch -= ret; 375 totalBytesOutput += ret; 372 376 373 377 if(parameters.debug) … … 386 390 waitForOutputCommandToDie(); 387 391 } 392 cerr<<"splitpipe: output "<<numStretches<<" stretches\n"; 388 393 } 389 394 catch(exception &e)