Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-25-2007, 10:39 AM
|
#1
|
|
Member
Registered: Oct 2003
Posts: 42
Rep:
|
Splice syscall does not work
Hello,
I'm trying to do a splice syscall from
tcp socket to a write side of a pipe
and getting BAD FILE DESCRIPTOR error...
Is it expected behaviour?
|
|
|
|
10-25-2007, 12:45 PM
|
#2
|
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
Can you show what code is causing this error? Please post code in [code] tags to preserve formatting ans aid readability.
Last edited by matthewg42; 12-15-2007 at 06:19 PM.
|
|
|
|
10-26-2007, 05:21 AM
|
#3
|
|
Member
Registered: Oct 2003
Posts: 42
Original Poster
Rep:
|
Ok, here is the code it is run with:
./tsplice 127.0.0.1:9000
Btw, where one can find the full doc for splice syscall?
Thanks
Code:
// tsplice.c - test splice syscall
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int
sa_pton(int af, const char *cp, struct sockaddr *sa)
{
sa->sa_family = af;
return inet_pton(af, cp, &((struct sockaddr_in *) sa)->sin_addr);
}
void
sa_set_port(struct sockaddr *sa, int port)
{
((struct sockaddr_in *) sa)->sin_port = htons(port);
}
int
sa_ptonp(int af, const char *cp, struct sockaddr *sa)
{
char *ports;
int r;
char *cp2 = alloca(strlen(cp) + 1);
strcpy(cp2, cp);
ports = strrchr(cp2, ':');
if (ports)
*ports = 0;
sa->sa_family = af;
r = inet_pton(af, cp2, &((struct sockaddr_in *) sa)->sin_addr);
if (r > 0)
sa_set_port(sa, atoi(ports+1));
return r;
}
void error(const char *m)
{
perror(m);
exit(1);
}
char data[] = "012345678";
#define DATASIZE (sizeof(data))
char rbuf[256];
main(int argc, char *argv[])
{
struct sockaddr sa;
struct sockaddr lsa;
int s1, s2, s3;
int pipes[2];
int r1, r2, r3;
loff_t o1 = 0, o2 = 0;
int alen = sizeof(lsa);
sa_ptonp(AF_INET, argv[1], &sa);
s1 = socket(AF_INET, SOCK_STREAM, 0);
if (s1 < 0)
error("socket");
r1 = bind(s1, &sa, sizeof(sa));
if (r1 < 0)
error("bind");
r1 = listen(s1, 1);
if (r1 < 0)
error("listen");
s2 = socket(AF_INET, SOCK_STREAM, 0);
if (s2 < 0)
error("second socket");
r1 = connect(s2, &sa, sizeof(sa));
if (r1 < 0)
error("connect");
s3 = accept(s1, &lsa, &alen);
if (s3 < 0)
error("connect");
pipe(pipes);
r1 = write(s2, data, DATASIZE);
r2 = splice(s3, &o1, pipes[1], &o2, DATASIZE, 0);
if (r2 < 0)
{
error("splice syscall");
}
printf("r1=%d, r2=%d\n", r1, r2);
r3 = read(pipes[0], rbuf, DATASIZE);
printf("r1=%d, r2=%d, r3=%d, data=%s\n", r1, r2, r3, rbuf);
}
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:44 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|