Using fgets on a network socket 
Author Message
 Using fgets on a network socket


wrote in comp.lang.c:

Quote:
> Hi folks,

> I would like to get some opinions on using fgets on a network socket.
> A friend of mine is calling fdopen on a socket and using that value
> in fgets to read lines of data.  I'm thinking this is not a good idea
> because fgets reads until it gets a \n, EOF, or the size passed to it.  So
> wouldn't this mean that until one of those conditions were met, fgets will
> block?  If for instance you call select on your socket, it says your socket
> is ready for reading, but a \n hasn't arrived yet fgets will block until it
> gets one.  Is this behavior typically OK?  Am I even correct in my thinking?

> Thanks,
> Scott

Sorry, wrong newsgroup.

The following are not defined or supported by the C language:

fdopen, socket, select

All use of networking is operating system specific, but consider this:

Assuming your compiler/OS combination actually allows you to open a
socket connection with fopen() and returns a FILE pointer, there is no
guarantee that the incoming data is text.  There is no requirement
that there ever be a '\n' in the stream.

Personally I think attempting to fgets() from a file connected to any
device which can produce binary data is a mistake, but a group
supporting your particular compiler or OS could tell you more.

Jack Klein
--
Home: http://www.*-*-*.com/



Thu, 16 May 2002 03:00:00 GMT  
 Using fgets on a network socket
Hi folks,

I would like to get some opinions on using fgets on a network socket.
A friend of mine is calling fdopen on a socket and using that value
in fgets to read lines of data.  I'm thinking this is not a good idea
because fgets reads until it gets a \n, EOF, or the size passed to it.  So
wouldn't this mean that until one of those conditions were met, fgets will
block?  If for instance you call select on your socket, it says your socket
is ready for reading, but a \n hasn't arrived yet fgets will block until it
gets one.  Is this behavior typically OK?  Am I even correct in my thinking?

Thanks,
Scott



Fri, 17 May 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. annoying fgets problem <fgets>

2. network sockets /linux

3. Windows Sockets Network Programming

4. socket programming problem (network not reachable)

5. socket programming problem (network not reachable)

6. Windows Sockets and PC's with 2 network cards

7. Windows Sockets and PC's with 2 network cards

8. NO Sockets Please!!(networking)

9. sample code for simple network socket programming

10. Sockets and network traffic

11. Sockets across dial in networking

12. network programming:COM,Socket,TCPIP?

 

 
Powered by phpBB® Forum Software