MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / safe_write

Function safe_write

src/ae.cpp:200–227  ·  view source on GitHub ↗

Unlike write() this is an all or nothing thing. We will block if a partial write is hit

Source from the content-addressed store, hash-verified

198
199// Unlike write() this is an all or nothing thing. We will block if a partial write is hit
200ssize_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
229int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask,
230 aeFileProc *proc, void *clientData)

Callers 1

aeCreateRemoteFileEventFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected