You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2012/07/22 22:21:51 UTC

[MINA 3] NioTcpServer bind() potential issue

Hi,

while checking the Mina 3 code, I saw that the NioTcpServer bind() 
method might potentially leads to losing some events, if I'm not wrong.

The bind() method does this :

     public synchronized void bind(final SocketAddress localAddress) 
throws IOException {
         serverChannel = ServerSocketChannel.open(); <<---------- here, 
the channel is not ready to accept incoming requests
         ...
         serverChannel.socket().bind(address); <<---- !!! Now, the 
server can receive incoming connections
         serverChannel.configureBlocking(false);

         acceptProcessor = this.strategy.getSelectorForBindNewAddress();

         acceptProcessor.addServer(this); <<--- We then create the 
selector here

So we can open a serveur socket, but we are not ready yet to process the 
requests...Woudln't it make more sense to let the acceptProcessor do the 
bind ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: [MINA 3] NioTcpServer bind() potential issue

Posted by Julien Vermillard <jv...@gmail.com>.
On Mon, Jul 23, 2012 at 9:24 AM, Emmanuel Lécharny <el...@gmail.com> wrote:
> Le 7/23/12 9:08 AM, Julien Vermillard a écrit :
>
>> On Sun, Jul 22, 2012 at 10:21 PM, Emmanuel Lécharny <el...@gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> while checking the Mina 3 code, I saw that the NioTcpServer bind() method
>>> might potentially leads to losing some events, if I'm not wrong.
>>>
>>> The bind() method does this :
>>>
>>>      public synchronized void bind(final SocketAddress localAddress)
>>> throws
>>> IOException {
>>>          serverChannel = ServerSocketChannel.open(); <<---------- here,
>>> the
>>> channel is not ready to accept incoming requests
>>>          ...
>>>          serverChannel.socket().bind(address); <<---- !!! Now, the server
>>> can
>>> receive incoming connections
>>>          serverChannel.configureBlocking(false);
>>>
>>>          acceptProcessor = this.strategy.getSelectorForBindNewAddress();
>>>
>>>          acceptProcessor.addServer(this); <<--- We then create the
>>> selector
>>> here
>>>
>>> So we can open a serveur socket, but we are not ready yet to process the
>>> requests...Woudln't it make more sense to let the acceptProcessor do the
>>> bind ?
>>>
>> The accept event will be queued at the kernel level, and will be
>> processed by the first select,
>
>
> Is this guaranteed ?
>
For posix : http://linux.die.net/man/2/listen

For windows I suppose it's the same

Re: [MINA 3] NioTcpServer bind() potential issue

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 7/23/12 9:08 AM, Julien Vermillard a écrit :
> On Sun, Jul 22, 2012 at 10:21 PM, Emmanuel Lécharny <el...@gmail.com> wrote:
>> Hi,
>>
>> while checking the Mina 3 code, I saw that the NioTcpServer bind() method
>> might potentially leads to losing some events, if I'm not wrong.
>>
>> The bind() method does this :
>>
>>      public synchronized void bind(final SocketAddress localAddress) throws
>> IOException {
>>          serverChannel = ServerSocketChannel.open(); <<---------- here, the
>> channel is not ready to accept incoming requests
>>          ...
>>          serverChannel.socket().bind(address); <<---- !!! Now, the server can
>> receive incoming connections
>>          serverChannel.configureBlocking(false);
>>
>>          acceptProcessor = this.strategy.getSelectorForBindNewAddress();
>>
>>          acceptProcessor.addServer(this); <<--- We then create the selector
>> here
>>
>> So we can open a serveur socket, but we are not ready yet to process the
>> requests...Woudln't it make more sense to let the acceptProcessor do the
>> bind ?
>>
> The accept event will be queued at the kernel level, and will be
> processed by the first select,

Is this guaranteed ?


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: [MINA 3] NioTcpServer bind() potential issue

Posted by Julien Vermillard <jv...@gmail.com>.
On Sun, Jul 22, 2012 at 10:21 PM, Emmanuel Lécharny <el...@gmail.com> wrote:
> Hi,
>
> while checking the Mina 3 code, I saw that the NioTcpServer bind() method
> might potentially leads to losing some events, if I'm not wrong.
>
> The bind() method does this :
>
>     public synchronized void bind(final SocketAddress localAddress) throws
> IOException {
>         serverChannel = ServerSocketChannel.open(); <<---------- here, the
> channel is not ready to accept incoming requests
>         ...
>         serverChannel.socket().bind(address); <<---- !!! Now, the server can
> receive incoming connections
>         serverChannel.configureBlocking(false);
>
>         acceptProcessor = this.strategy.getSelectorForBindNewAddress();
>
>         acceptProcessor.addServer(this); <<--- We then create the selector
> here
>
> So we can open a serveur socket, but we are not ready yet to process the
> requests...Woudln't it make more sense to let the acceptProcessor do the
> bind ?
>

The accept event will be queued at the kernel level, and will be
processed by the first select,
Julien