Changeset 232


Ignore:
Timestamp:
11/11/02 18:17:51 (20 years ago)
Author:
piso
Message:

getArticle(): support read timeout, one retry.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/mail/NntpSession.java

    r27 r232  
    33 *
    44 * Copyright (C) 2000-2002 Peter Graves
    5  * $Id: NntpSession.java,v 1.3 2002-10-02 18:00:46 piso Exp $
     5 * $Id: NntpSession.java,v 1.4 2002-11-11 18:17:51 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2727import java.io.OutputStreamWriter;
    2828import java.net.Socket;
     29import java.net.SocketException;
    2930import java.util.StringTokenizer;
    3031import org.armedbear.j.Debug;
     
    9899
    99100    public String getArticle(int articleNumber, ProgressNotifier progressNotifier)
     101    {
     102        if (socket == null)
     103            return _getArticle(articleNumber, progressNotifier);
     104
     105        // Existing connection.
     106        int timeout =
     107            Editor.preferences().getIntegerProperty(Property.NNTP_READ_TIMEOUT);
     108        try {
     109            socket.setSoTimeout(timeout);
     110        }
     111        catch (SocketException e) {
     112            Log.error(e);
     113        }
     114        String s = _getArticle(articleNumber, progressNotifier);
     115        if (s != null)
     116            return s;
     117        if (progressNotifier != null && progressNotifier.cancelled())
     118            return null;
     119
     120        if (timeout > 0) {
     121            Log.debug("reconnecting ...");
     122            disconnect();
     123            return _getArticle(articleNumber, progressNotifier);
     124        }
     125
     126        return null;
     127    }
     128
     129    private String _getArticle(int articleNumber, ProgressNotifier progressNotifier)
    100130    {
    101131        writeLine("ARTICLE ".concat(String.valueOf(articleNumber)));
     
    163193    public void disconnect()
    164194    {
    165         Log.debug("disconnecting...");
    166         writeLine("QUIT");
    167         readLine();
     195        if (socket != null) {
     196            writeLine("QUIT");
     197            readLine();
     198        }
    168199        abort();
    169200    }
    170201
    171     private void abort()
     202    public void abort()
    172203    {
    173204        if (socket != null) {
     
    197228        Debug.assertTrue(token.equals("211"));
    198229        count = Integer.parseInt(st.nextToken());
    199         Log.debug("count = " + count);
    200230        first = Integer.parseInt(st.nextToken());
    201         Log.debug("first = " + first);
    202231        last = Integer.parseInt(st.nextToken());
    203         Log.debug("last = " + last);
    204232        return true;
    205233    }
Note: See TracChangeset for help on using the changeset viewer.