Show
Ignore:
Timestamp:
08/04/08 09:17:20 PM (4 months ago)
Author:
octorian
Message:

Initial IMAP IDLE implementation

Files:
1 modified

Legend:

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

    r209 r266  
    103103    protected OutputStream output; 
    104104    private boolean useWiFi; 
     105    private int fakeAvailable = -1; 
    105106     
    106107    /** 
     
    114115    private byte[] buffer = new byte[128]; 
    115116     
    116     /** 
    117      * Holds the actual number of bytes in the buffer. 
    118      */ 
    119     private int count; 
    120  
    121117    /** 
    122118     * Holds a list of open connections 
     
    150146         
    151147        String protocolStr = (useSSL ? "ssl" : "socket"); 
    152         // This param, which allows bypassing the MDS proxy, should probably 
     148        // This parameter, which allows bypassing the MDS proxy, should probably 
    153149        // be a global user configurable option 
    154150        String paramStr = (deviceSide ? ";deviceside=true" : ""); 
     
    287283     * Sends a string to the server. This method is used internally for 
    288284     * all outgoing communication to the server. The main thing it does 
    289      * it terminate the line with a CR/LF. If there are occurences of CR or 
     285     * it terminate the line with a CR/LF. If there are occurrences of CR or 
    290286     * LF inside the string, the method ensures that proper CR/LF sequences 
    291      * are sent for them, since this is what most internet protocols expect. 
     287     * are sent for them, since this is what most Internet protocols expect. 
    292288     * 
    293289     * @see #receive 
     
    316312                 
    317313                /** 
    318                  * Find next occurence of a line separator or the end of the 
     314                 * Find next occurrence of a line separator or the end of the 
    319315                 * string. 
    320316                 */ 
     
    384380    } 
    385381 
     382    /** 
     383     * Returns the number of bytes available for reading. 
     384     * Used to poll the connection without blocking. 
     385     *  
     386     * @see InputStream#available() 
     387     */ 
     388    public int available() throws IOException { 
     389        if(fakeAvailable == -1) { 
     390                return input.available(); 
     391        } 
     392        else { 
     393                return fakeAvailable; 
     394        } 
     395    } 
     396     
    386397    /** 
    387398     * Receives a string from the server. This method is used internally for 
     
    403414         * characters belonging to a line were read. The result was 
    404415         * a high level of heap fragmentation, which made applications 
    405          * instable on MIDP devices (that don't provide compacting GC, 
     416         * unstable on MIDP devices (that don't provide compacting GC, 
    406417         * that is). 
    407418         * 
     
    423434        StringBuffer resultBuffer = new StringBuffer(); 
    424435        boolean stop = false; 
     436        int actualAvailable = input.available(); 
     437        int readBytes = 0; 
     438        int count; 
    425439         
    426440        /** 
     
    470484                 */ 
    471485                // Note: We really should look for CRLF, and not use this 
    472                 // half-assed approach which screws up on mid-lime LFs. (DK) 
     486                // approach which screws up on mid-line LFs. (DK) 
    473487                else { 
    474488                    byte b = buffer[count]; 
     489                    readBytes++; 
    475490                     
    476491                    /** 
     
    504519            EventLogger.logEvent(AppInfo.GUID, ("[RECV] " + resultBuffer.toString()).getBytes(), EventLogger.DEBUG_INFO); 
    505520        } 
     521        if(actualAvailable > readBytes) { 
     522                fakeAvailable = actualAvailable - readBytes; 
     523        } 
     524        else { 
     525                fakeAvailable = -1; 
     526        } 
    506527         
    507528        return resultBuffer.toString();