ZeroC

Archived

This forum has been archived. Please start a new discussion on GitHub.

transfer file with Ice

zhongshiz
zhongshiz
hi!
I use ice to develop transfer files, got the follow message, also i found my memoy reduce faster, thank you for help!
10/11/07 09:47:30.546 warning: dispatch exception: Thread.cpp:428: IceUtil::ThreadSyscallException:
thread syscall exception: Cannot allocate memory
identity: ReadCache
facet:
operation: ReadVideoNew



module libiceDef{
exception FileAccessException
{
string reason;
};

interface iReadVideo
{
["amd", "cpp:array"] ByteSeq read(string name, int offset, int num)
throws FileAccessException;
};

};



server:

FILE* fp = fopen( name.c_str(), "rb" );
if(fp == 0)
{
FileAccessException ex;
ex.reason = "cannot open `" + name + "' for reading: " + strerror(errno);
cb->ice_exception(ex);
return;
}

pair<const Ice::Byte*, const Ice::Byte*> ret(0, 0);
if( fseek(fp, offset, SEEK_SET) != 0 )
{
cb->ice_response( ret );
fclose(fp);
return;
}
IceUtil::ScopedArray<Ice::Byte> bytes(new Ice::Byte[num]);
int r = fread( bytes.get(), 1, num, fp);
fclose(fp);

ret.first = bytes.get();
ret.second = ret.first + r;
cb->ice_response(ret);

client:

int rc = EXIT_SUCCESS;
try
{
int len = 1000*1024;
FILE *fp = fopen( dest_file.c_str(), "wb" );
int offset = 0;
IceUtil::Time start = IceUtil::Time::now();
//2007-10-10
libiceDef::ByteSeq data;
while( 1 )
{
data = _c->read( src_file, offset, len ); //ReadVideo

if( data.size() == 0 )
{
break;
}

if( fwrite( &data[0], 1, data.size(), fp ) != data.size() )
{
cerr << "error writing: " << strerror(errno) << endl;
rc = EXIT_FAILURE;
}
cout << __FILE__ << " offset=" << offset << endl;
offset += data.size();
/*data.resize(0);
data.clear();*/
libiceDef::ByteSeq().swap( data );
cout << "data size=" << data.size() << endl;
}
libiceDef::ByteSeq().swap( data );

fclose( fp );

IceUtil::Time tm = IceUtil::Time::now() - start;
double mbs = ( offset/(1024.0 * 1024.0) ) / tm.toSecondsDouble();
cout << "throughput " << mbs << " MB/s" << endl;
}
catch( const FileAccessException &e )
{
cerr << "FileAccessException: " << e.reason << endl;
rc = EXIT_FAILURE;
}
return rc;

Comments

  • michi
    michi
    Looks like you are trying to allocate more memory than your process is allowed to have. Please this FAQ for some pointers on how to implement file transfer.

    Cheers,

    Michi.
  • dwayne
    dwayne St. John's, Newfoundland
    It would also be a good idea to read Matthew's newsletter article on optimizing file transfer here.

    Dwayne
  • zhongshiz
    zhongshiz
    dwayne wrote: »
    It would also be a good idea to read Matthew's newsletter article on optimizing file transfer here.

    Dwayne

    my program is base on the Matthew's newsletter article to develop.
  • matthew
    matthew NL, Canada
    If you haven't worked out what is causing your problems and you still need help the easiest way is to post a complete self contained compilable example that demonstrates your problem.