From: Craig Ringer <craig@postnewspapers.com.au>
To: rsmogura@softperience.pl
Cc: PG-JDBC Mailing List <pgsql-jdbc@postgresql.org>
Subject: Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify
Date: Mon, 21 Dec 2009 20:27:05 +0800
Message-ID: <4B2F6999.2050309@postnewspapers.com.au> (raw)
In-Reply-To: <675723c4dae1093da0a64f50ac6327e7@smogura-softworks.eu>
References: <C746D04C.CAE15%scott_ribe@killerbytes.com>
<4B2267A9.1080302@postnewspapers.com.au>
<4B2C7A13.9080807@postnewspapers.com.au>
<675723c4dae1093da0a64f50ac6327e7@smogura-softworks.eu>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: craig@postnewspapers.com.au, rsmogura@softperience.pl
Subject: Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify
In-Reply-To: <4B2F6999.2050309@postnewspapers.com.au>
References: <C746D04C.CAE15%scott_ribe@killerbytes.com> <4B2267A9.1080302@postnewspapers.com.au> <4B2C7A13.9080807@postnewspapers.com.au> <675723c4dae1093da0a64f50ac6327e7@smogura-softworks.eu> <4B2F6999.2050309@postnewspapers.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox