Can I write JNI API which refer to C library which return a socket

Say I have a C function that will return a socket to the caller, like Socket* bbSocket()Can I map it to a JNI java API that return a java.net.Socket ?
[171 byte] By [carfielda] at [2007-11-26 22:04:26]
# 1

I'm going to suggest that you can do something. But it is also something that I haven't done.

Take a look at the documentation for java.net.socket. It says that the real work is done by a SocketImpl.

You could write your own SocketImpl - probabkly mostly a wrapper around a C socket create via JNI. You would have to also write your own SocketFactory to instantiate the SocketImpl.

bschauwejavaa at 2007-7-10 10:47:48 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
So you mean have other JNI method map java socket to C socket through that pointer?I guess this should be something general... does anyone know where have sample code to refer to?
carfielda at 2007-7-10 10:47:48 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
What I mean is reimplement all of the SocketImpl methods as JNI functions.
bschauwejavaa at 2007-7-10 10:47:48 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
> What I mean is reimplement all of the SocketImpl> methods as JNI functions.Then it will affect all other modules within JVM using socket?
carfielda at 2007-7-10 10:47:48 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
Don't see why. You are supplying a java socket - it just happens to be implemented via JNI.
bschauwejavaa at 2007-7-10 10:47:48 > top of Java-index,Java HotSpot Virtual Machine,Specifications...