Getting UDT to properly load from eclipse/idea/natively
This commit is contained in:
parent
a35935ff85
commit
e961f395a5
@ -27,7 +27,7 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* UDT native socket wrapper
|
||||
* <p>
|
||||
* <p/>
|
||||
* note: current implementation supports IPv4 only (no IPv6)
|
||||
*/
|
||||
public
|
||||
@ -77,20 +77,20 @@ class SocketUDT {
|
||||
* indication of inconsistent build.
|
||||
*/
|
||||
@Native
|
||||
public static final int SIGNATURE_JNI = 20130512; // VersionUDT.BUILDTIME;
|
||||
public static final int SIGNATURE_JNI = 20150706; // VersionUDT.BUILDTIME;
|
||||
|
||||
/**
|
||||
* infinite timeout:
|
||||
* <p>
|
||||
* <p/>
|
||||
* blocking send/receive
|
||||
* <p>
|
||||
* <p/>
|
||||
* epoll wait
|
||||
*/
|
||||
public static final int TIMEOUT_INFINITE = -1;
|
||||
|
||||
/**
|
||||
* zero timeout:
|
||||
* <p>
|
||||
* <p/>
|
||||
* epoll wait
|
||||
*/
|
||||
public static long TIMEOUT_NONE = 0;
|
||||
@ -133,7 +133,7 @@ class SocketUDT {
|
||||
Method nativeMethod = exitClass.getMethod("isNative");
|
||||
Object invoke = nativeMethod.invoke(null);
|
||||
if (invoke != null) {
|
||||
isNativeDeployed = (boolean) invoke;
|
||||
isNativeDeployed = (Boolean) invoke;
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
@ -144,7 +144,13 @@ class SocketUDT {
|
||||
final Logger logger = LoggerFactory.getLogger(SocketUDT.class);
|
||||
|
||||
String moduleDir = System.getProperty("user.dir");
|
||||
final String libraryDir = FileUtil.normalizeAsFile(moduleDir + "../../../dorkbox/Dorkbox-Network/natives");
|
||||
String libraryDir = FileUtil.getParentRelativeToDir(moduleDir, "dorkbox");
|
||||
File file = new File(libraryDir);
|
||||
if (file.getName()
|
||||
.equals("dorkbox")) {
|
||||
file = file.getParentFile();
|
||||
}
|
||||
libraryDir = FileUtil.normalizeAsFile(file.getAbsolutePath() + "/dorkbox/dorkbox/Dorkbox-Network/natives");
|
||||
|
||||
|
||||
if (libraryDir == null || libraryDir.length() == 0) {
|
||||
@ -192,12 +198,15 @@ class SocketUDT {
|
||||
INIT_OK = true;
|
||||
|
||||
log.debug("native library load & init OK");
|
||||
}
|
||||
|
||||
public static
|
||||
void init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up global JNI references and the UDT library.
|
||||
* <p>
|
||||
* <p/>
|
||||
* The behavior of SocketUDT class after a call to cleanup is undefined, so
|
||||
* it should only ever be called once you are done and you are ready for the
|
||||
* class loader to unload the JNI library
|
||||
@ -222,7 +231,6 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* @return epoll id
|
||||
*
|
||||
* @see <a
|
||||
* href="http://udt.sourceforge.net/udt4/doc/epoll.htm">UDT::epoll_create()</a>
|
||||
*/
|
||||
@ -261,6 +269,7 @@ class SocketUDT {
|
||||
* href="http://udt.sourceforge.net/udt4/doc/epoll.htm">UDT::epoll_wait()</a>
|
||||
*/
|
||||
protected static native
|
||||
int epollWait0( //
|
||||
int epollWait0( //
|
||||
final int epollID, //
|
||||
final IntBuffer readBuffer, //
|
||||
@ -354,21 +363,16 @@ class SocketUDT {
|
||||
* {@link java.nio.DirectIntBuffer} info exchange.Timeout is in
|
||||
* milliseconds.
|
||||
*
|
||||
* @param millisTimeout
|
||||
*
|
||||
* http://udt.sourceforge.net/udt4/doc/epoll.htm
|
||||
*
|
||||
* @param millisTimeout http://udt.sourceforge.net/udt4/doc/epoll.htm
|
||||
* <p/>
|
||||
* "Finally, for epoll_wait, negative timeout value will make the
|
||||
* function to wait until an event happens. If the timeout value
|
||||
* is 0, then the function returns immediately with any sockets
|
||||
* associated an IO event. If timeout occurs before any event
|
||||
* happens, the function returns 0".
|
||||
*
|
||||
*
|
||||
* @return <code><0</code> : should not happen<br>
|
||||
* <code>=0</code> : timeout, no ready sockets<br>
|
||||
* <code>>0</code> : total number or reads, writes, exceptions<br>
|
||||
*
|
||||
* @see #epollWait0(int, IntBuffer, IntBuffer, IntBuffer, long)
|
||||
*/
|
||||
public static
|
||||
@ -397,7 +401,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* send from a complete byte[] array;
|
||||
*
|
||||
* <p/>
|
||||
* wrapper for <em>UDT::send()</em>, <em>UDT::sendmsg()</em>
|
||||
*
|
||||
* @see <a
|
||||
@ -416,7 +420,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* send from a portion of a byte[] array;
|
||||
*
|
||||
* <p/>
|
||||
* wrapper for <em>UDT::send()</em>, <em>UDT::sendmsg()</em>
|
||||
*
|
||||
* @see <a
|
||||
@ -437,7 +441,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* send from {@link java.nio.DirectByteBuffer};
|
||||
*
|
||||
* <p/>
|
||||
* wrapper for <em>UDT::send()</em>, <em>UDT::sendmsg()</em>
|
||||
*
|
||||
* @see <a
|
||||
@ -560,7 +564,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* native address family; read by JNI
|
||||
* <p>
|
||||
* <p/>
|
||||
* TODO add support for AF_INET6
|
||||
*/
|
||||
@Native
|
||||
@ -581,8 +585,7 @@ class SocketUDT {
|
||||
* "Primary" socket. Default constructor; will apply
|
||||
* {@link #setDefaultMessageSendMode()}
|
||||
*
|
||||
* @param type
|
||||
* UDT socket type
|
||||
* @param type UDT socket type
|
||||
*/
|
||||
public
|
||||
SocketUDT(final TypeUDT type) throws ExceptionUDT {
|
||||
@ -600,8 +603,7 @@ class SocketUDT {
|
||||
* "Secondary" socket. Made by {@link #accept0()}, will apply
|
||||
* {@link #setDefaultMessageSendMode()}
|
||||
*
|
||||
* @param socketID
|
||||
* UDT socket descriptor;
|
||||
* @param socketID UDT socket descriptor;
|
||||
*/
|
||||
protected
|
||||
SocketUDT(final TypeUDT type, final int socketID) throws ExceptionUDT {
|
||||
@ -723,14 +725,14 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* Connect to remote UDT socket.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Can be blocking or non blocking call; depending on
|
||||
* {@link OptionUDT#Is_Receive_Synchronous}
|
||||
* <p>
|
||||
* <p/>
|
||||
* Timing: UDT uses hard coded connect timeout:
|
||||
* <p>
|
||||
* <p/>
|
||||
* normal socket: 3 seconds
|
||||
* <p>
|
||||
* <p/>
|
||||
* rendezvous socket: 30 seconds; when
|
||||
* {@link OptionUDT#Is_Randezvous_Connect_Enabled} is true
|
||||
*
|
||||
@ -765,7 +767,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* NOTE: catch all exceptions; else prevents GC
|
||||
* <p>
|
||||
* <p/>
|
||||
* NOTE: do not leak "this" references; else prevents GC
|
||||
*/
|
||||
@Override
|
||||
@ -1042,7 +1044,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* Get "any blocking operation" timeout setting.
|
||||
*
|
||||
* <p/>
|
||||
* Returns milliseconds; zero return means "infinite"; negative means
|
||||
* invalid
|
||||
*
|
||||
@ -1136,7 +1138,6 @@ class SocketUDT {
|
||||
* @return true : socket is valid and both send and receive are set to
|
||||
* blocking mode; false : at least one channel is set to
|
||||
* non-blocking mode or socket is invalid;
|
||||
*
|
||||
* @see #isNonBlocking()
|
||||
* @see #setBlocking(boolean)
|
||||
*/
|
||||
@ -1255,9 +1256,7 @@ class SocketUDT {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queueSize
|
||||
* maximum number of queued clients
|
||||
*
|
||||
* @param queueSize maximum number of queued clients
|
||||
* @see #listen0(int)
|
||||
*/
|
||||
public
|
||||
@ -1403,8 +1402,7 @@ class SocketUDT {
|
||||
/**
|
||||
* send from byte[] array upto <code>size=array.length</code> bytes
|
||||
*
|
||||
* @param array
|
||||
* array to send
|
||||
* @param array array to send
|
||||
* @return <code>-1</code> : no buffer space (non-blocking only) <br>
|
||||
* <code>=0</code> : timeout expired (blocking only) <br>
|
||||
* <code>>0</code> : normal send, actual sent byte count <br>
|
||||
@ -1428,12 +1426,9 @@ class SocketUDT {
|
||||
/**
|
||||
* send from byte[] array upto <code>size=limit-position</code> bytes
|
||||
*
|
||||
* @param array
|
||||
* array to send
|
||||
* @param position
|
||||
* start of array portion to send
|
||||
* @param limit
|
||||
* finish of array portion to send
|
||||
* @param array array to send
|
||||
* @param position start of array portion to send
|
||||
* @param limit finish of array portion to send
|
||||
* @return <code>-1</code> : no buffer space (non-blocking only) <br>
|
||||
* <code>=0</code> : timeout expired (blocking only) <br>
|
||||
* <code>>0</code> : normal send, actual sent byte count <br>
|
||||
@ -1464,8 +1459,7 @@ class SocketUDT {
|
||||
* send from {@link java.nio.DirectByteBuffer}, upto
|
||||
* {@link ByteBuffer#remaining()} bytes
|
||||
*
|
||||
* @param buffer
|
||||
* buffer to send
|
||||
* @param buffer buffer to send
|
||||
* @return <code>-1</code> : no buffer space (non-blocking only)<br>
|
||||
* <code>=0</code> : timeout expired (blocking only)<br>
|
||||
* <code>>0</code> : normal send, actual sent byte count<br>
|
||||
@ -1551,8 +1545,7 @@ class SocketUDT {
|
||||
/**
|
||||
* Configure socket in strict blocking / strict non-blocking mode.
|
||||
*
|
||||
* @param block
|
||||
* true : set both send and receive to blocking mode; false : set
|
||||
* @param block true : set both send and receive to blocking mode; false : set
|
||||
* both send and receive to non-blocking mode
|
||||
* @see java.nio.channels.SocketChannel#configureBlocking(boolean)
|
||||
*/
|
||||
@ -1570,7 +1563,7 @@ class SocketUDT {
|
||||
|
||||
/**
|
||||
* Apply default settings for message mode.
|
||||
* <p>
|
||||
* <p/>
|
||||
* IsOdered = true;<br>
|
||||
* TimeTolLive = INFINITE_TTL;<br>
|
||||
*/
|
||||
@ -1768,8 +1761,7 @@ class SocketUDT {
|
||||
* Load updated statistics values into {@link #monitor} object. Must call
|
||||
* this methos only on connected socket.
|
||||
*
|
||||
* @param makeClear
|
||||
* true : reset all statistics with this call; false : keep
|
||||
* @param makeClear true : reset all statistics with this call; false : keep
|
||||
* collecting statistics, load updated values.
|
||||
* @see #updateMonitor0(boolean)
|
||||
*/
|
||||
|
@ -1,32 +1,32 @@
|
||||
/**
|
||||
* Copyright (C) 2009-2013 Barchart, Inc. <http://www.barchart.com/>
|
||||
*
|
||||
* <p/>
|
||||
* All rights reserved. Licensed under the OSI BSD License.
|
||||
*
|
||||
* <p/>
|
||||
* http://www.opensource.org/licenses/bsd-license.php
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
|
||||
/**
|
||||
* {@link OutputStream} for UDT sockets.
|
||||
*/
|
||||
public class NetOutputStreamUDT extends OutputStream {
|
||||
public
|
||||
class NetOutputStreamUDT extends OutputStream {
|
||||
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param socketUDT
|
||||
* The UDT socket.
|
||||
* @param socketUDT The UDT socket.
|
||||
*/
|
||||
public NetOutputStreamUDT(final SocketUDT socketUDT) {
|
||||
public
|
||||
NetOutputStreamUDT(final SocketUDT socketUDT) {
|
||||
|
||||
if (!socketUDT.isBlocking()) {
|
||||
throw new IllegalBlockingModeException();
|
||||
@ -37,7 +37,8 @@ public class NetOutputStreamUDT extends OutputStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final int b) throws IOException {
|
||||
public
|
||||
void write(final int b) throws IOException {
|
||||
|
||||
// Just cast it -- this is the same thing SocketOutputStream does.
|
||||
final byte[] bytes = {(byte) b};
|
||||
@ -47,22 +48,22 @@ public class NetOutputStreamUDT extends OutputStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final byte[] bytes) throws IOException {
|
||||
public
|
||||
void write(final byte[] bytes) throws IOException {
|
||||
|
||||
write(bytes, 0, bytes.length);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final byte[] bytes, final int off, final int len)
|
||||
throws IOException {
|
||||
public
|
||||
void write(final byte[] bytes, final int off, final int len) throws IOException {
|
||||
|
||||
int bytesRemaining = len;
|
||||
|
||||
while (bytesRemaining > 0) {
|
||||
|
||||
final int count = socketUDT.send(bytes, off + len - bytesRemaining,
|
||||
off + len);
|
||||
final int count = socketUDT.send(bytes, off + len - bytesRemaining, off + len);
|
||||
|
||||
if (count > 0) {
|
||||
bytesRemaining -= count;
|
||||
@ -70,23 +71,23 @@ public class NetOutputStreamUDT extends OutputStream {
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
throw new ExceptionSendUDT(socketUDT.id(),
|
||||
ErrorUDT.USER_DEFINED_MESSAGE, "UDT send time out");
|
||||
throw new ExceptionSendUDT(socketUDT.id(), ErrorUDT.USER_DEFINED_MESSAGE, "UDT send time out");
|
||||
}
|
||||
|
||||
throw new IllegalStateException(
|
||||
"Socket has been chaged to non-blocking");
|
||||
throw new IllegalStateException("Socket has been changed to non-blocking");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public
|
||||
void close() throws IOException {
|
||||
socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
public
|
||||
void flush() throws IOException {
|
||||
socketUDT.flush();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user