Unlike write() this is an all or nothing thing. We will block if a partial write is hit
| 198 | |
| 199 | // Unlike write() this is an all or nothing thing. We will block if a partial write is hit |
| 200 | ssize_t safe_write(int fd, const void *pv, size_t cb) |
| 201 | { |
| 202 | const char *pcb = (const char*)pv; |
| 203 | ssize_t written = 0; |
| 204 | do |
| 205 | { |
| 206 | ssize_t rval = write(fd, pcb, cb); |
| 207 | if (rval > 0) |
| 208 | { |
| 209 | pcb += rval; |
| 210 | cb -= rval; |
| 211 | written += rval; |
| 212 | } |
| 213 | else if (errno == EAGAIN) |
| 214 | { |
| 215 | if (written == 0) |
| 216 | break; |
| 217 | // if we've already written something then we're committed so keep trying |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | if (rval == 0) |
| 222 | return written; |
| 223 | return rval; |
| 224 | } |
| 225 | } while (cb); |
| 226 | return written; |
| 227 | } |
| 228 | |
| 229 | int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask, |
| 230 | aeFileProc *proc, void *clientData) |
no outgoing calls
no test coverage detected