MTS: only used in this file get the index of the next packet in order!
| 1926 | // MTS: only used in this file |
| 1927 | // get the index of the next packet in order! |
| 1928 | int nw_psnet_buffer_get_next(uint8_t *data, int *length, network_address *from) { |
| 1929 | int idx; |
| 1930 | int found_buf = 0; |
| 1931 | |
| 1932 | // if there are no buffers, do nothing |
| 1933 | if ((Psnet_lowest_id == -1) || (Psnet_lowest_id > Psnet_highest_id)) { |
| 1934 | return 0; |
| 1935 | } |
| 1936 | |
| 1937 | // search until we find the lowest packet index id# |
| 1938 | for (idx = 0; idx < MAX_PACKET_BUFFERS; idx++) { |
| 1939 | // if we found the buffer |
| 1940 | if (Psnet_buffers[idx].sequence_number == Psnet_lowest_id) { |
| 1941 | found_buf = 1; |
| 1942 | break; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | // at this point, we should _always_ have found the buffer |
| 1947 | ASSERT(found_buf); |
| 1948 | |
| 1949 | // copy out the buffer data |
| 1950 | memcpy(data, Psnet_buffers[idx].data, Psnet_buffers[idx].len); |
| 1951 | *length = Psnet_buffers[idx].len; |
| 1952 | memcpy(from, &Psnet_buffers[idx].from_addr, sizeof(network_address)); |
| 1953 | |
| 1954 | // now we need to cleanup the packet list |
| 1955 | |
| 1956 | // mark the buffer as free |
| 1957 | Psnet_buffers[idx].sequence_number = -1; |
| 1958 | Psnet_lowest_id++; |
| 1959 | |
| 1960 | return 1; |
| 1961 | } |
| 1962 | |
| 1963 | #ifdef WIN32 |
| 1964 | // MTS: only used in this file |