Confilct between code and comment in mqtt3_socket_accept()

Asked by Yun Wu

#ifdef WITH_TLS
  /* TLS init */
  for(i=0; i<db->config->listener_count; i++){
   for(j=0; j<db->config->listeners[i].sock_count; j++){
    if(db->config->listeners[i].socks[j] == listensock){
     if(db->config->listeners[i].ssl_ctx){
      new_context->ssl = SSL_new(db->config->listeners[i].ssl_ctx);
      if(!new_context->ssl){
       mqtt3_context_cleanup(NULL, new_context, true);
       return -1;
      }
      SSL_set_ex_data(new_context->ssl, tls_ex_index_context, new_context);
      SSL_set_ex_data(new_context->ssl, tls_ex_index_listener, &db->config->listeners[i]);
      new_context->want_write = true; <---------------------------- 1)
      bio = BIO_new_socket(new_sock, BIO_NOCLOSE);
      SSL_set_bio(new_context->ssl, bio, bio);
      rc = SSL_accept(new_context->ssl);
      if(rc != 1){
       rc = SSL_get_error(new_context->ssl, rc);
       if(rc == SSL_ERROR_WANT_READ){
        /* We always want to read. */ <------------------------ 2)
       }else if(rc == SSL_ERROR_WANT_WRITE){
        new_context->want_write = true;
       }else{
        e = ERR_get_error();
        while(e){
         _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE,
           "Client connection from %s failed: %s.",
           new_context->address, ERR_error_string(e, ebuf));
         e = ERR_get_error();
        }
        mqtt3_context_cleanup(NULL, new_context, true);
        return -1;
       }
      }
     }
    }
   }
  }
#endif

Should 1) be changed to
 new_context->want_read = true
?

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

No, it is correct. We don't need to set a variable to indicate that we want to read, because we attempt to read always, no matter what.

The line 1 setting want_write to true is probably redundant though, given the later write to want_write.

Can you help with this problem?

Provide an answer of your own, or ask Yun Wu for more information if necessary.

To post a message you must log in.