Exemple #1
0
			void finish(){
				AIO_PRE_CONDITION(!finished);
				for (;;){
					if (zstream.avail_out ==0 )
						new_buffer_();

					int ret = deflate(&zstream, Z_FINISH);

					if (ret == Z_STREAM_END)
					{
						if (stream_dest){
							auto rng = make_range(buf.begin(), reinterpret_cast<byte*>(zstream.next_out));
							stream_dest->write(rng);
							buffer<byte>().swap(buf);
						}
						break;
					}
					else if (ret == Z_OK || ret == Z_BUF_ERROR)
						continue;
					else
						AIO_THROW(deflate_exception)("deflate with Z_FINISH failed");
				}
				wview.reset();
				if (map_dest)
					map_dest->truncate(zstream.total_out);
				finished = true;
			}
Exemple #2
0
  void run()
  {
    struct timeval tvafter, tvpre;
    struct timezone tz;

    new_buffer_();

    gettimeofday (&tvpre , &tz);

    FILE* f = fopen(filenm_.c_str(), "r");
    IASSERT(f);
    IASSERT(fread(&count_, sizeof(uint64_t), 1, f)==1);

    boost::thread prefetch_thre(boost::bind(&self_t::prefetch_, this, f));
    boost::thread sort_thre(boost::bind(&self_t::sort_, this));

    FILE* out_f = fopen((filenm_+".out").c_str(), "w+");
    IASSERT(out_f);
    IASSERT(fwrite(&count_, sizeof(uint64_t), 1, out_f)==1);
    boost::thread out_thre(boost::bind(&self_t::output_, this, out_f));

    prefetch_thre.join();
    sort_thre.join();
    out_thre.join();

//     fseek(f, 0, SEEK_END);
//     fseek(out_f, 0, SEEK_END);
//     IASSERT((uint64_t)ftell(f)+ run_num_*sizeof(uint32_t)*2== (uint64_t)ftell(out_f));

    fseek(out_f, 0, SEEK_SET);
    IASSERT(fwrite(&count_, sizeof(uint64_t), 1, out_f)==1);
    fclose(f);
    fclose(out_f);

    if (boost::filesystem::exists(filenm_))
      boost::filesystem::remove(filenm_);
    if (boost::filesystem::exists(filenm_+".out"))
      boost::filesystem::rename(filenm_+".out", filenm_);

    gettimeofday (&tvafter , &tz);
    std::cout<<"A run is over("<<count_
             <<"): "<<((tvafter.tv_sec-tvpre.tv_sec)*1000+(tvafter.tv_usec-tvpre.tv_usec)/1000.)/60000<<" min\n";
  }
Exemple #3
0
			range<const byte*> write(const range<const byte*>& buf){
				AIO_PRE_CONDITION(!finished);
				AIO_PRE_CONDITION(zstream.avail_in == 0);
				crc = crc32(buf, crc);
				zstream.next_in = (Bytef*)buf.begin();
				zstream.avail_in = uInt(buf.size());

				for(;zstream.avail_in != 0;){
					if (zstream.avail_out ==0 )
						new_buffer_();

					switch (deflate(&zstream, Z_NO_FLUSH)){
						case Z_OK:
						case Z_BUF_ERROR:
							break;
						default:
							AIO_THROW(deflate_exception)("deflate with Z_NO_FLUSH failed");
					}
				}
				return range<const byte*>(buf.end(), buf.end());
			}