diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-04-04 16:07:03 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-04-04 16:07:03 +0000 |
commit | fc29b8818ddf5af43cdc8e5df43f0dbf0430f00c (patch) | |
tree | 72b57f3711dad43a761a7defd66fc15eeb70282b /cpp/src/IcePatch2/FileServerI.cpp | |
parent | Bug 919 - use requestId to set forwarding (diff) | |
download | ice-fc29b8818ddf5af43cdc8e5df43f0dbf0430f00c.tar.bz2 ice-fc29b8818ddf5af43cdc8e5df43f0dbf0430f00c.tar.xz ice-fc29b8818ddf5af43cdc8e5df43f0dbf0430f00c.zip |
Fixed 803 - make use of zero copy
Diffstat (limited to 'cpp/src/IcePatch2/FileServerI.cpp')
-rw-r--r-- | cpp/src/IcePatch2/FileServerI.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/cpp/src/IcePatch2/FileServerI.cpp b/cpp/src/IcePatch2/FileServerI.cpp index 02cd9a1d2e4..66f2add3e98 100644 --- a/cpp/src/IcePatch2/FileServerI.cpp +++ b/cpp/src/IcePatch2/FileServerI.cpp @@ -59,14 +59,16 @@ IcePatch2::FileServerI::getChecksum(const Current&) const return _tree0.checksum; } -ByteSeq -IcePatch2::FileServerI::getFileCompressed(const string& pa, Int pos, Int num, const Current&) const +void +IcePatch2::FileServerI::getFileCompressed_async(const AMD_FileServer_getFileCompressedPtr& cb, + const string& pa, Int pos, Int num, const Current&) const { if(isAbsolute(pa)) { FileAccessException ex; ex.reason = "illegal absolute path `" + pa + "'"; - throw ex; + cb->ice_exception(ex); + return; } string path = simplify(pa); @@ -77,12 +79,15 @@ IcePatch2::FileServerI::getFileCompressed(const string& pa, Int pos, Int num, co { FileAccessException ex; ex.reason = "illegal `..' component in path `" + path + "'"; - throw ex; + cb->ice_exception(ex); + return; } + pair<const Byte*, const Byte*> ret(0, 0); if(num <= 0 || pos < 0) - { - return ByteSeq(); + { + cb->ice_response(ret); + return; } int fd = OS::open(_dataDir + '/' + path + ".bz2", O_RDONLY|O_BINARY); @@ -90,7 +95,8 @@ IcePatch2::FileServerI::getFileCompressed(const string& pa, Int pos, Int num, co { FileAccessException ex; ex.reason = "cannot open `" + path + "' for reading: " + strerror(errno); - throw ex; + cb->ice_exception(ex); + return; } if(lseek(fd, static_cast<off_t>(pos), SEEK_SET) != static_cast<off_t>(pos)) @@ -102,27 +108,30 @@ IcePatch2::FileServerI::getFileCompressed(const string& pa, Int pos, Int num, co FileAccessException ex; ex.reason = "cannot seek position " + posStr.str() + " in file `" + path + "': " + strerror(errno); - throw ex; + cb->ice_exception(ex); + return; } - ByteSeq bytes(num); + IceUtil::auto_array<Byte> bytes(new Byte[num]); #ifdef _WIN32 int r; - if((r = read(fd, &bytes[0], static_cast<unsigned int>(num))) == -1) + if((r = read(fd, bytes.get(), static_cast<unsigned int>(num))) == -1) #else ssize_t r; - if((r = read(fd, &bytes[0], static_cast<size_t>(num))) == -1) + if((r = read(fd, bytes.get(), static_cast<size_t>(num))) == -1) #endif { close(fd); FileAccessException ex; ex.reason = "cannot read `" + path + "': " + strerror(errno); - throw ex; + cb->ice_exception(ex); + return; } close(fd); - bytes.resize(r); - return bytes; + ret.first = bytes.get(); + ret.second = ret.first + r; + cb->ice_response(ret); } |