Hi guys...
Playing with native methods, I have created a very basic program that
creates a TCP/IP socket from Java by using the corresponding C call (i.e.,
socket()).
My code (excluding error handling parts) is something like:
// File NativeSocketApplication.java
public class NativeSocketApplication
{
private static NativeSocket socket;
public static void main(String args[])
{
System.out.print("\n\nApplication started");
socket = new NativeSocket();
System.out.print("\n\nNativeSocket() returned
successfully.");
}
}
// File NativeSocket.java
public class NativeSocket()
{
public NativeSocket()
{
System.out.print("\n\nCalling native method");
nativeSocketCreate(AF_INET, SOCK_DGRAM, PF_INET);
}
private void nativeSocketCreate(int family, int type, int protocol)
{
// Calls Linux socket(family, type, protocol) function
}
}
// File native_socket.c
{
// My nativeSocketCreate function with JNI syntactic sugar
JNIEXPORT void JNICALL Java_NativeSocket_nativeSocketCreate
(JNIEnv *env, jobject jthis, jint family, jint type, jint
protocol)
{
printf("\n\nCreating native socket...");
socket(family, protocol, data);
}
}
Very simple, BUT: When I run the program under windows, as expected, I get
the following output:
Application started
Calling native method
Creating native socket...
NativeSocket() returned successfully.
which is reasonable (I use only one thread).
In Linux, things are not doing that well. Using either JDK 1.1.7 or JDK 1.2,
I get
Application started
Calling native method
NativeSocket() returned successfully.
==> Creating native socket... (!!!)
In JDK 1.1.7, the last message is even printed after the Unix prompt(!)...
Is this just a problem related to interaction with the output (can't be that
the order of execution is altered, surely!), or does it mean potential
synchronisation problems?
Thanks,
Dimitris
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]