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); }
Advertisement
Answer
The problem is that connfd wasn’t initialized.