Results 1 to 1 of 1
Hi,
I have been trying to use sendfile system call for transferring data for a udp connection.
This option was available only for tcp initially but in the documentation of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-04-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 1
sendfile usage for udp
Hi,
I have been trying to use sendfile system call for transferring data for a udp connection.
This option was available only for tcp initially but in the documentation of udp.c in the kernel it is given as a comment that "sendfile() on UDP works now."
My code snippet looks like this(at the server/transmitter):
/* open the file to be sent */
fd = open(bufin, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "unable to open '%s': %s\n", bufin, strerror(errno));
exit(1);
}
fstat(fd, &stat_buf);
iov.iov_base = (caddr_t)fd;
iov.iov_len = stat_buf.st_size;
//remote is defined struct sockaddr_in remote; for remote/client address
apl_header.msg_name = (caddr_t) &remote;
apl_header.msg_namelen = sizeof(remote);
apl_header.msg_iov = &iov;
apl_header.msg_iovlen = 1;
printf("before sendfile\n");
if(setsockopt(sd,IPPROTO_UDP, UDP_CORK,&yes,sizeof(int)) == -1)
{
fprintf(stderr, "error from setsockopt: %s\n", strerror(errno));
exit(1);
}
if(sendmsg(sd, &apl_header, sizeof(apl_header)) == -1)
{
fprintf(stderr, "error from sendmsg: %s\n", strerror(errno));
exit(1);
}
offset = sendfile(sd,fd,&offset,stat_buf.st_size);
if (offset == -1)
{
fprintf(stderr, "error from sendfile: %s\n", strerror(errno));
exit(1);
}
setsockopt(sd,IPPROTO_UDP, UDP_CORK,&no,sizeof(int));
I get the error that "error from sendfile: Destination address required"
If someone has worked on a similar issue before then it would be great help if any tips or hints are provided.
Also is there a way i can debug the system call itself. Pointers to this will be of help
Thanks,
Suhas


Reply With Quote
