daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

Socket may stay in bound state without exposing this information #51

Closed dumblob closed 9 years ago

dumblob commented 9 years ago

It seems, that if the socket was properly bound, but listen() failed, the socket will remain bound until it's shutdown/closed. This might be inconvenient for other processes/threads as the programmer will see a socket, but the raised error would be about listen() and the information, that the socket is actually properly bound is not accessible.

...
if( DaoSocket_Bind( self, Proto_TCP, ip, port, par[2]->xEnum.value ) == -1 || DaoNetwork_Listen( self->id, backlog ) == -1 ){
GetErrorMessage( errbuf, GetError() );
DaoProcess_RaiseError( proc, neterr, errbuf );
}
...
Night-walker commented 9 years ago

Its state will be $bound, albeit that is irrelevant for the current TcpListener implementation.

dumblob commented 9 years ago

Ok, if the state is $bound, then there is no issue. But why would it be irrelevant for the current implementation?

Night-walker commented 9 years ago

Because bound&listen always come in pair in order to avoid unnecessary intermediate states.

dumblob commented 9 years ago

Sure, that's how I understood it and I welcome this solution. But in this case I'm pretty sure, that after catching the exception, the socket is in bound state, but this information is not visible/available and thus e.g. calling DaoNetLib_Listen() again will call bind() again which might cause issues.

Night-walker commented 9 years ago

calling DaoNetLib_Listen() again will call bind() again which might cause issues.

It will close the socket first.

dumblob commented 9 years ago

Oh, now I see - DaoSocket_Delete() does it.