int TextBuffer::readFromFD(int fd) Issues a single read command on the file descriptor passed in. Attempts to read a minimum of 512 bytes from file descriptor passed.
| 202 | // descriptor passed in. Attempts to read a minimum of |
| 203 | // 512 bytes from file descriptor passed. |
| 204 | int |
| 205 | TextBuffer::readFromFD(int fd) |
| 206 | { |
| 207 | int readSize; |
| 208 | |
| 209 | // Check to see if we have got a reasonable amount of space left in our |
| 210 | // buffer, if not try to get some more |
| 211 | if (spaceLeft < 512) { |
| 212 | if (enlargeBuffer(512) == -1) { |
| 213 | return -1; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | readSize = read(fd, nextAdd, spaceLeft - 1); |
| 218 | |
| 219 | if (readSize == 0) { |
| 220 | // Socket is empty so we are done |
| 221 | return 0; |
| 222 | } else if (readSize < 0) { |
| 223 | // Error on read |
| 224 | return readSize; |
| 225 | } else { |
| 226 | nextAdd = nextAdd + readSize; |
| 227 | nextAdd[0] = '\0'; |
| 228 | spaceLeft -= readSize + 1; |
| 229 | return readSize; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void |
| 234 | TextBuffer::vformat(const char *fmt, va_list ap) |
no test coverage detected