File: sreadbytes.c

package info (click to toggle)
robotour 3.1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,596 kB
  • ctags: 2,972
  • sloc: cpp: 17,705; sh: 3,060; ansic: 2,778; makefile: 144
file content (47 lines) | stat: -rwxr-xr-x 1,046 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Sreadbytes.c: */
#include <stdio.h>
#include "sockets.h"

/* --------------------------------------------------------------------- */

/* Sreadbytes: this function performs a socket read.
 *  Gets buflen bytes, so long as read is working.
 *  Otherwise, (read fails with a -1), the number
 *  of bytes received will be returned.
 */
#ifdef __PROTOTYPE__
int Sreadbytes(
  Socket *skt,		/* socket handle			*/
  void   *buf,		/* socket character buffer	*/
  int     buflen)	/* max length of buffer		*/
#else
int Sreadbytes(
  skt,				/* socket handle			*/
  buf,				/* socket character buffer	*/
  buflen)			/* max length of buffer		*/
Socket *skt;
void   *buf;
int     buflen;
#endif
{
int cnt;
int rcnt;


/* sanity check */
if(!skt) {
	return -1;
	}

/* get buflen bytes, no matter the wait */
for(cnt= 0; cnt < buflen; cnt+= rcnt) {
	rcnt= recv(skt->skt,(void *) (((char *)buf)+cnt),(unsigned) (buflen-cnt),0);
	if(rcnt < 0) break;
	}

return cnt;
}

/* ---------------------------------------------------------------------
 * vim: ts=4
 */