Ignore:
Timestamp:
07/27/09 16:53:20 (3 years ago)
Author:
octorian
Message:

Granular progress indication of time consuming network operations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java

    r449 r471  
    119119    private boolean useWiFi; 
    120120    private int fakeAvailable = -1; 
    121  
     121    private int bytesSent = 0; 
     122    private int bytesReceived = 0; 
     123     
    122124    /** 
    123125     * Provides a buffer used for incoming data. 
     
    193195        output = socket.openDataOutputStream(); 
    194196        localAddress = ((SocketConnection) socket).getLocalAddress(); 
    195  
     197        bytesSent = 0; 
     198        bytesReceived = 0; 
     199         
    196200        if (EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
    197201            String msg = "Connection established:\r\n" + "Socket: " + 
     
    305309    } 
    306310 
     311    /** 
     312     * Gets the number of bytes that have been sent since the 
     313     * connection was opened. 
     314     * <p> 
     315     * The counter is not synchronized, so it should only be 
     316     * called from the same thread as the send and receive 
     317     * methods. 
     318     * </p> 
     319     * @return bytes sent 
     320     */ 
     321    public int getBytesSent() { 
     322        return bytesSent; 
     323    } 
     324     
     325    /** 
     326     * Gets the number of bytes that have been received since the 
     327     * connection was opened. 
     328     * <p> 
     329     * The counter is not synchronized, so it should only be 
     330     * called from the same thread as the send and receive 
     331     * methods. 
     332     * </p> 
     333     * @return bytes received 
     334     */ 
     335    public int getBytesReceived() { 
     336        return bytesReceived; 
     337    } 
     338     
    307339    /** 
    308340     * Sends a string to the server. This method is used internally for 
     
    328360 
    329361            output.write(CRLF, 0, 2); 
     362            bytesSent += 2; 
    330363        } 
    331364        /** 
     
    356389                 * Write the string up to there and terminate it properly. 
    357390                 */ 
    358                 output.write((s.substring(i, j) + "\r\n").getBytes()); 
     391                byte[] buf = (s.substring(i, j) + "\r\n").getBytes(); 
     392                output.write(buf); 
     393                bytesSent += buf.length; 
    359394 
    360395                /** 
     
    386421        if (s == null) { 
    387422            output.write(CRLF, 0, 2); 
     423            bytesSent += 2; 
    388424        } else { 
    389             output.write((s + "\r\n").getBytes()); 
     425                byte[] buf = (s + "\r\n").getBytes(); 
     426            output.write(buf); 
     427            bytesSent += buf.length; 
    390428        } 
    391429 
     
    402440     */ 
    403441    public synchronized void sendRaw(String s) throws IOException { 
    404         byte[] bytes = s.getBytes(); 
     442        byte[] buf = s.getBytes(); 
    405443 
    406444        if (globalConfig.getConnDebug()) { 
     
    409447        } 
    410448 
    411         output.write(bytes, 0, bytes.length); 
    412  
     449        output.write(buf, 0, buf.length); 
     450        bytesSent += buf.length; 
     451         
    413452        output.flush(); 
    414453    } 
     
    487526            while (true) { 
    488527                int actual = input.read(buffer, count, 1); 
    489  
     528                 
    490529                /** 
    491530                 * If -1 is returned, the InputStream is already closed, 
     
    524563                // approach which screws up on mid-line LFs. (DK) 
    525564                else { 
     565                        bytesReceived += actual; 
     566                         
    526567                    byte b = buffer[count]; 
    527568                    readBytes++; 
Note: See TracChangeset for help on using the changeset viewer.