qrexec-utils: add read_vchan_all and write_vchan_all

Similar to read_all and write_all.
This commit is contained in:
Marek Marczykowski-Górecki 2013-12-27 05:53:19 +01:00
parent 591fb10a32
commit 020f341f98
2 changed files with 28 additions and 0 deletions

View File

@ -42,6 +42,8 @@ void *buffer_data(struct buffer *b);
void do_fork_exec(const char *cmdline, int *pid, int *stdin_fd, int *stdout_fd,
int *stderr_fd);
void wait_for_vchan_or_argfd(libvchan_t *vchan, int max, fd_set * rdset, fd_set * wrset);
int read_vchan_all(libvchan_t *vchan, void *data, size_t size);
int write_vchan_all(libvchan_t *vchan, void *data, size_t size);
int read_all(int fd, void *buf, int size);
int write_all(int fd, const void *buf, int size);
void fix_fds(int fdin, int fdout, int fderr);

View File

@ -74,3 +74,29 @@ void wait_for_vchan_or_argfd(libvchan_t *ctrl, int max, fd_set * rdset, fd_set *
}
while (wait_for_vchan_or_argfd_once(ctrl, max, rdset, wrset) == 0);
}
int write_vchan_all(libvchan_t *vchan, void *data, size_t size) {
int pos, ret;
pos = 0;
while (pos < size) {
ret = libvchan_write(vchan, data+pos, size-pos);
if (ret < 0)
return 0;
pos += ret;
}
return 1;
}
int read_vchan_all(libvchan_t *vchan, void *data, size_t size) {
int pos, ret;
pos = 0;
while (pos < size) {
ret = libvchan_read(vchan, data+pos, size-pos);
if (ret < 0)
return 0;
pos += ret;
}
return 1;
}