File: dnet_recv.c

package info (click to toggle)
dnprogs 2.52
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,644 kB
  • ctags: 4,021
  • sloc: ansic: 26,737; cpp: 10,666; makefile: 832; sh: 537; awk: 13
file content (81 lines) | stat: -rw-r--r-- 2,141 bytes parent folder | download | duplicates (4)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/******************************************************************************
    (c) 1999 Christine Caulfield          christine.caulfield@googlemail.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/*
 * This routine reads a full record from the DECnet socket. it will
 * block until the whole record has been received.
 *
 * Most of the functionality of this is (partially) implemented in Eduardo's
 * kernel hence the #ifdefs here
 */


#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <string.h>
#include <stdlib.h>
#include <netdnet/dn.h>
#include <netdnet/dnetdb.h>

int dnet_recv(int s, void *buf, int len, unsigned int flags)
{
    unsigned int recvflags = flags;

    if (recvflags & MSG_EOR)
	recvflags ^= MSG_EOR;
    
/* Do MSG_EOR... */

#ifdef SDF_UICPROXY // Steve's kernel   
    if (flags & MSG_EOR)
    {
	struct iovec iov;
	struct msghdr msg;
	int status;
	size_t offset = 0;

	msg.msg_control = NULL;	
	msg.msg_controllen = 0;
	msg.msg_iovlen = 1;
	msg.msg_iov = &iov;
	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	iov.iov_len = len;
	iov.iov_base = buf;

	do
	{
 	    status = recvmsg(s, &msg, recvflags);
	    offset += status;
	    iov.iov_base += status;
	} 
	while (status > 0 && !(msg.msg_flags & MSG_EOR));

	if (status > 0) status = offset; /* Return size read */

	return status;
    }
    else
#endif
    {
        return recv(s, buf, len, recvflags);
    }
}