简体   繁体   中英

Read system call taking forever on Linux

I'm writing a TCP server application in c++.

I'm trying to read a line one char at a time from a socket, but the read() system call never returns.

string buffered_reader::read_line() {
    string str;
    int i = 0;
    char ch;

    do {
        int len = conn.read_from_conn((void*)&ch, 1);
        if (len == -1)
            throw string("Error reading from connection!");

        str += ch;
    } while (ch != '\n');

    return str;
}

And here is the read_from_conn() function

int connectionplusplus::read_from_conn(void *buffer, int buffer_len) {
   return read(this->connfd, buffer, buffer_len);
}

问题是connfd尚未初始化。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM