In Java, write operation on SSLSocket API is blocking and the write operation does not support timeout also.
Can someone please explain?
My application creates two threads one for read and one for write.
Because:
To address your specific questions:
- Can there be a situation where write operation can block a thread forever? I checked on Internet and it seems that there is a possibility of blocking forever.
Yes. I've seen an application blocked for several days in such a situation. Although not, as @StephenC rightly says, forever. We haven't lived that long yet.
- How to add timeout for write operation?
You can do it at the TCP level with non-blocking I/O and a Selector
, and you can layer an SSLEngine
on top of that to get SSL, but it is a tedious and highly error-prone exercise that many have tried: few have succeeded. Not for the faint-hearted.