/** * * @param data Guaranteed to be non null * @param offset * @param length */ public void send(byte[] data, int offset, int length) throws Exception { if(out == null) return; writers.incrementAndGet(); send_lock.lock(); try { doSend(data, offset, length); updateLastAccessed(); } catch(InterruptedException iex) { Thread.currentThread().interrupt(); // set interrupt flag again } finally { if(writers.decrementAndGet() == 0) // only the last active writer thread calls flush() flush(); // won't throw an exception send_lock.unlock(); } }
public void run() { Throwable t=null; while(canRun()) { try { int len=in.readInt(); // needed to read messages from TCP_NIO2 server.receive(peer_addr, in, len); updateLastAccessed(); } catch(OutOfMemoryError mem_ex) { t=mem_ex; break; // continue; } catch(IOException io_ex) { t=io_ex; break; } catch(Throwable e) { } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "n/a")); } }
/** * Send the cookie first, then the our port number. If the cookie * doesn't match the receiver's cookie, the receiver will reject the * connection and close it. */ protected void sendLocalAddress(Address local_addr) throws Exception { try { // write the cookie out.write(cookie, 0, cookie.length); // write the version out.writeShort(Version.version); out.writeShort(local_addr.serializedSize()); // address size local_addr.writeTo(out); out.flush(); // needed ? updateLastAccessed(); } catch(Exception ex) { server.socket_factory.close(this.sock); connected=false; throw ex; } }
updateLastAccessed(); return client_peer_addr;
/** * * @param data Guaranteed to be non null * @param offset * @param length */ public void send(byte[] data, int offset, int length) throws Exception { if(out == null) return; writers.incrementAndGet(); send_lock.lock(); try { doSend(data, offset, length); updateLastAccessed(); } catch(InterruptedException iex) { Thread.currentThread().interrupt(); // set interrupt flag again } finally { if(writers.decrementAndGet() == 0) // only the last active writer thread calls flush() flush(); // won't throw an exception send_lock.unlock(); } }
public void run() { Throwable t=null; while(canRun()) { try { int len=in.readInt(); // needed to read messages from TCP_NIO2 server.receive(peer_addr, in, len); updateLastAccessed(); } catch(OutOfMemoryError mem_ex) { t=mem_ex; break; // continue; } catch(IOException io_ex) { t=io_ex; break; } catch(Throwable e) { } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "n/a")); } }
/** * Send the cookie first, then the our port number. If the cookie * doesn't match the receiver's cookie, the receiver will reject the * connection and close it. */ protected void sendLocalAddress(Address local_addr) throws Exception { try { // write the cookie out.write(cookie, 0, cookie.length); // write the version out.writeShort(Version.version); out.writeShort(local_addr.serializedSize()); // address size local_addr.writeTo(out); out.flush(); // needed ? updateLastAccessed(); } catch(Exception ex) { server.socket_factory.close(this.sock); connected=false; throw ex; } }
updateLastAccessed(); return client_peer_addr;