Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update to jnr-ffi 0.6 and new package.

  • Loading branch information...
commit 18177b30567786fbbd9f2d3db6ff46f42c23c243 1 parent 696a090
Charles Oliver Nutter headius authored
1  .gitignore
View
@@ -8,3 +8,4 @@ dist
*~
.idea
*.iml
+/.redcar/
11 pom.xml
View
@@ -61,16 +61,15 @@
</dependency>
<dependency>
<groupId>org.jruby.extras</groupId>
- <artifactId>jaffl</artifactId>
- <version>0.5.9</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.jruby.extras</groupId>
<artifactId>jnr-constants</artifactId>
<version>0.8</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.github.jnr</groupId>
+ <artifactId>jnr-ffi</artifactId>
+ <version>0.6.0</version>
+ </dependency>
</dependencies>
<build>
<plugins>
11 src/main/java/jnr/enxio/channels/Native.java
View
@@ -18,14 +18,15 @@
package jnr.enxio.channels;
-import com.kenai.jaffl.LastError;
-import com.kenai.jaffl.Library;
-import com.kenai.jaffl.annotations.In;
-import com.kenai.jaffl.annotations.Out;
+import jnr.ffi.LastError;
+import jnr.ffi.Library;
+import jnr.ffi.annotations.In;
+import jnr.ffi.annotations.Out;
import java.io.IOException;
import java.nio.ByteBuffer;
class Native {
+ static final jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getSystemRuntime();
private static final class LibCHolder {
private static final LibC libc = Library.loadLibrary("c", LibC.class);
}
@@ -74,7 +75,7 @@ public static void setBlocking(int fd, boolean block) {
}
public static String getLastErrorString() {
- return libc().strerror(LastError.getLastError());
+ return libc().strerror(LastError.getLastError(runtime));
}
public static interface LibC {
2  src/main/java/jnr/enxio/channels/NativeSelectorProvider.java
View
@@ -18,7 +18,7 @@
package jnr.enxio.channels;
-import com.kenai.jaffl.Platform;
+import jnr.ffi.Platform;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
4 src/main/java/jnr/enxio/channels/NativeSocketChannel.java
View
@@ -19,7 +19,7 @@
package jnr.enxio.channels;
import jnr.constants.platform.Errno;
-import com.kenai.jaffl.LastError;
+import jnr.ffi.LastError;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
@@ -70,7 +70,7 @@ public int read(ByteBuffer dst) throws IOException {
case 0:
return -1;
case -1:
- switch (Errno.valueOf(LastError.getLastError())) {
+ switch (Errno.valueOf(LastError.getLastError(Native.runtime))) {
case EAGAIN:
case EWOULDBLOCK:
return 0;
17 src/main/java/jnr/enxio/channels/kqueue/KQSelector.java
View
@@ -18,12 +18,12 @@
package jnr.enxio.channels.kqueue;
-import com.kenai.jaffl.Library;
-import com.kenai.jaffl.Platform;
-import com.kenai.jaffl.annotations.In;
-import com.kenai.jaffl.annotations.Out;
-import com.kenai.jaffl.annotations.Transient;
-import com.kenai.jaffl.struct.Struct;
+import jnr.ffi.Library;
+import jnr.ffi.Platform;
+import jnr.ffi.annotations.In;
+import jnr.ffi.annotations.Out;
+import jnr.ffi.annotations.Transient;
+import jnr.ffi.Struct;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -375,16 +375,19 @@ public int getFD(ByteBuffer buf, int index) {
return (int) buf.getLong(EVENT_SIZE * index + IDENT_OFFSET);
}
}
+
+ private static final jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getSystemRuntime();
static class Timespec extends Struct {
public final SignedLong tv_sec = new SignedLong();
public final SignedLong tv_nsec = new SignedLong();
public Timespec() {
-
+ super(runtime);
}
public Timespec(long sec, long nsec) {
+ super(runtime);
tv_sec.set(sec);
tv_nsec.set(nsec);
}
6 src/main/java/jnr/enxio/channels/poll/PollSelector.java
View
@@ -16,9 +16,9 @@
package jnr.enxio.channels.poll;
-import com.kenai.jaffl.Library;
-import com.kenai.jaffl.annotations.In;
-import com.kenai.jaffl.annotations.Out;
+import jnr.ffi.Library;
+import jnr.ffi.annotations.In;
+import jnr.ffi.annotations.Out;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
29 src/main/java/jnr/enxio/example/TCPServer.java
View
@@ -18,14 +18,13 @@
package jnr.enxio.example;
-import com.kenai.jaffl.LastError;
-import com.kenai.jaffl.Library;
-import com.kenai.jaffl.Platform;
-import com.kenai.jaffl.annotations.In;
-import com.kenai.jaffl.annotations.Out;
-//import com.kenai.jaffl.byref.IntByReference;
-import com.kenai.jaffl.struct.Struct;
-import com.kenai.jaffl.struct.StructUtil;
+import jnr.ffi.LastError;
+import jnr.ffi.Library;
+import jnr.ffi.Platform;
+import jnr.ffi.annotations.In;
+import jnr.ffi.annotations.Out;
+//import jnr.ffi.byref.IntByReference;
+import jnr.ffi.Struct;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
@@ -45,8 +44,12 @@
? new String[] { "socket", "nsl", "c" }
: new String[] { "c" };
static final LibC libc = Library.loadLibrary(LibC.class, libnames);
+ static final jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getSystemRuntime();
public static class SockAddr extends Struct {
+ public SockAddr() {
+ super(runtime);
+ }
}
static class BSDSockAddrIN extends SockAddr {
@@ -98,13 +101,13 @@ static NativeServerSocketChannel serverSocket(int port) {
sin.sin_port.set(htons((short) port));
addr = sin;
}
- System.out.println("sizeof addr=" + StructUtil.getSize(addr));
- if (libc.bind(fd, addr, StructUtil.getSize(addr)) < 0) {
- System.err.println("bind failed: " + libc.strerror(LastError.getLastError()));
+ System.out.println("sizeof addr=" + Struct.size(addr));
+ if (libc.bind(fd, addr, Struct.size(addr)) < 0) {
+ System.err.println("bind failed: " + libc.strerror(LastError.getLastError(runtime)));
System.exit(1);
}
if (libc.listen(fd, 5) < 0) {
- System.err.println("listen failed: " + libc.strerror(LastError.getLastError()));
+ System.err.println("listen failed: " + libc.strerror(LastError.getLastError(runtime)));
System.exit(1);
}
System.out.println("bind+listen succeeded");
@@ -126,7 +129,7 @@ public Accepter(Selector selector, NativeServerSocketChannel ch) {
}
public void read() {
SockAddrIN sin = new SockAddrIN();
- int[] addrSize = { StructUtil.getSize(sin) };
+ int[] addrSize = { Struct.size(sin) };
int clientfd = libc.accept(((NativeSelectableChannel) channel).getFD(), sin, addrSize);
System.out.println("client fd = " + clientfd);
NativeSocketChannel ch = new NativeSocketChannel(clientfd);
Please sign in to comment.
Something went wrong with that request. Please try again.