data integrity problem during write pipe operation.
the kernel does not provide IO pipe API that force sends data completeness in once invocation.
We need to evaluate whether should go on do IO after once return
@@ -398,8 +398,27 @@ size_t
url_execute_fwrite(void *ptr, size_t size, URL_FILE *file, CopyState pstate)
{
URL_EXECUTE_FILE *efile = (URL_EXECUTE_FILE *) file;
+ int fd = efile->handle->pipes[EXEC_DATA_P];
+ size_t offset = 0;
+ const char* p = (const char* ) ptr;
- return pipewrite(efile->handle->pipes[EXEC_DATA_P], ptr, size);
+ size_t n;
+ /* ensure all data in buffer is send out to pipe*/
+ while(size > offset)
+ {
+ n = pipewrite(fd,p,size - offset);
+
+ if(n == -1) return -1;
+
+ if(n == 0) break;
+
+ offset += n;
+ p = (const char*)ptr + offset;
+ }
+
+ if(offset < size) elog(WARNING,"partial write, expected %lu, written %lu", size, offset);
+
+ return offset;
}
/*
