gSOAP does **not** close sockets?
I've an issue with gSoap - it's not closing the socket.. Here's the situation: the application is working fine, but when I call "reload" function, it cann开发者_C百科ot reconnect.. Here's a piece of code:
soap_destroy( &m_soapObj );
soap_end( &m_soapObj );
soap_done(&m_soapObj);
sleep(1);
soap_init(&m_soapObj);
//m_ptrThis should be initialized already
assert( m_ptrThis != NULL );
m_soapObj.user = &m_ptrThis;
m_soapObj.accept_timeout = nAcceptTimeout;
m_ptrThreadPool->SetNumThreads( nNumThreads );
m_nSocketListener = soap_bind(&m_soapObj, NULL, nPort, nBacklog);
if (!soap_valid_socket(m_nSocketListener))
{
throw Exception(
"Cannot start listening on port: %d", nPort );
}
and it throws.. When I try to use soap_free, the program crashes, as I don't create new Soap object, just initialize it again. SO, soap_done should work. And the interesting thing is, that this does not happen every time.
It's very strange.. and urgent :/
Thanks a lot in advance
EDIT The problem is solved. Many thanks to Duck!
You should find out exactly what error is being thrown.
It is possible you are getting an "Address Already in Use" error from bind(). You can try to correct for this by using setsockopt() - or the equivalent soap call - with the SO_REUSEADDR option.
This link provides a concise explanation.
精彩评论