From: Todd O. <to...@us...> - 2006-05-14 23:41:04
|
Update of /cvsroot/yassl/yassl/src In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28867/src Modified Files: handshake.cpp socket_wrapper.cpp yassl_error.cpp Log Message: make non-blocking data transfer match OpenSSL error codes Index: socket_wrapper.cpp =================================================================== RCS file: /cvsroot/yassl/yassl/src/socket_wrapper.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** socket_wrapper.cpp 11 Apr 2006 20:34:30 -0000 1.2 --- socket_wrapper.cpp 14 May 2006 23:40:59 -0000 1.3 *************** *** 59,63 **** Socket::Socket(socket_t s) ! : socket_(s) {} --- 59,63 ---- Socket::Socket(socket_t s) ! : socket_(s), wouldBlock_(false) {} *************** *** 124,130 **** ! uint Socket::receive(byte* buf, unsigned int sz, int flags) const { assert(socket_ != INVALID_SOCKET); int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags); --- 124,132 ---- ! uint Socket::receive(byte* buf, unsigned int sz, int flags) { assert(socket_ != INVALID_SOCKET); + wouldBlock_ = false; + int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags); *************** *** 132,137 **** if (recvd == -1) { if (get_lastError() == SOCKET_EWOULDBLOCK || ! get_lastError() == SOCKET_EAGAIN) return 0; } else if (recvd == 0) --- 134,141 ---- if (recvd == -1) { if (get_lastError() == SOCKET_EWOULDBLOCK || ! get_lastError() == SOCKET_EAGAIN) { ! wouldBlock_ = true; return 0; + } } else if (recvd == 0) *************** *** 143,147 **** // wait if blocking for input, return false for error ! bool Socket::wait() const { byte b; --- 147,151 ---- // wait if blocking for input, return false for error ! bool Socket::wait() { byte b; *************** *** 167,170 **** --- 171,180 ---- + bool Socket::WouldBlock() const + { + return wouldBlock_; + } + + void Socket::set_lastError(int errorCode) { Index: yassl_error.cpp =================================================================== RCS file: /cvsroot/yassl/yassl/src/yassl_error.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** yassl_error.cpp 28 Mar 2006 23:56:41 -0000 1.1.1.1 --- yassl_error.cpp 14 May 2006 23:40:59 -0000 1.2 *************** *** 27,30 **** --- 27,31 ---- #include "yassl_error.hpp" #include "error.hpp" // TaoCrypt error numbers + #include "openssl/ssl.h" // SSL_ERROR_WANT_READ namespace yaSSL { *************** *** 116,120 **** case certificate_error : strncpy(buffer, "unable to proccess cerificate", max); ! break; // TaoCrypt errors --- 117,126 ---- case certificate_error : strncpy(buffer, "unable to proccess cerificate", max); ! break; ! ! // openssl errors ! case SSL_ERROR_WANT_READ : ! strncpy(buffer, "the read operation would block", max); ! break; // TaoCrypt errors Index: handshake.cpp =================================================================== RCS file: /cvsroot/yassl/yassl/src/handshake.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** handshake.cpp 11 Apr 2006 20:34:30 -0000 1.2 --- handshake.cpp 14 May 2006 23:40:59 -0000 1.3 *************** *** 657,661 **** { // wait for input if blocking ! if (!ssl.getSocket().wait()) { ssl.SetError(receive_error); buffered.reset(0); --- 657,661 ---- { // wait for input if blocking ! if (!ssl.useSocket().wait()) { ssl.SetError(receive_error); buffered.reset(0); *************** *** 674,678 **** // add new data ! uint read = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready); buffer.add_size(read); uint offset = 0; --- 674,678 ---- // add new data ! uint read = ssl.useSocket().receive(buffer.get_buffer() + buffSz, ready); buffer.add_size(read); uint offset = 0; *************** *** 894,897 **** --- 894,900 ---- int receiveData(SSL& ssl, Data& data) { + if (ssl.GetError() == SSL_ERROR_WANT_READ) + ssl.SetError(no_error); + ssl.verfiyHandShakeComplete(); if (ssl.GetError()) return 0; *************** *** 903,906 **** --- 906,914 ---- if (ssl.GetError()) return 0; + + if (data.get_length() == 0 && ssl.getSocket().WouldBlock()) { + ssl.SetError(YasslError(SSL_ERROR_WANT_READ)); + return SSL_WOULD_BLOCK; + } return data.get_length(); } |