mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
+Web: added extended three-parameter version of Socket::Data::SetSockError to facilitate error handling in SSL sockets; fixed end-of-file detection in SSLSocketData::Read
git-svn-id: svn://ultimatepp.org/upp/trunk@3235 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
4e5a2b4742
commit
f7781f0fa0
3 changed files with 31 additions and 27 deletions
|
|
@ -373,7 +373,7 @@ void SSLSocketData::SetSSLError(const char *context)
|
|||
if(sock) {
|
||||
int code;
|
||||
String text = SSLGetLastError(code);
|
||||
sock->SetSockError(socket, context, code, text);
|
||||
SetSockError(context, code, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -382,25 +382,22 @@ void SSLSocketData::SetSSLResError(const char *context, int res)
|
|||
if(sock) {
|
||||
int code = SSL_get_error(ssl, res);
|
||||
String out;
|
||||
switch(code)
|
||||
{
|
||||
switch(code) {
|
||||
#define SSLERR(c) case c: out = #c; break;
|
||||
SSLERR(SSL_ERROR_NONE)
|
||||
SSLERR(SSL_ERROR_SSL)
|
||||
SSLERR(SSL_ERROR_WANT_READ)
|
||||
SSLERR(SSL_ERROR_WANT_WRITE)
|
||||
SSLERR(SSL_ERROR_WANT_X509_LOOKUP)
|
||||
SSLERR(SSL_ERROR_SYSCALL)
|
||||
SSLERR(SSL_ERROR_ZERO_RETURN)
|
||||
SSLERR(SSL_ERROR_WANT_CONNECT)
|
||||
SSLERR(SSL_ERROR_NONE)
|
||||
SSLERR(SSL_ERROR_SSL)
|
||||
SSLERR(SSL_ERROR_WANT_READ)
|
||||
SSLERR(SSL_ERROR_WANT_WRITE)
|
||||
SSLERR(SSL_ERROR_WANT_X509_LOOKUP)
|
||||
SSLERR(SSL_ERROR_SYSCALL)
|
||||
SSLERR(SSL_ERROR_ZERO_RETURN)
|
||||
SSLERR(SSL_ERROR_WANT_CONNECT)
|
||||
#ifdef PLATFORM_WIN32
|
||||
SSLERR(SSL_ERROR_WANT_ACCEPT)
|
||||
SSLERR(SSL_ERROR_WANT_ACCEPT)
|
||||
#endif
|
||||
default: out = "unknown code"; break;
|
||||
default: out = "unknown code"; break;
|
||||
}
|
||||
out << " (" << code << ")";
|
||||
if(sock)
|
||||
Socket::SetSockError(socket, context, code, out);
|
||||
SetSockError(context, code, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -415,16 +412,18 @@ int SSLSocketData::Read(void *buf, int amount)
|
|||
{
|
||||
ASSERT(ssl);
|
||||
int res = SSL_read(ssl, (char *)buf, amount);
|
||||
if(res == 0) {
|
||||
is_eof = true;
|
||||
if(SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN)
|
||||
return 0;
|
||||
}
|
||||
if(res <= 0)
|
||||
SetSSLResError("SSL_read", res);
|
||||
#ifndef NOFAKEERROR
|
||||
if(fake_error && res > 0)
|
||||
{
|
||||
if((fake_error -= res) <= 0)
|
||||
{
|
||||
if(fake_error && res > 0) {
|
||||
if((fake_error -= res) <= 0) {
|
||||
fake_error = 0;
|
||||
if(sock)
|
||||
sock->SetSockError(socket, "SSL_read", 1, "fake error");
|
||||
SetSockError("SSL_read", 0, "fake error");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -406,10 +406,14 @@ bool Socket::Data::Peek(int timeout_msec, bool write)
|
|||
return avail > 0;
|
||||
}
|
||||
|
||||
void Socket::Data::SetSockError(String context)
|
||||
void Socket::Data::SetSockError(const String& context)
|
||||
{
|
||||
int errorcode = Socket::GetErrorCode();
|
||||
SetSockError(context, errorcode, SocketErrorDesc(errorcode));
|
||||
}
|
||||
|
||||
void Socket::Data::SetSockError(const String& context, int errorcode, const String& errordesc)
|
||||
{
|
||||
int errorcode = Socket::GetErrorCode();
|
||||
String errordesc = SocketErrorDesc(Socket::GetErrorCode());
|
||||
if(sock)
|
||||
sock->SetSockError(socket, context, errorcode, errordesc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,9 +55,10 @@ public:
|
|||
protected:
|
||||
SOCKET AcceptRaw(dword *ipaddr, int timeout_msec);
|
||||
void Attach(SOCKET socket, bool nodelay, bool is_blocking);
|
||||
void SetSockResError(String context);
|
||||
void SetSockResError(const String& context);
|
||||
void AttachRaw(SOCKET s, bool blocking);
|
||||
void SetSockError(String context);
|
||||
void SetSockError(const String& context);
|
||||
void SetSockError(const String& context, int code, const String& errortext);
|
||||
|
||||
friend void AttachSocket(Socket& socket, SOCKET hsocket, bool blocking);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue