Exemplo n.º 1
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final A_Atom propertyKey = args.get(0);
   final A_Atom atom = args.get(1);
   if (atom.isAtomSpecial()) {
     return interpreter.primitiveFailure(E_SPECIAL_ATOM);
   }
   final A_BasicObject propertyValue = atom.getAtomProperty(propertyKey);
   return interpreter.primitiveSuccess(
       AtomDescriptor.objectFromBoolean(!propertyValue.equalsNil()));
 }
Exemplo n.º 2
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final AvailObject handle = args.get(0);
   final AvailObject options = args.get(1);
   final AvailObject pojo = handle.getAtomProperty(AtomDescriptor.socketKey());
   if (pojo.equalsNil()) {
     return interpreter.primitiveFailure(
         handle.isAtomSpecial() ? E_SPECIAL_ATOM : E_INVALID_HANDLE);
   }
   final AsynchronousSocketChannel socket = (AsynchronousSocketChannel) pojo.javaObjectNotNull();
   try {
     for (final MapDescriptor.Entry entry : options.mapIterable()) {
       final AvailObject key = entry.key();
       final AvailObject entryValue = entry.value();
       assert key != null;
       @SuppressWarnings("rawtypes")
       final SocketOption option = socketOptions[key.extractInt()];
       final Class<?> type = option.type();
       if (type.equals(Boolean.class) && entryValue.isBoolean()) {
         final SocketOption<Boolean> booleanOption = option;
         socket.setOption(booleanOption, entryValue.extractBoolean());
       } else if (type.equals(Integer.class) && entryValue.isInt()) {
         final Integer value = entryValue.extractInt();
         socket.<Integer>setOption(option, value);
       } else {
         return interpreter.primitiveFailure(E_INCORRECT_ARGUMENT_TYPE);
       }
     }
     return interpreter.primitiveSuccess(NilDescriptor.nil());
   } catch (final IllegalArgumentException e) {
     return interpreter.primitiveFailure(E_INCORRECT_ARGUMENT_TYPE);
   } catch (final IOException e) {
     return interpreter.primitiveFailure(E_IO_ERROR);
   }
 }