26 lines
319 B
C
26 lines
319 B
C
//
|
|
// TCP recv
|
|
//
|
|
|
|
#include "netlib.h"
|
|
|
|
int tcp_recv( int sock, void *buf, int len )
|
|
{
|
|
char *s = (char *)buf;
|
|
size_t n;
|
|
|
|
/* check! */
|
|
if ( sock < 0 )
|
|
return -1;
|
|
if ( !buf || len <= 0 )
|
|
return -1;
|
|
|
|
/* read */
|
|
n = recv( sock, buf, len, 0 );
|
|
|
|
if ( n > 0 )
|
|
*(s+n) = '\0';
|
|
|
|
return n;
|
|
}
|