public void setReceiveTimeout(TcpSocket fan, Duration v) { try { if (v == null) socket.setSoTimeout(0); else socket.setSoTimeout((int) (v.millis())); } catch (IOException e) { throw IOErr.make(e); } }
public void setLinger(TcpSocket fan, Duration v) { try { if (v == null) socket.setSoLinger(false, 0); else socket.setSoLinger(true, (int) (v.sec())); } catch (IOException e) { throw IOErr.make(e); } }
public Duration getReceiveTimeout(TcpSocket fan) { try { int timeout = socket.getSoTimeout(); if (timeout <= 0) return null; return Duration.makeMillis(timeout); } catch (IOException e) { throw IOErr.make(e); } }
public Duration getLinger(TcpSocket fan) { try { int linger = socket.getSoLinger(); if (linger < 0) return null; return Duration.makeSec(linger); } catch (IOException e) { throw IOErr.make(e); } }
public TcpSocket connect(TcpSocket fan, IpAddr addr, long port, Duration timeout) { try { // connect int javaTimeout = (timeout == null) ? 0 : (int) timeout.millis(); socket.connect(new InetSocketAddress(addr.peer.java, (int) port), javaTimeout); connected(fan); return fan; } catch (IOException e) { throw IOErr.make(e); } }
/** * Returns an appropriate XQuery type for the specified Java object. * * @param o object * @return item type or {@code null} if no appropriate type was found */ private static Type type(final Object o) { final Type t = type(o.getClass()); if (t != null) return t; if (o instanceof Element) return NodeType.ELM; if (o instanceof Document) return NodeType.DOC; if (o instanceof DocumentFragment) return NodeType.DOC; if (o instanceof Attr) return NodeType.ATT; if (o instanceof Comment) return NodeType.COM; if (o instanceof ProcessingInstruction) return NodeType.PI; if (o instanceof Text) return NodeType.TXT; if (o instanceof Duration) { final Duration d = (Duration) o; return !d.isSet(DatatypeConstants.YEARS) && !d.isSet(DatatypeConstants.MONTHS) ? AtomType.DTD : !d.isSet(DatatypeConstants.HOURS) && !d.isSet(DatatypeConstants.MINUTES) && !d.isSet(DatatypeConstants.SECONDS) ? AtomType.YMD : AtomType.DUR; } if (o instanceof XMLGregorianCalendar) { final QName type = ((XMLGregorianCalendar) o).getXMLSchemaType(); if (type == DatatypeConstants.DATE) return AtomType.DAT; if (type == DatatypeConstants.DATETIME) return AtomType.DTM; if (type == DatatypeConstants.TIME) return AtomType.TIM; if (type == DatatypeConstants.GYEARMONTH) return AtomType.YMO; if (type == DatatypeConstants.GMONTHDAY) return AtomType.MDA; if (type == DatatypeConstants.GYEAR) return AtomType.YEA; if (type == DatatypeConstants.GMONTH) return AtomType.MON; if (type == DatatypeConstants.GDAY) return AtomType.DAY; } return null; }