📄 tools.c
字号:
/*************************************************************************/
/* */
/* CopyrIght (c) 1993 - 1996 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*
*
* Portions of this program were written by: */
/***************************************************************************
* *
* part of: *
* TCP/IP kernel for NCSA Telnet *
* by Tim Krauskopf *
* *
* National Center for Supercomputing Applications *
* 152 Computing Applications Building *
* 605 E. Springfield Ave. *
* Champaign, IL 61820 *
* *
****************************************************************************/
/****************************************************************************/
/* */
/* FILENAME VERSION */
/* */
/* tools.c 3.2 */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* netsleep */
/* enqueue */
/* dequeue */
/* rmqueue */
/* netputevent */
/* */
/* DEPENDENCIES */
/* */
/* nucleus.h */
/* nu_defs.h */
/* nu_extr.h */
/* protocol.h */
/* data.h */
/* sockext.h */
/* externs.h */
/* tcpdefs.h */
/* tcp_errs.h */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Glen Johnson 10/26/94 Modified enqueue, rmqueue, dequeue, */
/* to handle the new buffer */
/* pointer management. */
/* Maiqi Qian 12/06/96 Fixed the time wrap around (spr0229) */
/* */
/****************************************************************************/
#ifdef PLUS
#include "nucleus.h"
#else /* !PLUS */
#include "nu_defs.h" /* added during ATI mods - 10/20/92, bgh */
#include "nu_extr.h"
#endif /* !PLUS */
#include "protocol.h"
#include "socketd.h"
#include "externs.h"
#include "data.h"
#include "tcpdefs.h"
#include "tcp_errs.h"
#include "target.h"
#include "tcp.h"
#ifdef NORM_PTR
#include <dos.h>
#endif
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* netsleep */
/* */
/* DESCRIPTION */
/* */
/* Sleep, while demuxing packets, so we don't miss anything */
/* */
/* CALLED BY */
/* netdlayer */
/* netgetrarp */
/* netxopen */
/* Stask */
/* NU_EventsDispatcher */
/* */
/* CALLS */
/* */
/* n_clicks */
/* comparen */
/* getdlayer */
/* */
/*************************************************************************/
#if !(defined INTERRUPT) || (defined PACKET_DRV)
int16 CDECL netsleep (int16 n)
{
uint16 u;
int16 nmux, redir;
int32 t, gt, start;
PORT *prt, **q;
uint8 *pc;
redir = 0;
start = n_clicks ();
if (n)
t = start + n * TICKSPERSEC;
else
t = start;
do
{
nmux = demux (1); /* demux all packets */
/*
* if there were packets in the incoming packet buffer, then more
* might have arrived while we were processing them. This gives
* absolute priority to packets coming in from the network.
*/
if (nmux)
continue;
/*
* Check each port to see if action is necessary.
* This now sends all Ack packets, due to prt->lasttime being set to 0L.
* Waiting for nmux==0 for sending ACKs makes sure that the network
* has a much higher priority and reduces the number of unnecessary
* ACKs.
*/
gt = n_clicks ();
q = &portlist[0];
for (u = 0; u < NPORTS; u++, q++)
{
prt = *q;
if ((prt != NU_NULL) && (prt->state > SLISTEN))
{
/* NFH - may be a bug, or we will never get here under normal
* circumstances. However, in transq, if sendsize is 0 we
* spin in an infinite loop. I added the code && p->sendsize
* > 0 to prevent this.
*/
if ((!prt->out.lasttime) && (prt->sendsize > 0) &&
(prt->state == SEST))
{
tcp_sendack(prt, 0); /* takes care of all ACKs */
}
if ((INT32_CMP((prt->out.lasttime+POKEINTERVAL), gt) < 0) &&
(prt->state == SEST))
{
tcp_sendack(prt, 0);
prt->out.lasttime = n_clicks();
}
/*
* check to see if ICMP redirection occurred and needs servicing.
* If it needs servicing, try to get the new hardware address for the new
* gateway. If getdlayer fails, we assume an ARP was sent, another ICMP
* redirect will occur, this routine will reactivate, and then the hardware
* address will be available in the cache.
* Check all ports to see if they match the redirected address.
*/
if (redir && comparen (prt->tcpout.i.ipdest, nnicmpsave, 4))
{
pc = getdlayer (nnicmpnew);
if (pc != NU_NULL)
{
memcpy ((void *)prt->tcpout.d.dest, (const void *)pc,
DADDLEN);
}
} /* end redir && comparen */
} /* end if */
} /* end for */
redir = 0; /* reset flag for next demux */
} while ((t>n_clicks ()) && (n_clicks() >= start)); /* allow for wraparound of timer */
return (nmux); /* will demux once, even for sleep(0) */
}
#endif /* !INTERRUPT */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* enqueue */
/* */
/* DESCRIPTION */
/* */
/* Add a packet to a TCP queue. Used by both 'write()' and */
/* TCP_Interpret(). WINDOWSIZE is the size limitation of the */
/* advertised window. */
/* */
/* CALLED BY */
/* estab1986 */
/* netwrite */
/* */
/* CALLS */
/* dll_update_lists */
/* */
/* INPUTS */
/* */
/* wind Pointer to the window in which the */
/* the packet will be placed. */
/* buffer Pointer to the data in the packet. */
/* nbytes The number of data bytes in the packet. */
/* */
/* OUTPUTS */
/* */
/* nbytes The number of data bytes in the packet. */
/*************************************************************************/
uint16 enqueue (struct window *wind, uchar *buffer, uint16 nbytes)
{
struct pqueue HUGE *item_ptr;
/* Remove the packet from the buffer_list and place it in the window list. */
item_ptr = dll_update_lists(&buffer_list, &wind->packet_list);
/* Initialize the data structure. */
item_ptr->data_ptr = (uchar HUGE *)buffer;
item_ptr->data_len = nbytes;
/* Increment the number of bytes and the number of packets this
* window contains.
*/
wind->contain += nbytes; /* more stuff here */
wind->num_packets++;
return (nbytes);
} /* end enqueue */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* dequeue */
/* */
/* DESCRIPTION */
/* */
/* Used by netread, this copies data out of the queue and then */
/* deallocates it from the queue. */
/* rmqueue is very similar and is to be used by tcpsend */
/* to store unacknowledged data. */
/* */
/* Returns the number of bytes removed from the queue. */
/* */
/* CALLED BY */
/* netread */
/* */
/* CALLS */
/* dll_update_lists */
/* */
/*************************************************************************/
uint16 dequeue (struct window *wind, char *buffer, uint16 nbytes, char odh_flag)
{
uint16 actual_bytes;
int16 offset = 0;
int32 *temp_ptr;
struct pqueue HUGE *buf_ptr;
/* If there is no data in the window, return. */
if ((wind->contain == 0) || (wind->packet_list.head == NU_NULL))
return(0);
/* Check the ODH flag. If ODH is enabled then return a pointer to data
section of the first buffer. Else copy the data into the users buffer.*/
if (odh_flag & NU_ODH_RECEIVE)
{
/* Set up an temporary int32 pointer to the buffer. If ODH is enabled
then buffer points to a 32 bit integer, not to a buffer. */
temp_ptr = (int32 *)buffer;
/* Place the first buffer in this windows packet_list onto the ODH
list. It will remain here until the application moves it to the
buffer_freelist with a call to NU_Deallocate_Buffer. */
buf_ptr = dll_update_lists(&wind->packet_list, &odh_list);
/* Convert the address of the first byte of data to a 32 bit integer. */
*temp_ptr = (int32)buf_ptr->data_ptr;
/* Get the number of bytes which will be returned. */
actual_bytes = buf_ptr->data_len;
/* Update the number of bytes in the window. */
wind->contain -= buf_ptr->data_len;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -