private int execMount(String[] arg) { return libFuse.fuse_main_real(arg.length, arg, fuseOperations, Struct.size(fuseOperations), null); }
private int execMount(String[] arg) { return libFuse.fuse_main_real(arg.length, arg, fuseOperations, Struct.size(fuseOperations), null); }
public WindowsSecurityAttributes(jnr.ffi.Runtime runtime) { super(runtime); // This seems like the sensible defaults for this. length.set(Struct.size(this)); inheritHandle.set(true); }
public WindowsSecurityAttributes(jnr.ffi.Runtime runtime) { super(runtime); // This seems like the sensible defaults for this. length.set(Struct.size(this)); inheritHandle.set(true); }
public WindowsSecurityAttributes(jnr.ffi.Runtime runtime) { super(runtime); // This seems like the sensible defaults for this. length.set(Struct.size(this)); inheritHandle.set(true); }
public WindowsSecurityAttributes(jnr.ffi.Runtime runtime) { super(runtime); // This seems like the sensible defaults for this. length.set(Struct.size(this)); inheritHandle.set(true); }
@Override public void postInvoke(Struct[] structs, Pointer primitive, ToNativeContext context) { if (structs != null && primitive != null) { try { int off = 0; for (int i = 0; i < structs.length; i++) { structs[i] = constructor.newInstance(runtime); int structSize = align(Struct.size(structs[i]), Struct.alignment(structs[i])); structs[i].useMemory(primitive.slice(off = align(off, Struct.alignment(structs[i])), structSize)); off += structSize; } } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } } } }
@Override public void postInvoke(Struct[] structs, Pointer primitive, ToNativeContext context) { if (structs != null && primitive != null) { try { int off = 0; for (int i = 0; i < structs.length; i++) { structs[i] = constructor.newInstance(runtime); int structSize = align(Struct.size(structs[i]), Struct.alignment(structs[i])); structs[i].useMemory(primitive.slice(off = align(off, Struct.alignment(structs[i])), structSize)); off += structSize; } } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } } } }
@Override public void postInvoke(Struct[] structs, Pointer primitive, ToNativeContext context) { if (structs != null && primitive != null) { try { int off = 0; for (int i = 0; i < structs.length; i++) { structs[i] = constructor.newInstance(runtime); int structSize = align(Struct.size(structs[i]), Struct.alignment(structs[i])); structs[i].useMemory(primitive.slice(off = align(off, Struct.alignment(structs[i])), structSize)); off += structSize; } } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } } } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
public void read() { SockAddrIN sin = new SockAddrIN(); 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); try { ch.configureBlocking(false); ch.register(selector, SelectionKey.OP_READ, new Client(selector, ch)); selector.wakeup(); } catch (IOException ex) {} } public void write() {
private static void assertPlatfomValue(Function<jnr.ffi.Runtime, Struct> structFunction) { Struct struct = structFunction.apply(Runtime.getSystemRuntime()); jnr.ffi.Platform.OS os = jnr.ffi.Platform.getNativePlatform().getOS(); PlatformSize size = sizes.get(struct.getClass()).get(os); assertEquals(Platform.IS_32_BIT ? size.x32 : size.x64, Struct.size(struct)); }
public static int getsockopt(int s, SocketLevel level, SocketOption optname, Struct data) { Pointer struct_ptr = Struct.getMemory(data); IntByReference ref = new IntByReference(Struct.size(data)); ByteBuffer buf = ByteBuffer.wrap((byte[])struct_ptr.array()); return Native.libsocket().getsockopt(s, level.intValue(), optname.intValue(), buf, ref); }
static NativeServerSocketChannel serverSocket(int port) { int fd = libc.socket(LibC.AF_INET, LibC.SOCK_STREAM, 0); System.out.println("fd=" + fd); SockAddr addr; if (Platform.getNativePlatform().isBSD()) { BSDSockAddrIN sin = new BSDSockAddrIN(); sin.sin_family.set((byte) LibC.AF_INET); sin.sin_port.set(htons((short) port)); addr = sin; } else { SockAddrIN sin = new SockAddrIN(); sin.sin_family.set(htons((short) LibC.AF_INET)); sin.sin_port.set(htons((short) port)); addr = sin; } 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(runtime))); System.exit(1); } System.out.println("bind+listen succeeded"); return new NativeServerSocketChannel(fd); }
for (int i = 0; i < numOfFactors; i++) { tjscalingfactor f = new tjscalingfactor(runtime); factorPtr = factorPtr.slice(Struct.size(f)); f.useMemory(factorPtr); factors[i] = f;
@Override @NotImplemented public int read_buf(String path, Pointer bufp, @size_t long size, @off_t long off, FuseFileInfo fi) { // should be implemented or null long vecmem = MemoryIO.getInstance().allocateMemory(Struct.size(new FuseBufvec(Runtime.getSystemRuntime())), false); if (vecmem == 0) { return -ErrorCodes.ENOMEM(); } Pointer src = Pointer.wrap(Runtime.getSystemRuntime(), vecmem); long memAdr = MemoryIO.getInstance().allocateMemory(size, false); if (memAdr == 0) { MemoryIO.getInstance().freeMemory(vecmem); return -ErrorCodes.ENOMEM(); } Pointer mem = Pointer.wrap(Runtime.getSystemRuntime(), memAdr); FuseBufvec buf = FuseBufvec.of(src); FuseBufvec.init(buf, size); buf.buf.mem.set(mem); bufp.putAddress(0, src.address()); int res = read(path, mem, size, off, fi); if (res >= 0) buf.buf.size.set(res); return res; }
@Override @NotImplemented public int read_buf(String path, Pointer bufp, @size_t long size, @off_t long off, FuseFileInfo fi) { // should be implemented or null long vecmem = MemoryIO.getInstance().allocateMemory(Struct.size(new FuseBufvec(Runtime.getSystemRuntime())), false); if (vecmem == 0) { return -ErrorCodes.ENOMEM(); } Pointer src = Pointer.wrap(Runtime.getSystemRuntime(), vecmem); long memAdr = MemoryIO.getInstance().allocateMemory(size, false); if (memAdr == 0) { MemoryIO.getInstance().freeMemory(vecmem); return -ErrorCodes.ENOMEM(); } Pointer mem = Pointer.wrap(Runtime.getSystemRuntime(), memAdr); FuseBufvec buf = FuseBufvec.of(src); FuseBufvec.init(buf, size); buf.buf.mem.set(mem); bufp.putAddress(0, src.address()); int res = read(path, mem, size, off, fi); if (res >= 0) buf.buf.size.set(res); return res; }
FuseBuf flatbuf; FuseBufvec tmp = new FuseBufvec(Runtime.getSystemRuntime()); long adr = MemoryIO.getInstance().allocateMemory(Struct.size(tmp), false); tmp.useMemory(Pointer.wrap(Runtime.getSystemRuntime(), adr)); FuseBufvec.init(tmp, size);