LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 11-17-2005, 12:23 AM   #1
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Problem w/ sockets, fdopen, and blocking.


I am having a silly problem w/ sockets and fscanf right now. I'm writing a server which uses pthreads for its concurrency. When it gets a client it creates a new pthread to handle it. I then use fdopen to open the file descriptor returned from accept as a FILE. I then use setvbuf(fd, NULL, _IONBF, 0) to turn off buffering. When I run fscanf w/ %s I expect it to immediately return whenever something is sent, regardless if it has a new line or if the buffer is full or not. However, it just blocks until it gets a new line. read works fine, but I would prefer fscanf. Why is setvbuf not working?
 
Old 11-17-2005, 06:09 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 657

Rep: Reputation: 66
Please, specify explicitly the way you use fscanf.
 
Old 11-17-2005, 12:11 PM   #3
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Original Poster
Rep: Reputation: 32
k (sfd is the socket's file descriptor).

FILE *f = fdopen(sfd,"r");
setvbuf(f, NULL, _IONBF, 0);
while(fscanf(f,"%s",buf) > 0) {
/* blah */
}
 
Old 11-17-2005, 12:38 PM   #4
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 657

Rep: Reputation: 66
OK, I understand now what do you want. I remember I have avoid buffer
successfully using functions listed on termios(3) manpage. They works with
int file descriptors.
I do not know why setvbuf does not work but I myself disabled the buffer of
the stdin using tcsetattr. Try it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non blocking sockets in Perl ivanatora Programming 3 08-19-2005 02:14 AM
Problem with OpenSSL and sockets alitrix Programming 3 07-08-2005 12:45 PM
problem with sockets... jp-lack Slackware 2 07-06-2005 11:25 AM
Problem while creating two different sockets. myself_rajat Linux - Networking 2 05-26-2004 10:44 PM
Set/Unset Non-Blocking sockets? zer0python Programming 2 01-04-2004 01:31 AM


All times are GMT -5. The time now is 09:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration