LinuxQuestions.org
Review your favorite Linux distribution.
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, 01: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, 07:09 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
Please, specify explicitly the way you use fscanf.
 
Old 11-17-2005, 01: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, 01:38 PM   #4
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
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 03:14 AM
Problem with OpenSSL and sockets alitrix Programming 3 07-08-2005 01:45 PM
problem with sockets... jp-lack Slackware 2 07-06-2005 12:25 PM
Problem while creating two different sockets. myself_rajat Linux - Networking 2 05-26-2004 11:44 PM
Set/Unset Non-Blocking sockets? zer0python Programming 2 01-04-2004 02:31 AM


All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
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