*** net.c 2004/03/13 18:52:43 1.1 --- net.c 2004/03/13 19:54:13 *************** *** 179,187 **** bytes = next->write(ps, buf, PI_NET_HEADER_LEN, flags); if (bytes < PI_NET_HEADER_LEN) return bytes; ! bytes = next->write(ps, msg, len, flags); ! if (bytes < len) return bytes; CHECK(PI_DBG_NET, PI_DBG_LVL_INFO, net_dump_header(buf, 1)); CHECK(PI_DBG_NET, PI_DBG_LVL_DEBUG, dumpdata(msg, len)); --- 179,189 ---- bytes = next->write(ps, buf, PI_NET_HEADER_LEN, flags); if (bytes < PI_NET_HEADER_LEN) return bytes; ! if (len > 0) { /* avoid zero-length write on tickle */ ! bytes = next->write(ps, msg, len, flags); ! if (bytes < len) return bytes; + } CHECK(PI_DBG_NET, PI_DBG_LVL_INFO, net_dump_header(buf, 1)); CHECK(PI_DBG_NET, PI_DBG_LVL_DEBUG, dumpdata(msg, len)); *************** *** 196,202 **** total_bytes, packet_len, timeout, ! size; struct pi_protocol *prot, *next; struct pi_net_data *data; --- 198,205 ---- total_bytes, packet_len, timeout, ! size, ! done; struct pi_protocol *prot, *next; struct pi_net_data *data; *************** *** 216,255 **** pi_setsockopt(ps->sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT, &timeout, &size); ! total_bytes = 0; ! if (data->txid == 0) { /* Peek to see if it is a headerless packet */ bytes = next->read(ps, msg, 1, flags); if (bytes > 0) { ! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO, ! "NET RX: Checking for headerless packet %d\n", msg[0])); ! if (msg[0] == 0x90) { ! /* Cause the header bytes to be skipped */ ! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO, ! "NET RX: Headerless packet\n")); ! total_bytes = PI_NET_HEADER_LEN; ! msg[PI_NET_OFFSET_TYPE] = PI_NET_TYPE_DATA; ! msg[PI_NET_OFFSET_TXID] = 0x01; ! set_long (&msg[PI_NET_OFFSET_SIZE], 21); ! } else { ! total_bytes += bytes; ! } } else { ! return bytes; } ! } ! /* Bytes in what's left of the header */ ! while (total_bytes < PI_NET_HEADER_LEN) { bytes = next->read(ps, msg + total_bytes, PI_NET_HEADER_LEN - total_bytes, flags); if (bytes <= 0) ! return bytes; total_bytes += bytes; } /* Bytes in the rest of the packet */ - packet_len = get_long(&msg[PI_NET_OFFSET_SIZE]); while (total_bytes < PI_NET_HEADER_LEN + packet_len) { bytes = next->read(ps, msg + total_bytes, PI_NET_HEADER_LEN + packet_len - total_bytes, flags); --- 219,278 ---- pi_setsockopt(ps->sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT, &timeout, &size); ! done = 0; ! while (!done) { ! total_bytes = 0; ! if (data->txid == 0) { /* Peek to see if it is a headerless packet */ bytes = next->read(ps, msg, 1, flags); if (bytes > 0) { ! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO, ! "NET RX: Checking for headerless packet %d\n", msg[0])); ! if (msg[0] == 0x90) { ! /* Cause the header bytes to be skipped */ ! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO, ! "NET RX: Headerless packet\n")); ! total_bytes = PI_NET_HEADER_LEN; ! msg[PI_NET_OFFSET_TYPE] = PI_NET_TYPE_DATA; ! msg[PI_NET_OFFSET_TXID] = 0x01; ! set_long (&msg[PI_NET_OFFSET_SIZE], 21); ! } else { ! total_bytes += bytes; ! } } else { ! return bytes; } ! } ! /* Bytes in what's left of the header */ ! while (total_bytes < PI_NET_HEADER_LEN) { bytes = next->read(ps, msg + total_bytes, PI_NET_HEADER_LEN - total_bytes, flags); if (bytes <= 0) ! return bytes; total_bytes += bytes; + } + packet_len = get_long(&msg[PI_NET_OFFSET_SIZE]); + data->type = msg[PI_NET_OFFSET_TYPE]; + switch (data->type) { + case PI_NET_TYPE_TCKL: + if (packet_len != 0) { + LOG ((PI_DBG_NET, PI_DBG_LVL_ERR, + "NET RX: tickle packet with non-zero length\n")); + return -1; + } + /* valid tickle packet; continue reading. */ + break; + case PI_NET_TYPE_DATA: + done = 1; + break; + default: + LOG ((PI_DBG_NET, PI_DBG_LVL_ERR, + "NET RX: Unknown packet type\n")); + } } /* Bytes in the rest of the packet */ while (total_bytes < PI_NET_HEADER_LEN + packet_len) { bytes = next->read(ps, msg + total_bytes, PI_NET_HEADER_LEN + packet_len - total_bytes, flags);