View | Details | Raw Unified | Return to bug 48843
Collapse All | Expand All

(-)connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java (-40 / +59 lines)
Lines 1029-1037 Link Here
1029
        protected long[] desc;
1029
        protected long[] desc;
1030
1030
1031
        protected long[] addS;
1031
        protected long[] addS;
1032
        protected int addCount = 0;
1032
        protected volatile int addCount = 0;
1033
        
1033
        
1034
        protected int keepAliveCount = 0;
1034
        protected volatile int keepAliveCount = 0;
1035
        public int getKeepAliveCount() { return keepAliveCount; }
1035
        public int getKeepAliveCount() { return keepAliveCount; }
1036
1036
1037
        /**
1037
        /**
Lines 1118-1132 Link Here
1118
                    }
1118
                    }
1119
                }
1119
                }
1120
1120
1121
                while (keepAliveCount < 1 && addCount < 1) {
1121
                if (keepAliveCount < 1 && addCount < 1) {
1122
                    // Reset maintain time.
1122
                    synchronized (this) {
1123
                    maintainTime = 0;
1123
                        while (keepAliveCount < 1 && addCount < 1) {
1124
                    try {
1124
                            // Reset maintain time.
1125
                        synchronized (this) {
1125
                            maintainTime = 0;
1126
                            this.wait();
1126
                            try {
1127
                                this.wait();
1128
                            } catch (InterruptedException e) {
1129
                                // Ignore
1130
                            }
1127
                        }
1131
                        }
1128
                    } catch (InterruptedException e) {
1129
                        // Ignore
1130
                    }
1132
                    }
1131
                }
1133
                }
1132
1134
Lines 1134-1150 Link Here
1134
                    // Add sockets which are waiting to the poller
1136
                    // Add sockets which are waiting to the poller
1135
                    if (addCount > 0) {
1137
                    if (addCount > 0) {
1136
                        synchronized (this) {
1138
                        synchronized (this) {
1137
                            for (int i = (addCount - 1); i >= 0; i--) {
1139
                            int successCount = 0;
1138
                                int rv = Poll.add
1140
                            try {
1139
                                    (serverPollset, addS[i], Poll.APR_POLLIN);
1141
                                for (int i = (addCount - 1); i >= 0; i--) {
1140
                                if (rv == Status.APR_SUCCESS) {
1142
                                    int rv = Poll.add
1141
                                    keepAliveCount++;
1143
                                        (serverPollset, addS[i], Poll.APR_POLLIN);
1142
                                } else {
1144
                                    if (rv == Status.APR_SUCCESS) {
1143
                                    // Can't do anything: close the socket right away
1145
                                        successCount++;
1144
                                    Socket.destroy(addS[i]);
1146
                                    } else {
1147
                                        // Can't do anything: close the socket right away
1148
                                        Socket.destroy(addS[i]);
1149
                                    }
1145
                                }
1150
                                }
1151
                            } finally {
1152
                                keepAliveCount += successCount;
1153
                                addCount = 0;
1146
                            }
1154
                            }
1147
                            addCount = 0;
1148
                        }
1155
                        }
1149
                    }
1156
                    }
1150
                    maintainTime += pollTime;
1157
                    maintainTime += pollTime;
Lines 1347-1356 Link Here
1347
        protected long[] desc;
1354
        protected long[] desc;
1348
        protected HashMap sendfileData;
1355
        protected HashMap sendfileData;
1349
        
1356
        
1350
        protected int sendfileCount;
1357
        protected volatile int sendfileCount;
1351
        public int getSendfileCount() { return sendfileCount; }
1358
        public int getSendfileCount() { return sendfileCount; }
1352
1359
1353
        protected ArrayList addS;
1360
        protected ArrayList addS;
1361
        protected volatile int addCount;
1354
1362
1355
        /**
1363
        /**
1356
         * Create the sendfile poller. With some versions of APR, the maximum poller size will
1364
         * Create the sendfile poller. With some versions of APR, the maximum poller size will
Lines 1371-1376 Link Here
1371
            desc = new long[size * 2];
1379
            desc = new long[size * 2];
1372
            sendfileData = new HashMap(size);
1380
            sendfileData = new HashMap(size);
1373
            addS = new ArrayList();
1381
            addS = new ArrayList();
1382
            addCount = 0;
1374
        }
1383
        }
1375
1384
1376
        /**
1385
        /**
Lines 1378-1383 Link Here
1378
         */
