@@ -118,25 +118,23 @@ IO_ERR Socket::read(char* buffer, size_t length, size_t& actualLength, bool msgP
118
118
// RecordTime record("Socket.read");
119
119
if (!enableSSL_) {
120
120
#ifdef _WIN32
121
- actualLength = recv (handle_, buffer, static_cast < int >(length), msgPeek ? MSG_PEEK : 0 ) ;
122
- RECORD_READ ( buffer, actualLength );
123
- if (actualLength < 0 ) {
121
+ actualLength = 0 ;
122
+ int ret = recv (handle_, buffer, static_cast < int >(length), msgPeek ? MSG_PEEK : 0 );
123
+ if (ret == SOCKET_ERROR ) {
124
124
DLogger::Error (" socket read error" , actualLength);
125
- }
126
- if (actualLength == 0 )
127
- return DISCONNECTED;
128
- else if (actualLength != (size_t )SOCKET_ERROR)
129
- return OK;
130
- else {
131
- actualLength = 0 ;
132
125
int error = WSAGetLastError ();
133
126
if (error == WSAENOTCONN || error == WSAESHUTDOWN || error == WSAENETRESET)
134
127
return DISCONNECTED;
135
- else if (error == WSAEWOULDBLOCK)
128
+ if (error == WSAEWOULDBLOCK)
136
129
return NODATA;
137
- else
138
- return OTHERERR;
130
+ return OTHERERR;
139
131
}
132
+ if (ret == 0 ) {
133
+ return DISCONNECTED;
134
+ }
135
+ actualLength = ret;
136
+ RECORD_READ (buffer, ret);
137
+ return OK;
140
138
#else // Linux
141
139
readdata:
142
140
actualLength = recv (handle_, (void *)buffer, length, (blocking_ ? 0 : MSG_DONTWAIT) | (msgPeek ? MSG_PEEK : 0 ));
@@ -156,20 +154,20 @@ IO_ERR Socket::read(char* buffer, size_t length, size_t& actualLength, bool msgP
156
154
} else {
157
155
#ifdef USE_OPENSSL
158
156
readdata2:
159
- int ret = SSL_read (ssl_, buffer, static_cast <int >(length));
157
+ int ret = SSL_read ((SSL*) ssl_, buffer, static_cast <int >(length));
160
158
if (ret > 0 ) {
161
159
actualLength = ret;
162
160
RECORD_READ (buffer, ret);
163
161
} else {
164
162
DLogger::Error (" socket read error" , ret);
165
- ret = SSL_get_error (ssl_, ret);
163
+ ret = SSL_get_error ((SSL*) ssl_, ret);
166
164
if (ret == SSL_ERROR_WANT_READ) goto readdata2;
167
165
LOG_ERR (" Socket(SSL)::read err =" + std::to_string (ret));
168
166
return OTHERERR;
169
167
}
170
168
#endif
171
- return OK;
172
169
}
170
+ return OK;
173
171
}
174
172
175
173
IO_ERR Socket::write (const char * buffer, size_t length, size_t & actualLength){
@@ -218,12 +216,12 @@ IO_ERR Socket::write(const char* buffer, size_t length, size_t& actualLength){
218
216
else {
219
217
#ifdef USE_OPENSSL
220
218
senddata2:
221
- int ret = SSL_write (ssl_, (const void *)buffer, static_cast <int >(length));
219
+ int ret = SSL_write ((SSL*) ssl_, (const void *)buffer, static_cast <int >(length));
222
220
if (ret > 0 ) {
223
221
actualLength = ret;
224
222
RECORD_WRITE (buffer, ret);
225
223
} else {
226
- int err = SSL_get_error (ssl_, ret);
224
+ int err = SSL_get_error ((SSL*) ssl_, ret);
227
225
if (err == SSL_ERROR_WANT_WRITE) goto senddata2;
228
226
DLogger::Error (" socket write error" , err);
229
227
LOG_ERR (" Socket(SSL)::write err =" + std::to_string (err));
@@ -387,10 +385,10 @@ IO_ERR Socket::close(){
387
385
#ifdef USE_OPENSSL
388
386
if (ssl_ != nullptr ) {
389
387
// shutdown until it done.
390
- while (SSL_shutdown (ssl_) == 0 ) {
388
+ while (SSL_shutdown ((SSL*) ssl_) == 0 ) {
391
389
Util::sleep (10 );
392
390
}
393
- SSL_free (ssl_);
391
+ SSL_free ((SSL*) ssl_);
394
392
ssl_ = nullptr ;
395
393
}
396
394
#endif
@@ -407,7 +405,7 @@ IO_ERR Socket::close(){
407
405
}
408
406
#ifdef USE_OPENSSL
409
407
if (ctx_ != nullptr ) {
410
- SSL_CTX_free (ctx_);
408
+ SSL_CTX_free ((SSL_CTX*) ctx_);
411
409
ctx_ = nullptr ;
412
410
}
413
411
#endif
@@ -552,7 +550,7 @@ int Socket::getErrorCode(){
552
550
}
553
551
554
552
#ifdef USE_OPENSSL
555
- SSL_CTX * Socket::initCTX (){
553
+ void * Socket::initCTX (){
556
554
const SSL_METHOD* method;
557
555
SSL_CTX* ctx;
558
556
@@ -576,11 +574,11 @@ bool Socket::sslInit() {
576
574
if (ctx_ == nullptr ) {
577
575
return false ;
578
576
}
579
- ssl_ = SSL_new (ctx_);
577
+ ssl_ = SSL_new ((SSL_CTX*) ctx_);
580
578
if (ssl_ == nullptr ) {
581
579
return false ;
582
580
}
583
- SSL_set_fd (ssl_, static_cast <int >(handle_));
581
+ SSL_set_fd ((SSL*) ssl_, static_cast <int >(handle_));
584
582
return true ;
585
583
}
586
584
@@ -589,7 +587,7 @@ IO_ERR Socket::sslConnect() {
589
587
if (!sslInit ()) {
590
588
return OTHERERR;
591
589
}
592
- if (SSL_connect (ssl_) == -1 ) {
590
+ if (SSL_connect ((SSL*) ssl_) == -1 ) {
593
591
if (!blocking_) {
594
592
// TODO: solve error
595
593
}
@@ -599,10 +597,10 @@ IO_ERR Socket::sslConnect() {
599
597
return OK;
600
598
}
601
599
602
- void Socket::showCerts (SSL *ssl) {
600
+ void Socket::showCerts (void *ssl) {
603
601
X509 *cert;
604
602
char *line;
605
- cert = SSL_get_peer_certificate (ssl); /* get the server's certificate */
603
+ cert = SSL_get_peer_certificate ((SSL*) ssl); /* get the server's certificate */
606
604
if ( cert != NULL ){
607
605
std::cout << " Server certificates:\n " ;
608
606
line = X509_NAME_oneline (X509_get_subject_name (cert), 0 , 0 );
0 commit comments