Changeset 61749aa
- Timestamp:
- Sep 27, 2008 10:59:22 PM (12 years ago)
- Branches:
- master
- Children:
- 5913d9e
- Parents:
- b0313bd6
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java
rb0313bd6 r61749aa 13 13 import java.net.Socket; 14 14 import java.net.SocketException; 15 import java.net.SocketTimeoutException; 15 16 import java.util.Iterator; 16 17 import java.util.Properties; … … 220 221 _log.error("Error accepting", ce); 221 222 // not killing the server.. 223 } catch(SocketTimeoutException ste) { 224 // ignored, we never set the timeout 222 225 } 223 226 } -
apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocket.java
rb0313bd6 r61749aa 3 3 import java.net.ConnectException; 4 4 5 import java.net.SocketTimeoutException; 5 6 import net.i2p.I2PException; 6 7 … … 25 26 * from the data available (aka the I2PSession closed, etc) 26 27 * @throws ConnectException if the I2PServerSocket is closed 28 * @throws SocketTimeoutException 27 29 */ 28 public I2PSocket accept() throws I2PException, ConnectException; 30 public I2PSocket accept() throws I2PException, ConnectException, SocketTimeoutException; 31 32 /** 33 * Set Sock Option accept timeout 34 * @param x 35 */ 36 public void setSoTimeout(long x); 37 38 /** 39 * Get Sock Option accept timeout 40 * @return timeout 41 */ 42 public long getSoTimeout(); 29 43 30 44 /** -
apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocketImpl.java
rb0313bd6 r61749aa 31 31 private Object socketAddedLock = new Object(); 32 32 33 /** 34 * Set Sock Option accept timeout stub, does nothing 35 * @param x 36 */ 37 public void setSoTimeout(long x) { 38 } 39 40 /** 41 * Get Sock Option accept timeout stub, does nothing 42 * @return timeout 43 */ 44 public long getSoTimeout() { 45 return -1; 46 } 47 33 48 public I2PServerSocketImpl(I2PSocketManager mgr) { 34 49 this.mgr = mgr; -
apps/ministreaming/java/src/net/i2p/client/streaming/StreamSinkServer.java
rb0313bd6 r61749aa 6 6 import java.io.InputStream; 7 7 import java.net.ConnectException; 8 import java.net.SocketTimeoutException; 8 9 import java.util.Properties; 9 10 … … 108 109 _log.error("Connection already dropped", ce); 109 110 return; 111 } catch(SocketTimeoutException ste) { 112 // ignored 110 113 } 111 114 } -
apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java
rb0313bd6 r61749aa 40 40 private volatile int _numWaiting; 41 41 private Object _connectionLock; 42 private long SoTimeout; 42 43 43 44 public ConnectionManager(I2PAppContext context, I2PSession session, int maxConcurrent, ConnectionOptions defaultOptions) { … … 59 60 _defaultOptions = defaultOptions; 60 61 _numWaiting = 0; 62 /** Socket timeout for accept() */ 63 SoTimeout = -1; 64 61 65 _context.statManager().createRateStat("stream.con.lifetimeMessagesSent", "How many messages do we send on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 }); 62 66 _context.statManager().createRateStat("stream.con.lifetimeMessagesReceived", "How many messages do we receive on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 }); … … 91 95 } 92 96 97 /** 98 * Set the socket accept() timeout. 99 * @param x 100 */ 101 public void MsetSoTimeout(long x) { 102 SoTimeout = x; 103 } 104 105 /** 106 * Get the socket accept() timeout. 107 * @return 108 */ 109 public long MgetSoTimeout() { 110 return SoTimeout; 111 } 112 93 113 public void setAllowIncomingConnections(boolean allow) { 94 114 _connectionHandler.setActive(allow); -
apps/streaming/java/src/net/i2p/client/streaming/I2PServerSocketFull.java
rb0313bd6 r61749aa 1 1 package net.i2p.client.streaming; 2 2 3 import java.net.SocketTimeoutException; 4 import java.util.logging.Level; 5 import java.util.logging.Logger; 3 6 import net.i2p.I2PException; 4 7 … … 14 17 } 15 18 16 public I2PSocket accept() throws I2PException { 19 /** 20 * 21 * @return 22 * @throws net.i2p.I2PException 23 * @throws SocketTimeoutException 24 */ 25 public I2PSocket accept() throws I2PException, SocketTimeoutException { 17 26 return _socketManager.receiveSocket(); 18 27 } 19 28 20 public void close() { _socketManager.getConnectionManager().setAllowIncomingConnections(false); } 29 public long getSoTimeout() { 30 return _socketManager.getConnectionManager().MgetSoTimeout(); 31 } 21 32 22 public I2PSocketManager getManager() { return _socketManager; } 33 public void setSoTimeout(long x) { 34 _socketManager.getConnectionManager().MsetSoTimeout(x); 35 } 36 /** 37 * Close the connection. 38 */ 39 public void close() { 40 _socketManager.getConnectionManager().setAllowIncomingConnections(false); 41 } 42 43 /** 44 * 45 * @return _socketManager 46 */ 47 public I2PSocketManager getManager() { 48 return _socketManager; 49 } 23 50 } -
apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java
rb0313bd6 r61749aa 2 2 3 3 import java.net.NoRouteToHostException; 4 import java.net.SocketTimeoutException; 4 5 import java.util.HashSet; 5 6 import java.util.Iterator; … … 45 46 _session = null; 46 47 } 48 49 /** 50 * 51 * @param context 52 * @param session 53 * @param opts 54 * @param name 55 */ 47 56 public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name) { 48 57 this(); … … 55 64 /** 56 65 * 66 * 67 * @param context 68 * @param session 69 * @param opts 70 * @param name 57 71 */ 58 72 public void init(I2PAppContext context, I2PSession session, Properties opts, String name) { … … 97 111 } 98 112 99 public I2PSocket receiveSocket() throws I2PException { 113 /** 114 * 115 * @return 116 * @throws net.i2p.I2PException 117 * @throws java.net.SocketTimeoutException 118 */ 119 public I2PSocket receiveSocket() throws I2PException, SocketTimeoutException { 100 120 verifySession(); 101 Connection con = _connectionManager.getConnectionHandler().accept( -1);102 if (_log.shouldLog(Log.DEBUG))121 Connection con = _connectionManager.getConnectionHandler().accept(_connectionManager.MgetSoTimeout()); 122 if(_log.shouldLog(Log.DEBUG)) { 103 123 _log.debug("receiveSocket() called: " + con); 124 } 104 125 if (con != null) { 105 126 I2PSocketFull sock = new I2PSocketFull(con); … … 107 128 return sock; 108 129 } else { 130 if(_connectionManager.MgetSoTimeout() == -1) { 109 131 return null; 132 } 133 throw new SocketTimeoutException("I2PSocket timed out"); 110 134 } 111 135 } … … 115 139 * the timeout specified, false otherwise. This call blocks. 116 140 * 141 * 142 * @param peer 143 * @param timeoutMs 144 * @return 117 145 */ 118 146 public boolean ping(Destination peer, long timeoutMs) { -
apps/streaming/java/src/net/i2p/client/streaming/RetransmissionTimer.java
rb0313bd6 r61749aa 6 6 * 7 7 */ 8 class RetransmissionTimer extends SimpleTimer {8 public class RetransmissionTimer extends SimpleTimer { 9 9 private static final RetransmissionTimer _instance = new RetransmissionTimer(); 10 10 public static final SimpleTimer getInstance() { return _instance; } -
core/java/src/net/i2p/util/Executor.java
rb0313bd6 r61749aa 9 9 private Log _log; 10 10 private List _readyEvents; 11 public Executor(I2PAppContext ctx, Log log, List events) { 11 private SimpleStore runn; 12 13 public Executor(I2PAppContext ctx, Log log, List events, SimpleStore x) { 12 14 _context = ctx; 13 15 _readyEvents = events; 16 runn = x; 14 17 } 18 15 19 public void run() { 16 while (true) {20 while(runn.getAnswer()) { 17 21 SimpleTimer.TimedEvent evt = null; 18 22 synchronized (_readyEvents) { -
core/java/src/net/i2p/util/SimpleTimer.java
rb0313bd6 r61749aa 26 26 private Map _eventTimes; 27 27 private List _readyEvents; 28 28 private SimpleStore runn; 29 29 30 protected SimpleTimer() { this("SimpleTimer"); } 30 31 protected SimpleTimer(String name) { 32 runn = new SimpleStore(true); 31 33 _context = I2PAppContext.getGlobalContext(); 32 34 _log = _context.logManager().getLog(SimpleTimer.class); … … 39 41 runner.start(); 40 42 for (int i = 0; i < 3; i++) { 41 I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents ));43 I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents, runn)); 42 44 executor.setName(name + "Executor " + i); 43 45 executor.setDaemon(true); … … 46 48 } 47 49 50 /** 51 * Removes the SimpleTimer. 52 */ 53 public void removeSimpleTimer() { 54 synchronized(_events) { 55 runn.setAnswer(false); 56 _events.notifyAll(); 57 } 58 } 59 60 /** 61 * 62 * @param event 63 * @param timeoutMs 64 */ 48 65 public void reschedule(TimedEvent event, long timeoutMs) { 49 66 addEvent(event, timeoutMs, false); … … 56 73 * timeout. If this is not the desired behavior, call removeEvent first. 57 74 * 75 * @param event 76 * @param timeoutMs 58 77 */ 59 78 public void addEvent(TimedEvent event, long timeoutMs) { addEvent(event, timeoutMs, true); } 60 79 /** 80 * @param event 81 * @param timeoutMs 61 82 * @param useEarliestTime if its already scheduled, use the earlier of the 62 83 * two timeouts, else use the later … … 144 165 private long _occurredTime; 145 166 private long _occurredEventCount; 146 private TimedEvent _recentEvents[] = new TimedEvent[5];147 167 // not used 168 // private TimedEvent _recentEvents[] = new TimedEvent[5]; 148 169 private class SimpleTimerRunner implements Runnable { 149 170 public void run() { 150 171 List eventsToFire = new ArrayList(1); 151 while (true) {172 while(runn.getAnswer()) { 152 173 try { 153 174 synchronized (_events) { … … 159 180 long nextEventDelay = -1; 160 181 Object nextEvent = null; 161 while (true) { 162 if (_events.size() <= 0) break; 182 while(runn.getAnswer()) { 183 if(_events.size() <= 0) { 184 break; 185 } 163 186 Long when = (Long)_events.firstKey(); 164 187 if (when.longValue() <= now) {
Note: See TracChangeset
for help on using the changeset viewer.