2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 extern int do_compression;
25 /* non-compressing recv token */
26 static int simple_recv_token(int f,char **data)
28 static int residue = 0;
29 static char *buf = NULL;
33 buf = (char *)malloc(CHUNK_SIZE);
34 if (!buf) out_of_memory("simple_recv_token");
45 n = MIN(CHUNK_SIZE,residue);
52 /* non-compressing send token */
53 static void simple_send_token(int f,int token,
54 struct map_struct *buf,int offset,int n)
59 int n1 = MIN(CHUNK_SIZE,n-l);
61 write_buf(f,map_ptr(buf,offset+l,n1),n1);
65 write_int(f,-(token+1));
72 * transmit a verbatim buffer of length n followed by a token
73 * If token == -1 then we have reached EOF
74 * If n == 0 then don't send a buffer
76 void send_token(int f,int token,struct map_struct *buf,int offset,int n)
78 if (!do_compression) {
79 simple_send_token(f,token,buf,offset,n);
83 /* compressed transmit here */
88 * receive a token or buffer from the other end. If the reurn value is >0 then
89 * it is a data buffer of that length, and *data will point at the data.
90 * if the return value is -i then it represents token i-1
91 * if the return value is 0 then the end has been reached
93 int recv_token(int f,char **data)
95 if (!do_compression) {
96 return simple_recv_token(f,data);
99 /* compressed receive here */