Results 1 to 2 of 2
Hello, any network programming gurus out there?
I am trying to make a service to receive a url over the network (then download the torrent file, and load it into ...
- 06-19-2007 #1Linux Newbie
- Join Date
- Nov 2006
- Posts
- 123
writing xinetd service
Hello, any network programming gurus out there?
I am trying to make a service to receive a url over the network (then download the torrent file, and load it into my torrent program, but basics first....) Since I read up on the net that if I configure it as an xinetd service, then it can just use stdin and stdout for communicating over the socket.
I did this, however I am having trouble getting it to work.
The code thus far is as such:
i.e. I am using getline to read data from stdin - this should read data from the socket, right?Code:#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char *argv[]) { FILE* logfile = fopen("/home/torrent/loadfile.log", "w"); fputs("starting\n", logfile); char* url = NULL; size_t linesize = 0; ssize_t urllen = getline(&url, &linesize, stdin); fputs("got url\n", logfile); if(urllen <= 0) {printf("no file specified\n");return 1;} printf("thanks!"); return 0; }
Basically this is a "client sends data first" type affair.
HOWEVER - it doesn't appear to even be completing the second line - i.e. when I look at /home/torrent/loadfile.log it has been created (so therefore the call to fopen must have worked) - however it is empty, zero bytes - so therefore even the first fputs didn't work.
I thought it would be a permissions issue, but I have got the service running as root, as can be seen from my configuration in /etc/xinetd.d/loadfile:
I commented out the 'internal' line as it didn't work with that - xinetd puts some message about it not recognizing the service into syslog if I have the internal flag on. I also find it only works to list it in /etc/services.Code:service loadfile { disable = no id = loadfile # type = INTERNAL wait = no socket_type = stream user = root group = root server = /usr/sbin/loadfile server_args = port = 12345 }
Any idea what could be the problem?
I don't understand why it's opening the log file but isn't even getting as far as writing to it - so I am stumped as to how to debug this now.
any help much appreciated.
- 06-11-2008 #2Just Joined!
- Join Date
- Jun 2008
- Location
- montreal
- Posts
- 1
log file is empty.
fopen uses buffered IO and you are not calling fclose. Using setvbuf with a type of _IOLBF sould send each line into the file...


Reply With Quote