tcp/ip program ( using sockets )

tcp/ip program ( using sockets )

Post by N621497 » Mon, 23 Feb 1998 04:00:00



In a program I just finished I am using strtok to extract TCP messages
one at a time ( with a DELimeter character set to ASCII 10 line feed )..
 If you call strtok the first time with a NULL argument
i.e like this strtok ( NULL, (char *) &DEL );
then it returns NULL which suits me fine.... but I'm just curious if
this is the defined behaviour....d

 More importantly, in a program that does read()s ( over a TCP
connection ) and which also uses signals I am using code which looks
like
 while ( read(...) == -1 )
 { if ( errno != EINTR ) { /* unrecovable error */ }
    /* just a signal... try again */
 }

 ( the read call is blocking )
 This doesn't work if read() is interrupted while reading .. it will
simply return with the number of bytes it managed to read... What are
the solutions to this rather fundemental problem?
/alex

p.s What is the cause of an IOT / Abort signal?

 
 
 

tcp/ip program ( using sockets )

Post by Rob Rya » Mon, 23 Feb 1998 04:00:00



> More importantly, in a program that does read()s ( over a TCP
> connection ) and which also uses signals I am using code which looks
> like
>  while ( read(...) == -1 )
>  { if ( errno != EINTR ) { /* unrecovable error */ }
>     /* just a signal... try again */
>  }

>  ( the read call is blocking )
>  This doesn't work if read() is interrupted while reading .. it will
> simply return with the number of bytes it managed to read... What are
> the solutions to this rather fundemental problem?

The fully general solution is to have the code deal with getting data in
chunks of whatever size happens.  As far as I know there is never any
guarantee that you will be able to read exactly as many bytes as were
written by one read.

-Rob Ryan

 
 
 

tcp/ip program ( using sockets )

Post by Ronald Wah » Mon, 23 Feb 1998 04:00:00



> In a program I just finished I am using strtok to extract TCP messages
> one at a time ( with a DELimeter character set to ASCII 10 line feed )..
>  If you call strtok the first time with a NULL argument
> i.e like this strtok ( NULL, (char *) &DEL );
> then it returns NULL which suits me fine.... but I'm just curious if
> this is the defined behaviour....d

Hmm, I dont know. But this is what I would expect.

Quote:>  More importantly, in a program that does read()s ( over a TCP
> connection ) and which also uses signals I am using code which looks
> like
>  while ( read(...) == -1 )
>  { if ( errno != EINTR ) { /* unrecovable error */ }
>     /* just a signal... try again */
>  }

>  ( the read call is blocking )
>  This doesn't work if read() is interrupted while reading .. it will
> simply return with the number of bytes it managed to read... What are
> the solutions to this rather fundemental problem?

read is not an atomic operation. As long as read is not returning 0 or an
"fatal" error (e.g. _not_ EINTR) you will need additional reads to get all
data.

ron

--

 \ WWW: http://www.tu-chemnitz.de/~row/            \

   \ PGP key available by finger to my email address \

 
 
 

tcp/ip program ( using sockets )

Post by Martin J. Man » Mon, 23 Feb 1998 04:00:00



Quote:> In a program I just finished I am using strtok to extract TCP messages
> one at a time ( with a DELimeter character set to ASCII 10 line feed )..
>  If you call strtok the first time with a NULL argument
> i.e like this strtok ( NULL, (char *) &DEL );
> then it returns NULL which suits me fine.... but I'm just curious if
> this is the defined behaviour....d

The very first time the program calls strtok, you mean?  No, that
would be undefined behavior, and I would expect an addressing
exception would be the result on many systems (assume the internal
pointer is initialized statically to NULL, then this call will try to
examine the character it addresses, which in any helpful environment
will result in a processor exception).

BTW, if you really expect strtok to work you need to pass a _string_
as the second argument, not a pointer to a single char (as seems to be
the case).  As written, that will work only due to luck, or perhaps to
a compiler that zero-fills padding inserted between variables for
alignment (whcih means it could break if you change the order of
variable declararations, or compile with different options, or any
damn thing).

 
 
 

1. Programming a server in Linux using TCP/IP Sockets

Hi, I'm a bit new to programming sockets in Unix, and I've got a major
problem.  The code compiles ok, and no errors are reported when it tries
to bind to the local address and port.  However, when I try to telnet to
it, I get no response.  It appears accept is never being returned from.
If anyone out there has any suggestions or would like to look at the code
for me, that would be great.

Thanks,
Tim

PS I'm running Linix 2.0.32 from a RedHat 5.0 or 5.1 (not sure)

--
Take it easy,

www.machine.eu.org
ftp.machine.eu.org

2. Can do PCI devices transmit data each other?

3. socket/tcp/ip programming with c/c++ ???

4. [2.5.70] DRM (mga) SMP link fix (flush_tlb_all)

5. How to get started on programming TCP/IP sockets on linux?

6. Identifying disconnected user telnet sessions

7. TCP/IP Sockets Programming

8. SCSI on LINUX 0.96

9. Tcp/ip socket programming question

10. TCP/IP socket programming

11. tcp/ip - udp - socket programming

12. How to get started on programming TCP/IP sockets on linux?

13. Good book to learn sockets/TCP-IP programming [SUMMARY]