Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writev on windows

Does Windows offer anything similar to writev in a non Cygwin environment?

Ideally, an answer would have a working example for windows, something along the lines of:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/uio.h>

int main() {
  struct iovec iov[2];
  char blah[][20] = { "mickey", " mouse" };
  int fd = open ("/tmp/mice.txt", O_WRONLY | O_CREAT);
  iov[0].iov_base=blah[0];
  iov[1].iov_base=blah[1];
  iov[0].iov_len=iov[1].iov_len=6;
  writev(fd, iov, 2 );
  close(fd);
}

The answer should be how to approach the problem using system calls. Specifically I am looking to avoid copying the individual buffers into a single larger buffer to perform the write. Also the resultant write should be a single large write request instead of something like fwrite which performs buffered IO.


Edit: 13 August 12

The link to Scatter Gather I/O seems to pertain primarily to TCP/IP networking (err winsock really). Another suggestion, which is writefilegather is a solution for writing files in a very specific format. I.e. whereas writev writes using iov containers (arbitrary blocks of memory), writefilegather uses fixed buffers aligned to page table size.

like image 492
Clarus Avatar asked Oct 06 '22 23:10

Clarus


1 Answers

WSASend function can send an array of WSABUF structures

like image 192
xiaobing Avatar answered Oct 13 '22 10:10

xiaobing