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

(-)java/org/apache/tomcat/util/net/NioBlockingSelector.java (-4 lines)
Lines 47-56 Link Here
47
        boolean timedout = false;
47
        boolean timedout = false;
48
        int keycount = 1; //assume we can write
48
        int keycount = 1; //assume we can write
49
        long time = System.currentTimeMillis(); //start the timeout timer
49
        long time = System.currentTimeMillis(); //start the timeout timer
50
        if (socket.getBufHandler().getWriteBuffer() != buf) {
51
            socket.getBufHandler().getWriteBuffer().put(buf);
52
            buf = socket.getBufHandler().getWriteBuffer();
53
        }
54
        try {
50
        try {
55
            while ( (!timedout) && buf.hasRemaining()) {
51
            while ( (!timedout) && buf.hasRemaining()) {
56
                if (keycount > 0) { //only write if we were registered for a write
52
                if (keycount > 0) { //only write if we were registered for a write
(-)java/org/apache/tomcat/util/net/NioSelectorPool.java (-4 lines)
Lines 139-148 Link Here
139
        boolean timedout = false;
139
        boolean timedout = false;
140
        int keycount = 1; //assume we can write
140
        int keycount = 1; //assume we can write
141
        long time = System.currentTimeMillis(); //start the timeout timer
141
        long time = System.currentTimeMillis(); //start the timeout timer
142
        if ( socket.getBufHandler().getWriteBuffer()!= buf ) {
143
            socket.getBufHandler().getWriteBuffer().put(buf);
144
            buf = socket.getBufHandler().getWriteBuffer();
145
        }
146
        try {
142
        try {
147
            while ( (!timedout) && buf.hasRemaining() ) {
143
            while ( (!timedout) && buf.hasRemaining() ) {
148
                int cnt = 0;
144
                int cnt = 0;
(-)java/org/apache/tomcat/util/net/SecureNioChannel.java (-30 / +36 lines)
Lines 392-429 Link Here
392
     * @todo Implement this java.nio.channels.WritableByteChannel method
392
     * @todo Implement this java.nio.channels.WritableByteChannel method
393
     */
393
     */
394
    public int write(ByteBuffer src) throws IOException {
394
    public int write(ByteBuffer src) throws IOException {
395
        //make sure we can handle expand, and that we only use on buffer
395
        if ( src == this.netOutBuffer ) {
396
        if ( src != bufHandler.getWriteBuffer() ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler.");
396
            //we can get here through a recursive call
397
        //are we closing or closed?
397
            //by using the NioBlockingSelector
398
        if ( closing || closed) throw new IOException("Channel is in closing state.");
398
            int written = sc.write(src);
399
        
400
        //the number of bytes written
401
        int written = 0;
402
        
403
        if (!flush(netOutBuffer)) {
404
            //we haven't emptied out the buffer yet
405
            return written;
399
            return written;
400
        } else {
401
            //make sure we can handle expand, and that we only use on buffer
402
            if ( src != bufHandler.getWriteBuffer() ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler.");
403
            //are we closing or closed?
404
            if ( closing || closed) throw new IOException("Channel is in closing state.");
405
    
406
            //the number of bytes written
407
            int written = 0;
408
    
409
            if (!flush(netOutBuffer)) {
410
                //we haven't emptied out the buffer yet
411
                return written;
412
            }
413
    
414
            /*
415
             * The data buffer is empty, we can reuse the entire buffer.
416
             */
417
            netOutBuffer.clear();
418
    
419
            SSLEngineResult result = sslEngine.wrap(src, netOutBuffer);
420
            written = result.bytesConsumed();
421
            netOutBuffer.flip();
422
    
423
            if (result.getStatus() == Status.OK) {
424
                if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks();
425
            } else {
426
                throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus());
427
            }        
428
    
429
            //force a flush
430
            flush(netOutBuffer);
431
            return written;
406
        }
432
        }
407
408
        /*
409
         * The data buffer is empty, we can reuse the entire buffer.
410
         */
411
        netOutBuffer.clear();
412
413
        SSLEngineResult result = sslEngine.wrap(src, netOutBuffer);
414
        written = result.bytesConsumed();
415
        netOutBuffer.flip();
416
417
        if (result.getStatus() == Status.OK) {
418
            if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks();
419
        } else {
420
            throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus());
421
        }        
422
423
        //force a flush
424
        flush(netOutBuffer);
425
426
        return written;
427
    }
433
    }
428
    
434
    
429
    /**
435
    /**
(-)org/apache/coyote/http11/InternalNioOutputBuffer.java (-2 / +3 lines)
Lines 417-424 Link Here
417
417
418
        if (!committed) {
418
        if (!committed) {
419
            //Socket.send(socket, Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length) < 0
419
            //Socket.send(socket, Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length) < 0
420
            ByteBuffer buf = ByteBuffer.wrap(Constants.ACK_BYTES,0,Constants.ACK_BYTES.length);    
420
            //ByteBuffer buf = ByteBuffer.wrap(Constants.ACK_BYTES,0,Constants.ACK_BYTES.length);
421
            writeToSocket(buf,false);
421
            socket.getBufHandler().getWriteBuffer().put(Constants.ACK_BYTES,0,Constants.ACK_BYTES.length);
422
            writeToSocket(socket.getBufHandler().getWriteBuffer(),true);
422
        }
423
        }
423
424
424
    }
425
    }

Return to bug 43653