/* Split input on CRLF as that is defined in NNTP protocol 
   and makes everything else simpler */
void channel_read(int c, int gotio)
{
	int nn,rlen;
	char *s1,*s2;
	char tmp[200],rec[4000];
	static int n[MAX_CHAN],r[MAX_CHAN];
	static char buf[8001]; /* Increase to 8001 when debuging finished*/ 


	nn = socket_read(chan[c], buf+n[c], sizeof(buf)-1-n[c]);
	if (nn>0) n[c] +=nn;
	if (nn<0) {chan_close(c); n[c] = 0;}
	else if (n[c]>0)  {
		buf[n[c]] = 0;	
		s1 = buf;
		s2 = strstr(s1,EOL);
		if (s2==NULL) return;
		for (;s2!=NULL;) {
			rlen = s2-s1+2;
			ncpy(rec,s1,rlen);
			dmsg("nntpget: n[%d]=%d (%d) %s",c,n[c],rlen,rec);
			chan_read(c,rec,rlen);
			n[c] -= rlen;
			s1 = s2 + 2;
			s2 = strstr(s1,EOL);		
		}
		memmove(buf,s1,strlen(s1)+1); 
	}
}
