aboutsummaryrefslogtreecommitdiff
path: root/sys/ki/kireceive.x
blob: 2cd1e7b641c9b758bf44bc5d116703aeb1e2531a (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<mach.h>
include	<ctype.h>
include	"ki.h"

# KI_RECEIVE -- Read a machine independent KII packet from the network
# interface and decode it into the internal, machine dependent form in the
# kii common.  An error status is returned if the opcode and subcode in
# the packet do not match those expected, or if an i/o error occurs on the
# channel.

int procedure ki_receive (server, opcode, subcode)

int	server			# node index of server process
int	opcode			# function opcode
int	subcode			# function subcode (for drivers)

int	stat, ip, op, ch
int	gstrcpy()
include	"kii.com"
include	"kinode.com"

begin
	# Read the packet.
	call ks_aread (server, p_packet, SZB_PACKET)
	call ks_await (server, stat)

	# Hard error on the channel to the kernel server.
	if (stat == ERR)
	    return (ERR)

	# The encoded packet consists of LEN_INTFIELDS 32 bit MII integers
	# followed by p_sbuflen chars, one char per byte.

	call miiupk32 (p_packet, FIRSTINTFIELD, LEN_INTFIELDS, TY_INT)
	call chrupk (p_packet, LEN_INTFIELDS * 4 + 1, p_sbuf, 1,
	    max(0, min(SZ_SBUF, p_sbuflen)) + 1)

	# Check for out of band data, i.e., the data read was not a packet
	# but some unsolicited message, e.g., error message, from the
	# called program.  If this happens, print the error message and
	# return an error status.

	if (stat != SZB_PACKET || p_opcode != opcode || p_subcode != subcode) {

	    # Is it a printable string?  If so, print the message in the
	    # format "node: message".

	    op = gstrcpy (n_alias[1,1,server], p_sbuf, SZ_ALIAS) + 1
	    p_sbuf[op] = ':'
	    op = op + 1
	    p_sbuf[op] = ' '
	    op = op + 1
	    call chrupk (p_packet, 1, p_sbuf, op, SZ_LINE)

	    do ip = op, SZ_LINE {
		ch = p_sbuf[ip]
		if (ch == EOS)
		    break
		else if (!IS_ASCII(ch))
		    call strcpy ("out of band data on ki channel\n", p_sbuf,
			SZ_LINE)
	    }

	    call xer_putline (STDERR, p_sbuf)
	    return (ERR)

	} else
	    return (OK)
end