1387
         */
1379
        protected void destroy() {
1388
        protected void destroy() {
1380
            // Close any socket remaining in the add queue
1389
            // Close any socket remaining in the add queue
1390
            addCount = 0;
1381
            for (int i = (addS.size() - 1); i >= 0; i--) {
1391
            for (int i = (addS.size() - 1); i >= 0; i--) {
1382
                SendfileData data = (SendfileData) addS.get(i);
1392
                SendfileData data = (SendfileData) addS.get(i);
1383
                Socket.destroy(data.socket);
1393
                Socket.destroy(data.socket);
Lines 1445-1450 Link Here
1445
            // at most for pollTime before being polled
1455
            // at most for pollTime before being polled
1446
            synchronized (this) {
1456
            synchronized (this) {
1447
                addS.add(data);
1457
                addS.add(data);
1458
                addCount++;
1448
                this.notify();
1459
                this.notify();
1449
            }
1460
            }
1450
            return false;
1461
            return false;
Lines 1482-1516 Link Here
1482
                    }
1493
                    }
1483
                }
1494
                }
1484
1495
1485
                while (sendfileCount < 1 && addS.size() < 1) {
1496
                if (sendfileCount < 1 && addCount < 1) {
1486
                    // Reset maintain time.
1497
                    synchronized (this) {
1487
                    maintainTime = 0;
1498
                        while (sendfileCount < 1 && addS.size() < 1) {
1488
                    try {
1499
                            // Reset maintain time.
1489
                        synchronized (this) {
1500
                            maintainTime = 0;
1490
                            this.wait();
1501
                            try {
1502
                                this.wait();
1503
                            } catch (InterruptedException e) {
1504
                                // Ignore
1505
                            }
1491
                        }
1506
                        }
1492
                    } catch (InterruptedException e) {
1493
                        // Ignore
1494
                    }
1507
                    }
1495
                }
1508
                }
1496
1509
1497
                try {
1510
                try {
1498
                    // Add socket to the poller
1511
                    // Add socket to the poller
1499
                    if (addS.size() > 0) {
1512
                    if (addCount > 0) {
1500
                        synchronized (this) {
1513
                        synchronized (this) {
1501
                            for (int i = (addS.size() - 1); i >= 0; i--) {
1514
                            int successCount = 0;
1502
                                SendfileData data = (SendfileData) addS.get(i);
1515
                            try {
1503
                                int rv = Poll.add(sendfilePollset, data.socket, Poll.APR_POLLOUT);
1516
                                for (int i = (addS.size() - 1); i >= 0; i--) {
1504
                                if (rv == Status.APR_SUCCESS) {
1517
                                    SendfileData data = (SendfileData) addS.get(i);
1505
                                    sendfileData.put(new Long(data.socket), data);
1518
                                    int rv = Poll.add(sendfilePollset, data.socket, Poll.APR_POLLOUT);
1506
                                    sendfileCount++;
1519
                                    if (rv == Status.APR_SUCCESS) {
1507
                                } else {
1520
                                        sendfileData.put(new Long(data.socket), data);
1508
                                    log.warn(sm.getString("endpoint.sendfile.addfail", "" + rv, Error.strerror(rv)));
1521
                                        successCount++;
1509
                                    // Can't do anything: close the socket right away
1522
                                    } else {
1510
                                    Socket.destroy(data.socket);
1523
                                        log.warn(sm.getString("endpoint.sendfile.addfail", "" + rv, Error.strerror(rv)));
1524
                                        // Can't do anything: close the socket right away
1525
                                        Socket.destroy(data.socket);
1526
                                    }
1511
                                }
1527
                                }
1528
                            } finally {
1529
                                sendfileCount += successCount;
1530
                                addS.clear();
1531
                                addCount = 0;
1512
                            }
1532
                            }
1513
                            addS.clear();
1514
                        }
1533
                        }
1515
                    }
1534
                    }
1516
1535

Return to bug 48843