?
Solved

JNI help

Posted on 2003-03-27
4
Medium Priority
?
620 Views
Last Modified: 2008-03-06
I'm encountering a problem when I try to use a C DLL that has a Win32 SOCKET object.  When I open and close a connection within one JNI method call, it works fine.  But when I open a connection in one JNI call and close on a different JNI call, the JVM is crashes.  This is the error that I get:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x102141EB
Function=fcloseall+0x93B
Library=C:\WINNT\system32\MSVCR70D.dll

Does anybody know what the problem is, and what possible solutions/work-arounds there are?
0
Comment
Question by:Radford
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8220978
Sounds like you aren't using the correct SOCKET object to close it. How do you maintain the reference to the instance between calls?
0
 
LVL 1

Author Comment

by:Radford
ID: 8221257
The Win32 SOCKET object is actually inside an object in some third party code.  The third party code has open and close functions.  Again, calling these functions within one JNI call works fine, but in seperate JNI calls, it crashes.  The Open function in the third party code returns a reference to the object that contains the SOCKET object.  I am assigning that object to a global variable in the C code.
0
 
LVL 3

Accepted Solution

by:
msterjev earned 1000 total points
ID: 8223022
You should read the documentation for that socket class. For example, MFC class CSocket is not thread safe. If you pass CSocket object between threads the program crashes. It is recomended to use CSocket.Attach() and CSocket.Detach() methods. So check for these or similar methods. The scenario is as follows():

1. You should keep SOCKET handle, not the socket object (CSocket for example) as global variable!
2. When you call some JNI method, attach the SOCKET handle to the  socket object and this way you have a high level socket wrapping helper!
3. At the and of the method, detach the SOCKET handle from the socket object!

I think this will help you!
0
 
LVL 1

Author Comment

by:Radford
ID: 8225690
alright my colleague and i solved the problem on our own.  =)

i'll give the points to msterjev for trying to help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question