// Continue reading output void operator()() { // This assumes there aren't any 0's in the mongo program output. // Hope that's ok. char buf[ 1024 ]; char temp[ 1024 ]; char *start = buf; while( 1 ) { int lenToRead = 1023 - ( start - buf ); int ret = read( pipe_, (void *)start, lenToRead ); assert( ret != -1 ); start[ ret ] = '\0'; if ( strlen( start ) != unsigned( ret ) ) writeMongoProgramOutputLine( port_, pid_, "WARNING: mongod wrote null bytes to output" ); char *last = buf; for( char *i = strchr( buf, '\n' ); i; last = i + 1, i = strchr( last, '\n' ) ) { *i = '\0'; writeMongoProgramOutputLine( port_, pid_, last ); } if ( ret == 0 ) { if ( *last ) writeMongoProgramOutputLine( port_, pid_, last ); close( pipe_ ); break; } if ( last != buf ) { strcpy( temp, last ); strcpy( buf, temp ); } else { assert( strlen( buf ) < 1023 ); } start = buf + strlen( buf ); } }
// Continue reading output void operator()() { try { // This assumes there aren't any 0's in the mongo program output. // Hope that's ok. const unsigned bufSize = 128 * 1024; char buf[ bufSize ]; char temp[ bufSize ]; char *start = buf; while( 1 ) { int lenToRead = ( bufSize - 1 ) - ( start - buf ); if ( lenToRead <= 0 ) { cout << "error: lenToRead: " << lenToRead << endl; cout << "first 300: " << string(buf,0,300) << endl; } assert( lenToRead > 0 ); int ret = read( pipe_, (void *)start, lenToRead ); if( mongo::dbexitCalled ) break; assert( ret != -1 ); start[ ret ] = '\0'; if ( strlen( start ) != unsigned( ret ) ) writeMongoProgramOutputLine( port_, pid_, "WARNING: mongod wrote null bytes to output" ); char *last = buf; for( char *i = strchr( buf, '\n' ); i; last = i + 1, i = strchr( last, '\n' ) ) { *i = '\0'; writeMongoProgramOutputLine( port_, pid_, last ); } if ( ret == 0 ) { if ( *last ) writeMongoProgramOutputLine( port_, pid_, last ); close( pipe_ ); break; } if ( last != buf ) { strcpy( temp, last ); strcpy( buf, temp ); } else { assert( strlen( buf ) < bufSize ); } start = buf + strlen( buf ); } } catch(...) { } }