said:
>char *GetLine(int Socket){
> static char Buffer[4096];
> int rc;
> int offset;
> rc = recv (Socket, Buffer, sizeof (Buffer), 0);
> if (rc > 0){
> if ( '\n' == Buffer[rc-1] ) {
> return &Buffer;
> } else {
> offset = rc;
> rc = recv (Socket, Buffer+offset, sizeof (Buffer)-offset, 0);
> return &Buffer;
> }
> } else {
> return NULL;
> }
>}
Time for my 2cents. The above only fixes part of the problem and can
return a buffer without and NL to the caller. The "specifications" don't
say if the caller must handle this.
char *GetLine(int Socket){
static char Buffer[4096];
int rc = 0;
int offset = 0;
while (rc >= 0 && offset < sizeof(Buffer)){
rc = recv (Socket, Buffer + offset, sizeof (Buffer) - offset,
0);
if (rc > 0) {
if ( '\n' == Buffer[offset+rc-1] )
return Buffer;
else
offset += rc;
}
}
return NULL; /* No NL or recv failed */
}
What's left is to decide how many times we allow recv to return no data
before giving up.
Steven
--
-----------------------------------------------------------
Steven Levine MR2/ICE #10183
-----------------------------------------------------------
=====================================================
To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".
For problems, contact the list owner at
"rollin@scoug.com".
=====================================================
<< Previous Message <<
>> Next Message >>
Return to [ 02 |
June |
1998 ]
The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS
RESERVED.
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International
Business Machines Corporation.
All other trademarks remain the property of their respective owners.