- Timestamp:
- 08/04/08 09:17:20 PM (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java
r209 r266 103 103 protected OutputStream output; 104 104 private boolean useWiFi; 105 private int fakeAvailable = -1; 105 106 106 107 /** … … 114 115 private byte[] buffer = new byte[128]; 115 116 116 /**117 * Holds the actual number of bytes in the buffer.118 */119 private int count;120 121 117 /** 122 118 * Holds a list of open connections … … 150 146 151 147 String protocolStr = (useSSL ? "ssl" : "socket"); 152 // This param , which allows bypassing the MDS proxy, should probably148 // This parameter, which allows bypassing the MDS proxy, should probably 153 149 // be a global user configurable option 154 150 String paramStr = (deviceSide ? ";deviceside=true" : ""); … … 287 283 * Sends a string to the server. This method is used internally for 288 284 * all outgoing communication to the server. The main thing it does 289 * it terminate the line with a CR/LF. If there are occur ences of CR or285 * it terminate the line with a CR/LF. If there are occurrences of CR or 290 286 * 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. 292 288 * 293 289 * @see #receive … … 316 312 317 313 /** 318 * Find next occur ence of a line separator or the end of the314 * Find next occurrence of a line separator or the end of the 319 315 * string. 320 316 */ … … 384 380 } 385 381 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 386 397 /** 387 398 * Receives a string from the server. This method is used internally for … … 403 414 * characters belonging to a line were read. The result was 404 415 * 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, 406 417 * that is). 407 418 * … … 423 434 StringBuffer resultBuffer = new StringBuffer(); 424 435 boolean stop = false; 436 int actualAvailable = input.available(); 437 int readBytes = 0; 438 int count; 425 439 426 440 /** … … 470 484 */ 471 485 // 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) 473 487 else { 474 488 byte b = buffer[count]; 489 readBytes++; 475 490 476 491 /** … … 504 519 EventLogger.logEvent(AppInfo.GUID, ("[RECV] " + resultBuffer.toString()).getBytes(), EventLogger.DEBUG_INFO); 505 520 } 521 if(actualAvailable > readBytes) { 522 fakeAvailable = actualAvailable - readBytes; 523 } 524 else { 525 fakeAvailable = -1; 526 } 506 527 507 528 return resultBuffer.toString();
