Debian Codegraph @

COSMIC/Sreadbytes.c

raw
1 /* Sreadbytes.c:
2 * Authors: Charles E. Campbell, Jr.
3 * Terry McRoberts
4 * Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
5 * Permission is hereby granted to use and distribute this code,
6 * with or without modifications, provided that this copyright
7 * notice is copied with it. Like anything else that's free,
8 * Sreadbytes.c is provided *as is* and comes with no warranty
9 * of any kind, either expressed or implied. By using this
10 * software, you agree that in no event will the copyright
11 * holder be liable for any damages resulting from the use
12 * of this software.
13 * Date: Aug 22, 2005
14 */
15 #include <stdio.h>
16 #include "sockets.h"
17
18 /* --------------------------------------------------------------------- */
19
20 /* Sreadbytes: this function performs a socket read.
21 * Gets buflen bytes, so long as read is working.
22 * Otherwise, (read fails with a -1), the number
23 * of bytes received will be returned.
24 */
25 #ifdef __PROTOTYPE__
26 int Sreadbytes(
27 Socket *skt, /* socket handle */
28 void *buf, /* socket character buffer */
29 int buflen) /* max length of buffer */
30 #else
31 int Sreadbytes(
32 skt, /* socket handle */
33 buf, /* socket character buffer */
34 buflen) /* max length of buffer */
35 Socket *skt;
36 void *buf;
37 int buflen;
38 #endif
39 {
40 int cnt;
41 int rcnt;
42
43
44 /* sanity check */
45 if(!skt) {
46 return -1;
47 }
48
49 /* get buflen bytes, no matter the wait */
50 for(cnt= 0; cnt < buflen; cnt+= rcnt) {
51 rcnt= recv(skt->skt,(void *) (((char *)buf)+cnt),(unsigned) (buflen-cnt),0);
52 if(rcnt < 0) break;
53 }
54
55 return cnt;
56 }
57
58 /* ---------------------------------------------------------------------
59 * vim: ts=4
60 */