LibRequestDirector.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:YiBo 作者:
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    HttpRoute route = req.getRoute();

    int connectCount = 0;
    for (;;) {
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (IOException ex) {
            try {
                managedConn.close();
            } catch (IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (DEBUG) {
                    Logger.debug("I/O exception ({}) caught when connecting to the target host: {}",
                            ex.getClass().getName(), ex.getMessage());
                    Logger.debug(ex.getMessage(), ex);
                    Logger.debug("Retrying connect");
                }
            } else {
                throw ex;
            }
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号