OpenSSL 연결에서 블로킹 소켓을 사용하고 있습니다. SSL_read는 때때로 몇 초 동안 차단됩니다. 서버에서 - BIO_write는 가변 버퍼 크기로 데이터를 전송하는 데 사용됩니다. 클라이언트 - 먼저 버퍼 크기를 얻는 SSL_read가 성공하지만 데이터가 성공적으로 전송 되었더라도 SSL_read를 따라 몇 초 동안 버퍼 데이터 블록을 가져옵니다 (이 문제는 2 ~ 3 분 후 시뮬레이션 됨). 나는 클라이언트 읽기 기능을 호출하기 위해 poll()을 기다린다. 블로킹 소켓에서 이러한 문제를 해결하는 방법은 무엇입니까?OpenSSL 차단 소켓 SSL_read 블록
서버 코드
void process_and_send() {
// sending variable size buffer each time
// sbuf - first 4 bytes contains sbuf size information
send_data(sbuf, sbufSize);
}
void send_data(void *sbuf, int pending_len) {
while(pending_len > 0) {
result = BIO_write(bio, sbuf, pending_len);
if(result == 0) {
attempts = 0;
LOG_D("%s", log_str(SSL_CONN_CLOSE));
SSL_FN_TRACE("connection closed\n");
break;
}
else if(result < 0) {
LOG_I("%s", log_str(SSL_WRITE_FAIL));
SSL_FN_TRACE("BIO_write fail\n");
if(errno == EINTR) {
continue;
}
if(errno == EAGAIN) {
attempts++;
continue;
}
if(errno == EWOULDBLOCK) {
attempts++;
continue;
}
break;
}
else {
BIO_flush(bio);
pending_len -= result;
sbuf += result;
}
}
}
클라이언트 코드
// wait on poll() and call receive_and_process
void receive_and_process() {
int rbufSize = 0;
// get the size of data to read
receive_data((void *)&rbufSize, sizeof(Int));
// this call blocks for few seconds
receive_data(rbuf, rbufSize);
}
void receive_data(void *rbuf, int pending_len) {
while(pending_len > 0) {
result = SSL_read(ssl, rbuf, pending_len);
if(result == 0) {
LOG_D("%s", log_str(SSL_CONN_CLOSE));
SSL_FN_TRACE("connection closed\n");
return NULL;
}
else if(result < 0) {
if(errno == ETIMEDOUT) {
SSL_FN_ERROR("SSL read timeout: \n");
continue;
}
if(errno == EINTR) {
continue;
}
if(errno == EAGAIN) {
continue;
}
if(errno == EWOULDBLOCK) {
continue;
}
SSL_FN_ERROR("SSL read fail error no: %s\n",
ERR_reason_error_string(ERR_get_error()));
LOG_I("%s", log_str(SSL_READ_FAIL));
return NULL;
}
pending_len -= result;
rbuf += result;
FN_ERROR("after read full data pending len %d\n", pending_len);
}
}
. 블로킹 소켓 블록을 통한 I/O. 너의 질문? – EJP
왜 차단합니까? 데이터가 성공적으로 전송 되었더라도 고마워요. 레미. –