static void writeFdWait(int const fd, const unsigned char * const data, size_t const size) { /*---------------------------------------------------------------------------- Write the 'size' bytes at 'data' to the file image 'fd'. Wait as long as it takes for the file image to be able to take all the data. -----------------------------------------------------------------------------*/ size_t totalBytesWritten; // We do the first one blind because it will probably just work // and we don't want to waste the poll() call and buffer arithmetic. writeFd(fd, data, size, &totalBytesWritten); while (totalBytesWritten < size) { struct pollfd pollfds[1]; pollfds[0].fd = fd; pollfds[0].events = POLLOUT; poll(pollfds, ARRAY_SIZE(pollfds), -1); size_t bytesWritten; writeFd(fd, &data[totalBytesWritten], size - totalBytesWritten, &bytesWritten); totalBytesWritten += bytesWritten; } }
ssize_t Pipe::write(const void* buf, size_t size) { ssize_t rv = ::write(writeFd(), buf, size); if (rv > 0) size_ += rv; return rv; }
ssize_t writeFile(const char *path, const char *content) { int fd = open(path, O_RDWR | O_CREAT); ssize_t result; if (fd >= 0) { result = writeFd(fd, content); close(fd); } else { result = -1; } return result; }
ssize_t Pipe::write(int fd, off_t* fd_off, size_t size) { ssize_t rv = 0; #ifdef __APPLE__ assert(__APPLE__); #else rv = splice(fd, fd_off, writeFd(), NULL, size, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); #endif if (rv > 0) size_ += rv; return rv; }
ssize_t Pipe::write(Pipe* pipe, size_t size) { ssize_t rv = 0; #ifdef __APPLE__ assert(__APPLE__); #else rv = splice(pipe->readFd(), NULL, writeFd(), NULL, pipe->size_, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); #endif if (rv > 0) { pipe->size_ -= rv; size_ += rv; } return rv; }
int vswrite(LOG_OPT* pLogOpt, const char* fmt, va_list vl) { int ret = -1; char buffer[MAX_SINGLE_MSG_LEN] = {0}; if (NULL == fmt || strlen(fmt) <= 0){ return 0; } ret = vsnprintf(buffer, MAX_SINGLE_MSG_LEN, fmt, vl); if (ret < 0){ pLogOpt->err_code = LOG_ERR_STREAM_FAIL; return ret; } return writeFd(pLogOpt, buffer); }
ssize_t Pipe::write(int fd, off_t* fd_off, size_t size) { return splice(fd, fd_off, writeFd(), NULL, size, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); }
ssize_t Pipe::write(Pipe* pipe, size_t size) { return splice(pipe->readFd(), NULL, writeFd(), NULL, 4096, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); }
ssize_t Pipe::write(const void* buf, size_t size) { return ::write(writeFd(), buf, size); }