override public bool pkt_proc(byte[] buf) { if (buf == null) { pktbuf = new pkt_rrq(remoteFile, tftpmode.ToString(), idic["timeout"] * idic["maxretry"] / 1000, idic["blksize"]).pack(); } else if (blkno == 0 && (Opcodes)buf[1] == Opcodes.OAck) // oack { pkt_oack pkt = new pkt_oack(); if (!pkt.parse(buf)) { return(false); } update_param(pkt.timeout * 1000 / Math.Max(idic["maxretry"], 1), pkt.blksize); write_file(filename); pktbuf = new pkt_ack(blkno++).pack(); } else { if (blkno == 0) // data blkno start with 1 { write_file(filename); blkno++; } pkt_data pkt = new pkt_data(); if (!pkt.parse(buf)) { return(false); } if (pkt.blkno != (blkno & 0xffff)) { return(true); // ignore expired data? } filesize += pkt.data.Length; if (pkt.data.Length > 0) { while (q.produce(pkt.data) == 0) { ; // infinit produce this data } } pktbuf = new pkt_ack(blkno++).pack(); if (pkt.data.Length < idic["blksize"]) // stop { maxblkno = --blkno; q.stop(); uc.Send(pktbuf, pktbuf.Length, r); return(false); } } curretry = 0; // reset retry cnt return(uc.Send(pktbuf, pktbuf.Length, r) == pktbuf.Length); }
override public bool pkt_proc(byte[] buf) { byte[] data; if (buf == null) { pktbuf = new pkt_wrq(remoteFile, tftpmode.ToString(), idic["timeout"] * idic["maxretry"] / 1000, idic["blksize"]).pack(); } else if (blkno == 0 && (Opcodes)buf[1] == Opcodes.OAck) // oack { pkt_oack pkt = new pkt_oack(); if (!pkt.parse(buf)) { return(false); } update_param(pkt.timeout * 1000 / Math.Max(idic["maxretry"], 1), pkt.blksize); read_file(filename); data = q.consume(); //while ((data = q.consume()) == null) ; // may be infinite wait for a new msg here? pktbuf = new pkt_data(++blkno, data).pack(); } else { if (blkno == 0) { read_file(filename); } pkt_ack pkt = new pkt_ack(); if (!pkt.parse(buf)) { return(false); } if (pkt.blkno != (blkno & 0xffff)) { return(true); // ignore expired ack? } if (blkno == maxblkno && blkno > 0) // over { return(false); } if ((data = q.consume()) == null) { data = new byte[0]; // srv send last empty block; client write last block } pktbuf = new pkt_data(++blkno, data).pack(); } curretry = 0; // reset retry cnt return(uc.Send(pktbuf, pktbuf.Length, r) == pktbuf.Length); }