Usage of SocketFactory#createSocket(String host, int port)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Usage of SocketFactory#createSocket(String host, int port)

Pascal Schumacher
Hello everybody,

took a look at the camel-smpp source code and noticed that is using
javax.net.SocketFactory#createSocket(String host, int port) which
"creates a socket and connects it to the specified port number at the
specified address" according to the javadoc.

As Socket#setSoTimeout is called later on and
Socket#connect(SocketAddress endpoint, int timeout) exists, I guess the
initial connection is created without any timeout?

As blocking operations without timeouts should be avoided, should the
code be changed to:

socket = socketFactory.createSocket();
socket.connect(new InetSocketAddress(host, port), timeout);

or am I missing something?

Thanks,

Pascal


Reply | Threaded
Open this post in threaded view
|

Re: Usage of SocketFactory#createSocket(String host, int port)

Andrea Cosentino-2
I believe you're right.

--
Andrea Cosentino 
----------------------------------
Apache Camel PMC Member
Apache Karaf Committer
Apache Servicemix PMC Member
Email: [hidden email]
Twitter: @oscerd2
Github: oscerd






On Tuesday, March 13, 2018, 8:33:51 PM GMT+1, Pascal Schumacher <[hidden email]> wrote:





Hello everybody,

took a look at the camel-smpp source code and noticed that is using
javax.net.SocketFactory#createSocket(String host, int port) which
"creates a socket and connects it to the specified port number at the
specified address" according to the javadoc.

As Socket#setSoTimeout is called later on and
Socket#connect(SocketAddress endpoint, int timeout) exists, I guess the
initial connection is created without any timeout?

As blocking operations without timeouts should be avoided, should the
code be changed to:

socket = socketFactory.createSocket();
socket.connect(new InetSocketAddress(host, port), timeout);

or am I missing something?

Thanks,

Pascal


Reply | Threaded
Open this post in threaded view
|

Re: Usage of SocketFactory#createSocket(String host, int port)

Claus Ibsen-2
In reply to this post by Pascal Schumacher
Hi

Yeah that sounds reasonable, have you checked the javadoc of the jdk
operations? But in all regards I do think your suggestion seems
better. You are welcome to do a PR / commit / JIRA etc.

On Tue, Mar 13, 2018 at 8:33 PM, Pascal Schumacher
<[hidden email]> wrote:

> Hello everybody,
>
> took a look at the camel-smpp source code and noticed that is using
> javax.net.SocketFactory#createSocket(String host, int port) which "creates a
> socket and connects it to the specified port number at the specified
> address" according to the javadoc.
>
> As Socket#setSoTimeout is called later on and Socket#connect(SocketAddress
> endpoint, int timeout) exists, I guess the initial connection is created
> without any timeout?
>
> As blocking operations without timeouts should be avoided, should the code
> be changed to:
>
> socket = socketFactory.createSocket();
> socket.connect(new InetSocketAddress(host, port), timeout);
>
> or am I missing something?
>
> Thanks,
>
> Pascal
>
>



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: Usage of SocketFactory#createSocket(String host, int port)

Pascal Schumacher
Thanks for the feedback Claus and Andrea!

I did not find anything in the javadoc concerning default timeouts etc.

As SocketFactory is an abstract class, the behavior of
#createSocket(String host, int port) of course depends on the concrete
implementation in use, but at least the default implementation of Oracle
Java 8 Update 152 connects without using a timeout.

I created https://issues.apache.org/jira/browse/CAMEL-12358 and
https://github.com/apache/camel/pull/2258 for this.

Cheers,
Pascal

Am 16.03.2018 um 07:18 schrieb Claus Ibsen:

> Yeah that sounds reasonable, have you checked the javadoc of the jdk
> operations? But in all regards I do think your suggestion seems
> better. You are welcome to do a PR / commit / JIRA etc.
>
> On Tue, Mar 13, 2018 at 8:33 PM, Pascal Schumacher
> <[hidden email]> wrote:
>> Hello everybody,
>>
>> took a look at the camel-smpp source code and noticed that is using
>> javax.net.SocketFactory#createSocket(String host, int port) which "creates a
>> socket and connects it to the specified port number at the specified
>> address" according to the javadoc.
>>
>> As Socket#setSoTimeout is called later on and Socket#connect(SocketAddress
>> endpoint, int timeout) exists, I guess the initial connection is created
>> without any timeout?
>>
>> As blocking operations without timeouts should be avoided, should the code
>> be changed to:
>>
>> socket = socketFactory.createSocket();
>> socket.connect(new InetSocketAddress(host, port), timeout);
>>
>> or am I missing something?
>>
>> Thanks,
>>
>> Pascal
>>
>>
>
>