Changeset fceec5c for apps/ministreaming


Ignore:
Timestamp:
May 5, 2009 9:46:17 AM (12 years ago)
Author:
mkvore-commit <mkvore-commit@…>
Branches:
master
Children:
30b73ffe
Parents:
e42f7ab
Message:

reverted changes to mstreaming and streaming

Location:
apps/ministreaming/java/src/net/i2p/client/streaming
Files:
6 edited

Legend:

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

    re42f7ab rfceec5c  
    3232
    3333    /**
    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()
    36      *
    37      * @param timeout in ms
    38      *
    39      * @return a connected I2PSocket, or null
    40      *
    41      * @throws I2PException if there is a problem with reading a new socket
    42      *         from the data available (aka the I2PSession closed, etc)
    43      * @throws ConnectException if the I2PServerSocket is closed
    44      * @throws InterruptedException if thread is interrupted while waiting
    45      */
    46     public I2PSocket accept(long timeout) throws I2PException, ConnectException, InterruptedException;
    47 
    48     /**
    49      * Wait until there is a socket waiting for acception or the timeout is
    50      * reached.
    51      *
    52      * @param timeoutMs timeout in ms. If ms is 0, wait forever.
    53      *
    54      * @return true if a socket is available, false if not
    55      *
    56      * @throws I2PException if there is a problem with reading a new socket
    57      *         from the data available (aka the I2PSession closed, etc)
    58      * @throws ConnectException if the I2PServerSocket is closed
    59      * @throws InterruptedException if the thread is interrupted before
    60      *         completion
    61      */
    62     public void waitIncoming(long timeoutMs) throws I2PException, ConnectException, InterruptedException;
    63 
    64     /**
    6534     * Set Sock Option accept timeout
    6635     * @param x timeout in ms
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocketImpl.java

    re42f7ab rfceec5c  
    22
    33import java.net.ConnectException;
    4 import java.net.SocketTimeoutException;
    54import java.util.ArrayList;
    65import java.util.Collections;
     
    5251   
    5352    /**
    54      * Waits until there is a socket waiting for acception or the timeout is
    55      * reached.
    56      *
    57      * @param timeoutMs timeout in ms. A negative value waits forever.
    58      *
    59      * @throws I2PException if there is a problem with reading a new socket
    60      *         from the data available (aka the I2PSession closed, etc)
    61      * @throws ConnectException if the I2PServerSocket is closed
    62      * @throws InterruptedException if thread is interrupted while waiting
    63      */
    64     public void waitIncoming(long timeoutMs) throws I2PException, ConnectException, InterruptedException {
    65         if (_log.shouldLog(Log.DEBUG))
    66             _log.debug("waitIncoming() called, pending: " + pendingSockets.size());
    67        
    68         boolean isTimed = (timeoutMs>0);
    69         if (isTimed) {
    70             Clock clock = I2PAppContext.getGlobalContext().clock();
    71             long now = clock.now();
    72             long end = now + timeoutMs;
    73             while (pendingSockets.size() <= 0 && now<end) {
    74                 if (closing) throw new ConnectException("I2PServerSocket closed");
    75                 synchronized(socketAddedLock) {
    76                     socketAddedLock.wait(end - now);
    77                 }
    78                 now = clock.now();
    79             }
    80         } else {
    81             while (pendingSockets.size() <= 0) {
    82                 if (closing) throw new ConnectException("I2PServerSocket closed");
    83                 try {
    84                     synchronized(socketAddedLock) {
    85                         socketAddedLock.wait();
    86                     }
    87                 } catch (InterruptedException ie) {}
    88             }
    89         }
    90         }
    91 
    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
    97      *
    98      * @return a connected I2PSocket, or null
    99      *
    100      * @throws I2PException if there is a problem with reading a new socket
    101      *         from the data available (aka the I2PSession closed, etc)
    102      * @throws ConnectException if the I2PServerSocket is closed
    103      * @throws InterruptedException if thread is interrupted while waiting
    104      */
    105         public I2PSocket accept(long timeout) throws I2PException, ConnectException, InterruptedException {
    106         I2PSocket ret = null;
    107        
    108         if (timeout<=0) {
    109                 ret = accept();
    110         } else {
    111                 long now  = I2PAppContext.getGlobalContext().clock().now();
    112             long expiration = timeout + now ;
    113                 synchronized (pendingSockets) {
    114                 while (pendingSockets.size() == 0 && expiration>now) {
    115                         pendingSockets.wait(expiration-now);
    116                         now  = I2PAppContext.getGlobalContext().clock().now();
    117                 }
    118                 ret = (I2PSocket)pendingSockets.remove(0);
    119             }
    120             if (ret != null) {
    121                 synchronized (socketAcceptedLock) {
    122                     socketAcceptedLock.notifyAll();
    123                 }
    124             }           
    125         }
    126                 return ret;
    127         }
    128 
    129         /**
    13053     * Waits for the next socket connecting.  If a remote user tried to make a
    13154     * connection and the local application wasn't .accept()ing new connections,
     
    14669       
    14770        while ( (ret == null) && (!closing) ){
    148                 try {
    149                         this.waitIncoming(0);
    150                         ret = accept(1);
    151                 } catch (InterruptedException e) {
    152                         throw new I2PException("Thread interrupted") ;
    153                 }
     71            while (pendingSockets.size() <= 0) {
     72                if (closing) throw new ConnectException("I2PServerSocket closed");
     73                try {
     74                    synchronized(socketAddedLock) {
     75                        socketAddedLock.wait();
     76                    }
     77                } catch (InterruptedException ie) {}
     78            }
     79            synchronized (pendingSockets) {
     80                if (pendingSockets.size() > 0) {
     81                    ret = (I2PSocket)pendingSockets.remove(0);
     82                }
     83            }
     84            if (ret != null) {
     85                synchronized (socketAcceptedLock) {
     86                    socketAcceptedLock.notifyAll();
     87                }
     88            }
    15489        }
    15590       
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java

    re42f7ab rfceec5c  
    351351                bc.notifyAll();
    352352            }
     353            boolean timedOut = false;
    353354
    354355            while ( (read.length == 0) && (!inStreamClosed) ) {
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java

    re42f7ab rfceec5c  
    1414import net.i2p.client.I2PSession;
    1515import net.i2p.client.I2PSessionException;
     16import net.i2p.data.Destination;
    1617import net.i2p.util.Log;
    1718
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerImpl.java

    re42f7ab rfceec5c  
    131131    public void messageAvailable(I2PSession session, int msgId, long size) {
    132132        try {
     133            I2PSocketImpl s;
    133134            byte msg[] = session.receiveMessage(msgId);
    134135            if (msg.length == 1 && msg[0] == -1) {
  • apps/ministreaming/java/src/net/i2p/client/streaming/TestSwarm.java

    re42f7ab rfceec5c  
    2929    private boolean _dead; // unused? used elsewhere?
    3030   
    31     public void antiCompilationWarnings() {
    32         _log.debug(""+_conOptions+_dead);
    33     }
    34    
    3531    public static void main(String args[]) {
    3632        if (args.length < 1) {
     
    136132        }
    137133       
    138         public void antiCompilationWarnings() {
    139                 _log.debug(""+this._lastReceived+this._lastReceivedOn+this._started);
    140         }
    141         public void antiCompilationWarnings(long x, long y) {
    142                 if (false)
    143                         _log.debug(""+x+y);
    144         }
    145 
    146134        public Flooder(I2PSocket socket) {
    147135            _socket = socket;
     
    167155            long value = 0;
    168156            long lastSend = _context.clock().now();
    169             this.antiCompilationWarnings(value, lastSend);
    170            
    171157            if (_socket == null) {
    172158                try {
Note: See TracChangeset for help on using the changeset viewer.