Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory-Map Buffer file copy fails in native code over network.

Status
Not open for further replies.

dbleyl

Programmer
Mar 26, 2001
117
US
Hi,

Program copies files using the new nio, from server to client. Occasionally, handles to the files on the client aren't released, preventing client to manipulate files. Worse - occasionally the server crashes with

"Unexpected Signal : EXCEPTION_IN_PAGE_ERROR occurred at PC=0x78012BF0
Function=flsbuf+0x1B4
Library=C:\WINNT\system32\MSVCRT.dll"

Which is described as:
'0xC0000006 EXCEPTION_IN_PAGE_ERROR
The thread tried to access a page that was not present, and the system was unable to load the page. -ie. the program or memory mapped file couldn't be paged in because it isn't accessable any more. Device drivers can return this exception if something went wrong with the read (i.e hardware problems) '

The client is NT 4.0 sp 6, The server is Win2K Server.
jvm is 1.4.1_02.
File size ranges from 1kb to 250mb.
Server has 2gb ram.

The copying code is:

fin = new FileInputStream(sourcePath);
fout = new RandomAccessFile(destinationPath, "rw");

FileChannel in = fin.getChannel();
FileChannel out = fout.getChannel();
MappedByteBuffer input = in.map(FileChannel.MapMode.READ_ONLY, 0,
in.size());
MappedByteBuffer output = out.map(FileChannel.MapMode.READ_WRITE,
0, in.size());
output.put(input);
in.close();
out.close();
in = null;
out = null;
output = null;
input = null;
//Fin Fout is closed in try...

Q: Is this the completely wrong approach to copying files & directories from client to server? (I've tried using XCopy/Copy from process, and even pushing the code into stored procedures, but the idiosyncracies and errors associated with these techniques have been worse than the problem itself.)

I'm considering Win32 CopyFile, and SHFileOperation, but i really dread this approach.

*I verified that the CachedOpenLimit reg setting is set to 0 as per (KB 126026).
 
What was I thinking? I have to get that nio O'Reilly book or something, and just stop pretending.

This seems to work much better(no mem-mapping):

fin = new FileInputStream(sourcePath);
fout = new RandomAccessFile(destinationPath, "rw");

FileChannel in = fin.getChannel();
FileChannel out = fout.getChannel();
in.transferTo(0,in.size(), out);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top