64,654
社区成员
发帖
与我相关
我的任务
分享
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_disconnect(struct soap *soap)
{
#ifdef WITH_OPENSSL
if (soap->ssl)
{ int r, s = 0;
if (soap->session)
{ SSL_SESSION_free(soap->session);
soap->session = NULL;
}
if (*soap->host)
{ soap->session = SSL_get1_session(soap->ssl);
if (soap->session)
{ strcpy(soap->session_host, soap->host);
soap->session_port = soap->port;
}
}
r = SSL_shutdown(soap->ssl);
/* SSL shutdown does not work when reads are pending */
while (SSL_want_read(soap->ssl))
{ SSL_read(soap->ssl, NULL, 0);
if (soap_socket_errno(soap->socket) != SOAP_EAGAIN)
{ r = SSL_shutdown(soap->ssl);
break;
}
}
if (r == 0)
{ if (soap_valid_socket(soap->socket))
{ if (!soap->fshutdownsocket(soap, soap->socket, 1))
{ /*
wait up to 10 seconds for close_notify to be sent by peer (if peer not
present, this avoids calling SSL_shutdown() which has a lengthy return
timeout)
*/
//这一句它等了10s? 这是为什么呢?
r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, 10);
if (r <= 0 && soap->errnum != SOAP_EINTR)
{ soap->errnum = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connection lost...\n"));
soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
ERR_remove_state(0);
return SOAP_OK;
}
}
}
}
if (r != 1)
{ s = ERR_get_error();
if (s)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r)));
if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP))
{ soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
}
}
}
SSL_free(soap->ssl);
soap->ssl = NULL;
if (s)
return SOAP_SSL_ERROR;
ERR_remove_state(0);
}
#endif
if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP))
{ soap->fshutdownsocket(soap, soap->socket, 2);
soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_closesocket(struct soap *soap, SOAP_SOCKET fd)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd));
return soap_closesocket(fd);
}
#endif
#endif