The Samba-Bugzilla – Attachment 2393 Details for
Bug 4527
sendfile(2) fails improperly on CIFS mounts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Trivial sendfile(2) program
sendfile.c (text/plain), 1.60 KB, created by
Dan Merillat
on 2007-04-19 21:09:24 UTC
(
hide
)
Description:
Trivial sendfile(2) program
Filename:
MIME Type:
Creator:
Dan Merillat
Created:
2007-04-19 21:09:24 UTC
Size:
1.60 KB
patch
obsolete
>#include <sys/sendfile.h> >#include <sys/types.h> >#include <sys/stat.h> >#include <sys/poll.h> >#include <sys/socket.h> >#include <fcntl.h> >#include <unistd.h> >#include <stdlib.h> >#include <errno.h> >#include <stdio.h> >#include <string.h> > >int transmit(int ifd, int ofd) { > struct stat sbuf; > off_t offset=0; > int res; > > > fstat(ifd, &sbuf); > printf("Transmitting testfile - size %d\n", sbuf.st_size); > res=sendfile(ofd, ifd, &offset, sbuf.st_size); > if (res>0) > printf("Transmitted %d bytes - offset %d\n", res, offset); > else { > printf("sendfile() = %d %s (@%d)\n", res, strerror(errno), offset); > fflush(stdout); > } > fflush(stdout); > > > close(ifd); >} > >int receive(int ifd) { > struct pollfd pfd[1]; > int rdsize; > int rdtotal=0; > char *rbuf=0; > > rbuf=malloc(64 * 1024); // 64k reads. > > pfd[0].fd=ifd; > pfd[0].events=POLLIN; > > while(1) { > poll(pfd, 1, -1); > if (pfd->revents & POLLIN) { > while(1) { > rdsize=read(ifd, rbuf, 64*1024); > if (rdsize <= 0) > break; > rdtotal+=rdsize; > } > if (0==rdsize) > break; > } > } > printf("Read %d bytes.\n", rdtotal); > free(rbuf); >} > > >int main(int argc, char ** argv) { > > int child_pid; > int ret; > > int ifd; > > int sv[2]; > > ret=socketpair(AF_UNIX, SOCK_STREAM, 0, sv); > > if (argc>1) { > ifd=open(argv[1], O_RDONLY, 0); > if (ifd<0) { > printf("File not found: %s\n", argv[1]); > exit(1); > } > } else { > printf("usage: %s <filename>\n", argv[0]); > exit(0); > } > > if ((child_pid = fork()) == -1) > perror("forking"); > else if (child_pid==0) { > close(sv[0]); > receive(sv[1]); > exit(0); > } > > > > close(sv[1]); > transmit(ifd, sv[0]); > close(sv[0]); > waitpid(child_pid, 0, 0); > > exit(0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 4527
: 2393