Changeset d2b09ec for apps/ministreaming


Ignore:
Timestamp:
Apr 14, 2004 3:28:02 PM (18 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7b03c95
Parents:
4cdd42f
git-author:
human <human> (04/14/04 15:28:02)
git-committer:
zzz <zzz@…> (04/14/04 15:28:02)
Message:

(human)

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

Legend:

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

    r4cdd42f rd2b09ec  
    11package net.i2p.client.streaming;
     2
     3import java.net.ConnectException;
    24
    35import net.i2p.I2PException;
     
    1820     * they should get refused (if .accept() doesnt occur in some small period)
    1921     *
     22     * @return a connected I2PSocket
     23     *
    2024     * @throws I2PException if there is a problem with reading a new socket
    2125     *         from the data available (aka the I2PSession closed, etc)
     26     * @throws ConnectException if the I2PServerSocket is closed
    2227     */
    23     public I2PSocket accept() throws I2PException;
     28    public I2PSocket accept() throws I2PException, ConnectException;
    2429
    2530    /**
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocketImpl.java

    r4cdd42f rd2b09ec  
    11package net.i2p.client.streaming;
     2
     3import java.net.ConnectException;
    24
    35import net.i2p.I2PException;
     
    1315    private I2PSocket cached = null; // buffer one socket here
    1416
     17    private boolean closing = false; // Are we being closed?
     18
     19    private Object acceptLock = new Object();
     20
    1521    public I2PServerSocketImpl(I2PSocketManager mgr) {
    1622        this.mgr = mgr;
    1723    }
    1824
    19     public synchronized I2PSocket accept() throws I2PException {
    20         while (cached == null) {
    21             myWait();
    22         }
    23         I2PSocket ret = cached;
    24         cached = null;
    25         notifyAll();
     25    public synchronized I2PSocket accept() throws I2PException, ConnectException {
     26        I2PSocket ret;
     27       
     28        synchronized (acceptLock) {
     29            while ((cached == null) && !closing) {
     30                myWait();
     31            }
     32
     33            if (closing) {
     34                throw new ConnectException("I2PServerSocket closed");
     35            }
     36
     37            ret = cached;
     38            cached = null;
     39            acceptLock.notifyAll();
     40        }
     41       
    2642        _log.debug("TIMING: handed out accept result " + ret.hashCode());
    2743        return ret;
    2844    }
    2945
    30     public synchronized boolean getNewSocket(I2PSocket s) {
    31         while (cached != null) {
    32             myWait();
    33         }
    34         cached = s;
    35         notifyAll();
     46    public boolean getNewSocket(I2PSocket s) {
     47        synchronized (acceptLock) {
     48            while (cached != null) {
     49                myWait();
     50            }
     51            cached = s;
     52            acceptLock.notifyAll();
     53        }
     54
    3655        return true;
    3756    }
    3857
    3958    public void close() throws I2PException {
    40         //noop
    41     }
    42 
    43     private void myWait() {
    44         try {
    45             wait();
    46         } catch (InterruptedException ex) {
    47         }
     59        synchronized (acceptLock) {
     60            closing = true;
     61            acceptLock.notifyAll();
     62        }
    4863    }
    4964
     
    5166        return mgr;
    5267    }
     68
     69    private void myWait() {
     70        try {
     71            acceptLock.wait();
     72        } catch (InterruptedException ex) {}
     73    }
    5374}
Note: See TracChangeset for help on using the changeset viewer.