Changeset 2cf5221


Ignore:
Timestamp:
Apr 4, 2009 12:37:19 PM (11 years ago)
Author:
mkvore-commit <mkvore-commit@…>
Branches:
master
Children:
6b825fb
Parents:
de6edc6
Message:

minimize differences with mainstream apps/streaming

Location:
apps
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocket.java

    rde6edc6 r2cf5221  
    3232
    3333    /**
    34      * accept(true) has the same behaviour as accept().
    35      * accept(false) does not wait for a socket connecting. If a socket is
    36      * available in the queue, it is accepted. Else, null is returned.
     34     * accept(timeout) waits timeout ms for a socket connecting. If a socket is
     35     * not available during the timeout, return null. accept(0) behaves like accept()
    3736     *
    38      * @param true if the call should block until a socket is available
     37     * @param timeout in ms
    3938     *
    4039     * @return a connected I2PSocket, or null
     
    4342     *         from the data available (aka the I2PSession closed, etc)
    4443     * @throws ConnectException if the I2PServerSocket is closed
    45      * @throws SocketTimeoutException
     44     * @throws InterruptedException if thread is interrupted while waiting
    4645     */
    47     public I2PSocket accept(long timeout) throws I2PException, ConnectException, SocketTimeoutException, InterruptedException;
     46    public I2PSocket accept(long timeout) throws I2PException, ConnectException, InterruptedException;
    4847
    4948    /**
    50      * Waits until there is a socket waiting for acception or the timeout is
     49     * Wait until there is a socket waiting for acception or the timeout is
    5150     * reached.
    5251     *
    53      * @param timeoutMs timeout in ms. A negative value waits forever.
     52     * @param timeoutMs timeout in ms. If ms is 0, wait forever.
    5453     *
    5554     * @return true if a socket is available, false if not
     
    5857     *         from the data available (aka the I2PSession closed, etc)
    5958     * @throws ConnectException if the I2PServerSocket is closed
     59     * @throws InterruptedException if the thread is interrupted before
     60     *         completion
    6061     */
    6162    public void waitIncoming(long timeoutMs) throws I2PException, ConnectException, InterruptedException;
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocketImpl.java

    rde6edc6 r2cf5221  
    22
    33import java.net.ConnectException;
     4import java.net.SocketTimeoutException;
    45import java.util.ArrayList;
    56import java.util.Collections;
     
    5051    }
    5152   
    52  
    53    
    54    
    55    
    56    
    5753    /**
    5854     * Waits until there is a socket waiting for acception or the timeout is
     
    6460     *         from the data available (aka the I2PSession closed, etc)
    6561     * @throws ConnectException if the I2PServerSocket is closed
     62     * @throws InterruptedException if thread is interrupted while waiting
    6663     */
    6764    public void waitIncoming(long timeoutMs) throws I2PException, ConnectException, InterruptedException {
     
    9390        }
    9491
    95    
    96     /**
    97      * accept(true) has the same behaviour as accept().
    98      * accept(false) does not wait for a socket connecting. If a socket is
    99      * available in the queue, it is accepted. Else, null is returned.
    100      *
    101      * @param true if the call should block until a socket is available
     92    /**
     93     * accept(timeout) waits timeout ms for a socket connecting. If a socket is
     94     * not available during the timeout, return null. accept(0) behaves like accept()
     95     *
     96     * @param timeout in ms
    10297     *
    10398     * @return a connected I2PSocket, or null
     
    106101     *         from the data available (aka the I2PSession closed, etc)
    107102     * @throws ConnectException if the I2PServerSocket is closed
    108      */
    109 
     103     * @throws InterruptedException if thread is interrupted while waiting
     104     */
    110105        public I2PSocket accept(long timeout) throws I2PException, ConnectException, InterruptedException {
    111106        I2PSocket ret = null;
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionHandler.java

    rde6edc6 r2cf5221  
    33import java.util.concurrent.LinkedBlockingQueue;
    44import java.util.concurrent.TimeUnit;
    5 import java.util.ArrayList;
    6 import java.util.List;
    75
    86import net.i2p.I2PAppContext;
     
    4341        _log = context.logManager().getLog(ConnectionHandler.class);
    4442        _manager = mgr;
    45         _synQueue = new LinkedBlockingQueue(MAX_QUEUE_SIZE);
     43        _synQueue = new LinkedBlockingQueue<Packet>(MAX_QUEUE_SIZE);
     44        _synSignal= new Object();
    4645        _active = false;
    4746        _acceptTimeout = DEFAULT_ACCEPT_TIMEOUT;
     
    8483            SimpleScheduler.getInstance().addEvent(new TimeoutSyn(packet), _acceptTimeout);
    8584            if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE))
    86                 synchronized (this._synSignal)
    87                 {
    88                         this._synSignal.notifyAll();
    89                 }
    90 
    91        } else {
     85                synchronized (this._synSignal) {this._synSignal.notifyAll();}
     86        } else {
    9287            if (_log.shouldLog(Log.WARN))
    9388                _log.warn("Dropping new SYN request, as the queue is full");
     
    10499     */
    105100    public void waitSyn( long ms ) throws InterruptedException {
    106         synchronized (this._synSignal) 
     101        synchronized (this._synSignal)
    107102        {
    108                 this._synSignal.wait(ms);
     103                long now = this._context.clock().now() ;
     104                long expiration = now + ms ;
     105                while ( expiration > now || ms<=0 ) {
     106                        // check we have not missed a SYN packet before entering
     107                        // the lock
     108                        for ( Packet p : this._synQueue ) {
     109                                if ( p.isFlagSet(Packet.FLAG_SYNCHRONIZE) ) return ;
     110                        }
     111                        // wait until a SYN is signaled
     112                        if ( ms == 0) {
     113                                this._synSignal.wait();
     114                        } else {
     115                                this._synSignal.wait(expiration-now);
     116                                now = this._context.clock().now();
     117                        }
     118                }
    109119        }
    110120    }
     
    115125     * that they don't get thrown away while the SYN packet before it is queued.
    116126     *
    117      * @param timeoutMs max amount of time to wait for a connection (if negative,
    118      *                  wait indefinitely)
     127     * @param timeoutMs max amount of time to wait for a connection (if less
     128     *                  than 1ms, wait indefinitely)
    119129     * @return connection received, or null if there was a timeout or the
    120130     *                    handler was shut down
     
    126136        long expiration = timeoutMs + _context.clock().now();
    127137        while (true) {
     138            if ( (timeoutMs > 0) && (expiration < _context.clock().now()) )
     139                return null;
    128140            if (!_active) {
    129141                // fail all the ones we had queued up
     
    137149            }
    138150           
    139             if ( (timeoutMs > 0) && (expiration < _context.clock().now()) )
    140                 return null;
    141 
    142151            Packet syn = null;
    143152            while ( _active && syn == null) {
  • apps/streaming/java/src/net/i2p/client/streaming/I2PServerSocketFull.java

    rde6edc6 r2cf5221  
    11package net.i2p.client.streaming;
    22
    3 import java.net.ConnectException;
    43import java.net.SocketTimeoutException;
    54
    65import net.i2p.I2PAppContext;
    76import net.i2p.I2PException;
    8 import net.i2p.util.Clock;
    9 import net.i2p.util.Log;
    107
    118/**
     
    5350
    5451    /**
    55      * accept(true) has the same behaviour as accept().
    56      * accept(false) does not wait for a socket connecting. If a socket is
    57      * available in the queue, it is accepted. Else, null is returned.
     52     * accept(timeout) waits timeout ms for a socket connecting. If a socket is
     53     * not available during the timeout, return null. accept(0) behaves like accept()
    5854     *
    59      * @param true if the call should block until a socket is available
     55     * @param timeout in ms
    6056     *
    6157     * @return a connected I2PSocket, or null
     
    6359     * @throws I2PException if there is a problem with reading a new socket
    6460     *         from the data available (aka the I2PSession closed, etc)
    65      * @throws SocketTimeoutException if the timeout has been reached
    6661     */
    6762
     
    7974        }
    8075
    81         public void waitIncoming(long timeoutMs) throws InterruptedException {
     76        /**
     77         * block until a SYN packet is detected or the timeout is reached. If timeout is 0,
     78         * block until a SYN packet is detected.
     79         *
     80         * @param timeoutMs
     81         * @throws InterruptedException
     82         * @throws I2PException
     83         */
     84        public void waitIncoming(long timeoutMs) throws I2PException, InterruptedException {
     85                if (this._socketManager.getConnectionManager().getSession().isClosed())
     86                        throw new I2PException("Session is closed");
    8287        this._socketManager.getConnectionManager().getConnectionHandler().waitSyn(timeoutMs);
    8388        }
Note: See TracChangeset for help on using the changeset viewer.