Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 49302632D27 for ; Mon, 21 Dec 2009 08:27:29 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 92482-06 for ; Mon, 21 Dec 2009 12:27:21 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 5C4CF63251A for ; Mon, 21 Dec 2009 08:27:21 -0400 (AST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id E44EE1E0450; Mon, 21 Dec 2009 20:27:16 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id HBUyqduquZGj; Mon, 21 Dec 2009 20:27:15 +0800 (WST) Received: from [10.1.1.6] (124-169-133-89.dyn.iinet.net.au [124.169.133.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id EBA191E044D; Mon, 21 Dec 2009 20:27:14 +0800 (WST) Message-ID: <4B2F6999.2050309@postnewspapers.com.au> Date: Mon, 21 Dec 2009 20:27:05 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: rsmogura@softperience.pl CC: PG-JDBC Mailing List Subject: Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify References: <4B2267A9.1080302@postnewspapers.com.au> <4B2C7A13.9080807@postnewspapers.com.au> <675723c4dae1093da0a64f50ac6327e7@smogura-softworks.eu> In-Reply-To: <675723c4dae1093da0a64f50ac6327e7@smogura-softworks.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/77 X-Sequence-Number: 20158 On 21/12/2009 5:41 PM, rsmogura@softperience.pl wrote: > One of disadvantage of checking plain socket is that available or read > uses "under" SSL Layer bytes, which include encrypted data, handshaking > data (the SSL supports renegotiation and session changes...?), and other > protocol specific, with no sense for application. But generally when whole > SSL socket bytes are read, then plain socket _should_ be "empty" too. Yes - when the plain socket is empty, the SSL socket is also empty. That does not imply the inverse, though. If the plain socket is NOT empty, that does not mean that the SSL socket is also NOT empty. As you said, the plain socket underlying the SSL socket may have bytes available() but they're just an SSL re-negotiation request or the like. So if you try to read from the SSL socket in this case, you will still block, even though the underlying socket did have bytes available to read. For available() on an ssl socket to work, you would need to implement it by using the underlying SSL implementation to read any data buffered on the plain socket (if any), process it, and return the amount of client data in it if any. So if the underlying socket's available() returns 0, your SSL available() returns 0 also. Otherwise it reads what's there, decodes it if it can, and returns how much readable user data it got. Unfortunately this can't be done with Java's SSLSocket, since you have no access to the underlying SSL engine implementation. It *can* be done with the Java 5 java.nio API and SSLEngine, possibly via a wrapper like SSLSocketChannel, though. In fact, if you're building on java.nio and SSLSocketChannel you can use exactly the approach described above. Really, the requirements to make this work are: - a non-blocking SSL socket; or - a thread that can afford to block on the socket -- Craig Ringer