⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 mcf5307实验源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	Smptr->next = Smachlist;			/* add to front of machlist */
	Smachlist = Smptr;
	return (Smptr);
}

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      Slookip(struct id_struct *)                                      */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*   For FTP to look up the transfer options to use when running         */
/*                                                                       */
/* CALLED BY                                                             */
/*      NU_Connect                                                       */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      comparen                                                         */
/*                                                                       */
/*************************************************************************/
struct machinfo *Slookip(struct id_struct *ipnum)
{
    struct machinfo *m;

    m = Smachlist;
    while (m)
    {
        if (comparen (&m->hostip, ipnum, 4))
        {
            return (m);
        }
        m = m->next;
    }
    return(NU_NULL);
}  /* end Slookip */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      Shostlook(int8 *)                                                */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*   The straightforward list searcher.  Looks for either the            */
/*   session name matching or the host name matching.  NULL if neither.  */
/*                                                                       */
/* CALLED BY                                                             */
/*      Scopyfrom                                                        */
/*      Smadd                                                            */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      ncstrcmp                                                         */
/*                                                                       */
/*************************************************************************/
struct machinfo *Shostlook(int8 *hname)
{
    struct machinfo *m;

    m = Smachlist;
    while (m != NU_NULL)
    {
        if ((m->sname[0] && !ncstrcmp(hname, (int8 *)&m->sname))
            || (m->hname[0] && !ncstrcmp (hname, (int8 *)&m->hname)))
        {
            return (m);
        }
        m = m->next;
    }

    return (NU_NULL);
}  /* end routine Shostlook */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      Snetopen(struct machinfo *, int16)                               */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*   Takes a pointer to a machine record (already looked up with         */
/*   Sgethost) and sends a TCP open call.  Uses port *tport*.            */
/*                                                                       */
/* CALLED BY                                                             */
/*      connect_sock                                                     */
/*      NU_EventsDispatcher                                              */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      netxopen                                                         */
/*      Stimerset                                                        */
/*                                                                       */
/*************************************************************************/
int16 Snetopen(struct machinfo *m, int16 tport)
{
    if ((!m) || (m->mstat<HAVEIP))
    {
        return (-1);
    }
    /* do the open call */
    return (netxopen ((uint8 *)&m->hostip, (uint16)tport, m->retrans,
                  m->mtu, m->maxseg, m->window));

}   /* end Snetopen() */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      Stimerset(int16, int16, int16, int16, int32)                     */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*   Set an async timer which is checked in Stask -- when time elapses   */
/*   sticks an event in the network event queue                          */
/*                                                                       */
/*   class, event, dat is what gets posted when howlong times out.       */
/*                                                                       */
/* CALLED BY                                                             */
/*      NU_EventsDispatcher                                              */
/*      tcpsend                                                          */
/*      Snetopen                                                         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      dll_dequeue                                                      */
/*      NU_Allocate_Memory                                               */
/*      n_clicks                                                         */
/*      netputevent                                                      */
/*                                                                       */
/*************************************************************************/
STATUS Stimerset (UNSIGNED class, UNSIGNED event, UNSIGNED dat, UNSIGNED howlong,
                 int32 seq_number)
{
    tqe_t *tqe;
#ifdef PLUS
    STATUS  status;
#else
    sint status;              /* status of memory allocation */
#endif
    uint *return_ptr;

    /*  Get an entry from the freelist.  */
    tqe = (tqe_t *) dll_dequeue ((tqe_t *) &tcptimer_freelist);

    /*  Check to see if an entry was found.  If one was not found, need
        to allocate a new one. */

    if (!tqe)
	{
        /*  Get some memory for the new entry.  */
#ifdef PLUS
        status = NU_Allocate_Memory(&System_Memory, (void *) &return_ptr,
                                (UNSIGNED)sizeof(tqe_t),
                                (UNSIGNED)NU_NO_SUSPEND);
#else
        status = NU_Alloc_Memory (sizeof(tqe_t),
                              (unsigned int **)&return_ptr, NU_WAIT_FOREVER);
#endif

        /* check status of memory allocation */
		if (status == NU_SUCCESS)
        {
            return_ptr = normalize_ptr(return_ptr);
            tqe = (tqe_t *)return_ptr;
        }
		else
		{
            NU_Tcp_Log_Error (TCP_SESS_MEM, TCP_RECOVERABLE,
                                __FILE__, __LINE__);
			return (-1);
		}
	}

    /*  Set up the new entry.  */
    tqe->tqe_class = class;
	tqe->tqe_event = event;
	tqe->tqe_data = dat;
    tqe->tqe_ext_data = seq_number;
    tqe->duetime = n_clicks() + howlong;

    /*  Place the new entry on the timerlist.  */
    tqpost ((tqe_t *) &tcp_timerlist, tqe);

    /* Check to see if the current task is the  events dispatcher.  If it
     * is we do not want to place an item onto the event queue.  If the queue
     * is full the events dispatcher will suspend on the queue, and since
     * the events dispatcher is the only task that removes items from the
     * queue, deadlock will occur.
     */
#ifdef PLUS
    if (NU_Current_Task_Pointer() == &NU_EventsDispatcher_ptr)
#else
    if (NU_Current_Task_ID() == NU_EventsDispatcherID)
#endif
    {
        return(NU_SUCCESS);
    }

    /*  Wake up the event dispatcher from an indefinite wait */
    /*  iff this is the first entry on the timer list        */
    if (tcp_timerlist.flink == tqe)
      netputevent(CONCLASS, CONNULL, dat);

    return (NU_SUCCESS);
} /* end Stimerset */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      Stimerunset(uint8, uint8, int16, int32)                          */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*   Remove all timer events from the queue that match the               */
/*   class/event/dat.                                                    */
/*                                                                       */
/* CALLED BY                                                             */
/*      tcpdo                                                            */
/*      ackcheck                                                         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      clear_matching_timer                                             */
/*                                                                       */
/*************************************************************************/
STATUS Stimerunset (UNSIGNED class, UNSIGNED event, UNSIGNED dat, int32 ack_num)
{
   return (clear_matching_timer (&tcp_timerlist, class, event, dat, ack_num));
}  /* end Stimerunset */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      clear_matching_timer(struct tqhdr *, uint8, uint8, int16)        */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*   Remove all timer events from the queue that match the               */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -