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;
    }
}
示例#2
0
文件: Pipe.cpp 项目: saeschdivara/x0
ssize_t Pipe::write(const void* buf, size_t size)
{
	ssize_t rv = ::write(writeFd(), buf, size);

	if (rv > 0)
		size_ += rv;

	return rv;
}
示例#3
0
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;
}
示例#4
0
文件: Pipe.cpp 项目: saeschdivara/x0
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;
}
示例#5
0
文件: Pipe.cpp 项目: saeschdivara/x0
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;
}
示例#6
0
文件: LibLog.c 项目: ZipLee/mylog
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);
}
示例#7
0
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);
}
示例#8
0
ssize_t Pipe::write(Pipe* pipe, size_t size)
{
	return splice(pipe->readFd(), NULL, writeFd(), NULL, 4096, SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
}
示例#9
0
ssize_t Pipe::write(const void* buf, size_t size)
{
	return ::write(writeFd(), buf, size);
}