1 // ======================================================================== 2 // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd. 3 // ------------------------------------------------------------------------ 4 // All rights reserved. This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v1.0 6 // and Apache License v2.0 which accompanies this distribution. 7 // The Eclipse Public License is available at 8 // http://www.eclipse.org/legal/epl-v10.html 9 // The Apache License v2.0 is available at 10 // http://www.opensource.org/licenses/apache2.0.php 11 // You may elect to redistribute this code under either of these licenses. 12 // ======================================================================== 13 14 package org.eclipse.jetty.io; 15 16 import java.io.IOException; 17 18 19 20 /** 21 * 22 * A transport EndPoint 23 */ 24 public interface EndPoint 25 { 26 27 /** 28 * Close any backing stream associated with the buffer 29 */ 30 void close() throws IOException; 31 32 /** 33 * Fill the buffer from the current putIndex to it's capacity from whatever 34 * byte source is backing the buffer. The putIndex is increased if bytes filled. 35 * The buffer may chose to do a compact before filling. 36 * @return an <code>int</code> value indicating the number of bytes 37 * filled or -1 if EOF is reached. 38 */ 39 int fill(Buffer buffer) throws IOException; 40 41 42 /** 43 * Flush the buffer from the current getIndex to it's putIndex using whatever byte 44 * sink is backing the buffer. The getIndex is updated with the number of bytes flushed. 45 * Any mark set is cleared. 46 * If the entire contents of the buffer are flushed, then an implicit empty() is done. 47 * 48 * @param buffer The buffer to flush. This buffers getIndex is updated. 49 * @return the number of bytes written 50 */ 51 int flush(Buffer buffer) throws IOException; 52 53 /** 54 * Flush the buffer from the current getIndex to it's putIndex using whatever byte 55 * sink is backing the buffer. The getIndex is updated with the number of bytes flushed. 56 * Any mark set is cleared. 57 * If the entire contents of the buffer are flushed, then an implicit empty() is done. 58 * The passed header/trailer buffers are written before/after the contents of this buffer. This may be done 59 * either as gather writes, as a poke into this buffer or as several writes. The implementation is free to 60 * select the optimal mechanism. 61 * @param header A buffer to write before flushing this buffer. This buffers getIndex is updated. 62 * @param buffer The buffer to flush. This buffers getIndex is updated. 63 * @param trailer A buffer to write after flushing this buffer. This buffers getIndex is updated. 64 * @return the total number of bytes written. 65 */ 66 int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException; 67 68 69 /* ------------------------------------------------------------ */ 70 /** 71 * @return The local IP address to which this <code>EndPoint</code> is bound, or <code>null</code> 72 * if this <code>EndPoint</code> does not represent a network connection. 73 */ 74 public String getLocalAddr(); 75 76 /* ------------------------------------------------------------ */ 77 /** 78 * @return The local host name to which this <code>EndPoint</code> is bound, or <code>null</code> 79 * if this <code>EndPoint</code> does not represent a network connection. 80 */ 81 public String getLocalHost(); 82 83 /* ------------------------------------------------------------ */ 84 /** 85 * @return The local port number on which this <code>EndPoint</code> is listening, or <code>0</code> 86 * if this <code>EndPoint</code> does not represent a network connection. 87 */ 88 public int getLocalPort(); 89 90 /* ------------------------------------------------------------ */ 91 /** 92 * @return The remote IP address to which this <code>EndPoint</code> is connected, or <code>null</code> 93 * if this <code>EndPoint</code> does not represent a network connection. 94 */ 95 public String getRemoteAddr(); 96 97 /* ------------------------------------------------------------ */ 98 /** 99 * @return The host name of the remote machine to which this <code>EndPoint</code> is connected, or <code>null</code> 100 * if this <code>EndPoint</code> does not represent a network connection. 101 */ 102 public String getRemoteHost(); 103 104 /* ------------------------------------------------------------ */ 105 /** 106 * @return The remote port number to which this <code>EndPoint</code> is connected, or <code>0</code> 107 * if this <code>EndPoint</code> does not represent a network connection. 108 */ 109 public int getRemotePort(); 110 111 112 /* ------------------------------------------------------------ */ 113 public boolean isBlocking(); 114 115 /* ------------------------------------------------------------ */ 116 public boolean isBufferred(); 117 118 /* ------------------------------------------------------------ */ 119 public boolean blockReadable(long millisecs) throws IOException; 120 121 /* ------------------------------------------------------------ */ 122 public boolean blockWritable(long millisecs) throws IOException; 123 124 /* ------------------------------------------------------------ */ 125 public boolean isOpen(); 126 127 /* ------------------------------------------------------------ */ 128 /** 129 * @return The underlying transport object (socket, channel, etc.) 130 */ 131 public Object getTransport(); 132 133 /* ------------------------------------------------------------ */ 134 /** 135 * @return True if the endpoint has some buffered input data 136 */ 137 public boolean isBufferingInput(); 138 139 /* ------------------------------------------------------------ */ 140 /** 141 * @return True if the endpoint has some buffered output data 142 */ 143 public boolean isBufferingOutput(); 144 145 /* ------------------------------------------------------------ */ 146 /** Flush any buffered output. 147 * May fail to write all data if endpoint is non-blocking 148 * @throws IOException 149 */ 150 public void flush() throws IOException; 151 152 }