Changeset 5f413ef for core


Ignore:
Timestamp:
Dec 13, 2017 4:06:13 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e6251e7c
Parents:
bd341d4
Message:

InternalSocket?: Implement more methods, add debug output, don't ignore interrupt on accept()
Close socket on InternalSocketRunner? exception

Location:
core/java/src/net/i2p/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/InternalServerSocket.java

    rbd341d4 r5f413ef  
    22
    33import java.io.IOException;
     4import java.io.InterruptedIOException;
    45import java.io.PipedInputStream;
    56import java.io.PipedOutputStream;
     7import java.io.Writer;
    68import java.net.InetAddress;
    79import java.net.ServerSocket;
     
    911import java.net.SocketAddress;
    1012import java.nio.channels.ServerSocketChannel;
     13import java.util.ArrayList;
     14import java.util.Collections;
     15import java.util.List;
    1116import java.util.concurrent.BlockingQueue;
    1217import java.util.concurrent.ConcurrentHashMap;
     
    6974                serverSock = _acceptQueue.take();
    7075            } catch (InterruptedException ie) {
    71                 continue;
     76                if (_running)
     77                    throw new InterruptedIOException();
     78                throw new IOException("closed");
    7279            }
    7380            if (serverSock.getInputStream() == null) // poison
     
    129136    }
    130137
    131     // everything below here unsupported
     138    // most below here unsupported
     139
    132140    /** @deprecated unsupported */
    133141    @Deprecated
     
    142150        throw new IllegalArgumentException("unsupported");
    143151    }
    144     /** @deprecated unsupported */
    145     @Deprecated
     152
     153    /**
     154     * Returns null as of 0.9.33, prior to that threw IllegalArgumentException
     155     */
    146156    @Override
    147157    public ServerSocketChannel getChannel() {
    148         throw new IllegalArgumentException("unsupported");
    149     }
     158        return null;
     159    }
     160
    150161    /** @deprecated unsupported */
    151162    @Deprecated
     
    172183        throw new IllegalArgumentException("unsupported");
    173184    }
    174     /** @deprecated unsupported */
    175     @Deprecated
     185
     186    /**
     187     * Returns true as of 0.9.33, prior to that threw IllegalArgumentException
     188     */
    176189    @Override
    177190    public boolean isBound() {
    178         throw new IllegalArgumentException("unsupported");
    179     }
    180     /** @deprecated unsupported */
    181     @Deprecated
     191        return true;
     192    }
     193
     194    /**
     195     * Supported as of 0.9.33, prior to that threw IllegalArgumentException
     196     */
    182197    @Override
    183198    public boolean isClosed() {
    184         throw new IllegalArgumentException("unsupported");
    185     }
     199        return !_running;
     200    }
     201
    186202    /** @deprecated unsupported */
    187203    @Deprecated
     
    196212        throw new IllegalArgumentException("unsupported");
    197213    }
     214
     215    /**
     216     *  For debugging only
     217     *  @since 0.9.33
     218     */
     219    public static void renderStatusHTML(Writer out) throws IOException {
     220        out.write("<h2 id=\"debug_portmapper\">Internal Server Sockets</h2><table id=\"portmapper\"><tr><th>Port\n");
     221        List<Integer> ports = new ArrayList<Integer>(_sockets.keySet());
     222        Collections.sort(ports);
     223        for (Integer i : ports) {
     224            out.write("<tr><td>" + i + '\n');
     225        }
     226        out.write("</table>\n");
     227    }
    198228}
  • core/java/src/net/i2p/util/InternalSocket.java

    rbd341d4 r5f413ef  
    245245    }
    246246
    247     /** @deprecated unsupported */
    248     @Deprecated
    249     @Override
    250     public boolean isInputShutdown() {
    251         throw new UnsupportedOperationException();
    252     }
    253     /** @deprecated unsupported */
    254     @Deprecated
    255     @Override
    256     public boolean isOutputShutdown() {
    257         throw new UnsupportedOperationException();
    258     }
     247    /**
     248     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     249     */
     250    @Override
     251    public synchronized boolean isInputShutdown() {
     252        return _is == null;
     253    }
     254
     255    /**
     256     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     257     */
     258    @Override
     259    public synchronized boolean isOutputShutdown() {
     260        return _os == null;
     261    }
     262
    259263    /** @deprecated unsupported */
    260264    @Deprecated
     
    311315        throw new UnsupportedOperationException();
    312316    }
    313     /** @deprecated unsupported */
    314     @Deprecated
    315     @Override
    316     public void shutdownInput() {
    317         throw new UnsupportedOperationException();
    318     }
    319     /** @deprecated unsupported */
    320     @Deprecated
    321     @Override
    322     public void shutdownOutput() {
    323         throw new UnsupportedOperationException();
     317
     318    /**
     319     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     320     */
     321    @Override
     322    public synchronized void shutdownInput() throws IOException {
     323        if (_is != null) {
     324            _is.close();
     325            _is = null;
     326        }
     327    }
     328
     329    /**
     330     * Flushes (as the Socket javadocs advise) and closes.
     331     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     332     */
     333    @Override
     334    public void shutdownOutput() throws IOException {
     335        OutputStream out;
     336        synchronized(this) {
     337            out = _os;
     338        }
     339        if (out == null)
     340            return;
     341        // PipedOutputStream may not flush on close, not clear from javadocs
     342        try {
     343            out.flush();
     344            out.close();
     345        } finally {
     346            synchronized(this) {
     347                _os = null;
     348            }
     349        }
    324350    }
    325351}
Note: See TracChangeset for help on using the changeset viewer.