Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process_write的switch判断是不是有点问题 #279

Open
YaoKong opened this issue May 16, 2024 · 2 comments
Open

process_write的switch判断是不是有点问题 #279

YaoKong opened this issue May 16, 2024 · 2 comments

Comments

@YaoKong
Copy link

YaoKong commented May 16, 2024

switch (ret)
    {
   //其他case略
    case FILE_REQUEST:
    {
        add_status_line(200, ok_200_title);
        if (m_file_stat.st_size != 0)
        {
            add_headers(m_file_stat.st_size);
            m_iv[0].iov_base = m_write_buf;
            m_iv[0].iov_len = m_write_idx;
            m_iv[1].iov_base = m_file_address;
            m_iv[1].iov_len = m_file_stat.st_size;
            m_iv_count = 2;
            bytes_to_send = m_write_idx + m_file_stat.st_size;
            return true;
        }
        else
        {
            const char *ok_string = "<html><body></body></html>";
            add_headers(strlen(ok_string));
            if (!add_content(ok_string))
                return false;
        }
    }
    default:
        return false;
    }

http_conn.cpp的第690行,也就是if (!add_content(ok_string))return false; 后面是不是少了个break,要不然当add_content()为真时会直接跳到default里去,正常来说应该break到循环外返回true

@diandengpao
Copy link

diandengpao commented Sep 14, 2024

经测试,是错的。 代码如下

#include<iostream>
using namespace std;

bool process_write() {
    int ret = 3;
	
    switch (ret){
        case 3:
    
            if (0)
                return true;
            else            
                if (0)
                    return false;
        
        default:
            cout << "default" << endl;
            return false;
    }
}

int main() {

    cout << process_write() << endl;

}

@vicky-beep
Copy link

我也觉得是少了个break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants