📄 net_list.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1998 - 1999 ZZX Communicatoin Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of ZZX Communication 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. */
/* */
/*************************************************************************/
/******************************************************************************/
/* */
/* FILENAME */
/* */
/* task_list.c */
/* */
/* DESCRIPTION */
/* */
/* The utl fun of task_list */
/* */
/* AUTHOR */
/* */
/* Morgan Lin */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* Task_List_Init */
/* Task_List_Insert */
/* Task_List_Delete */
/* Listen_Daemon_Init */
/* Listen_Daemon_Insert */
/* Listen_Daemon_Delete */
/* */
/* DEPENDENCIES */
/* */
/* No other file dependencies */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* */
/******************************************************************************/
/* Include */
#include "NMS.H"
/*
It must be defined for bype align
*/
/*
* var defined in nms.c
*/
extern SOCKET_TASK_LIST Command_Task_List ;
extern LISTEN_DAEMON_LIST Command_Listen_Daemon_List ;
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* Task_List_Init */
/* */
/* DESCRIPTION */
/* */
/* This Procedure Init the Command_Task_List */
/*************************************************************************/
STATUS Task_List_Init(SOCKET_TASK_LIST *socket_task_list)
{
socket_task_list->head = NU_NULL ;
socket_task_list->tail = NU_NULL ;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* Task_List_Insert */
/* */
/* DESCRIPTION */
/* */
/* This Procedure insert a entry into the list */
/*************************************************************************/
STATUS Task_List_Insert(SOCKET_TASK *socket_task_head, SOCKET_TASK *task_entry)
{
if (socket_task_head == NU_NULL)
{
Command_Task_List.head = task_entry ;
task_entry->next = NU_NULL ;
return NU_SUCCESS ;
}
task_entry->next = socket_task_head->next ;
socket_task_head ->next = task_entry ;
return NU_SUCCESS ;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* Task_List_Delete */
/* */
/* DESCRIPTION */
/* */
/* This Procedure delete the taskentry which socketd = channel */
/*************************************************************************/
STATUS Task_List_Delete(SOCKET_TASK *socket_task_head, INT channel)
{
SOCKET_TASK *current_task ;
SOCKET_TASK *pre_task ;
for(pre_task= current_task = socket_task_head ; current_task != NU_NULL ;)
{
if (current_task->socketd == channel)
{
if (pre_task != NU_NULL)
{
if (pre_task->next == NULL)
Command_Task_List.head = NULL ;
else
pre_task->next = current_task->next ;
//NU_Close_Socket(current_task->socketd) ;
NU_Delete_Pipe(current_task->sendpipe) ;
NU_Delete_Pipe(current_task->recvpipe) ;
//NU_Delete_Task(current_task->task_id) ;
break ;
}
}
pre_task = current_task ;
current_task = current_task->next ;
}
if (current_task == NU_NULL)
return MSG_TASK_NOTEXIST ;
else
return NU_SUCCESS ;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* Listen_Daemon_List_Init */
/* */
/* DESCRIPTION */
/* */
/* This Procedure Init the Command_Listen_Daemon_List */
/*************************************************************************/
STATUS Listen_Daemon_List_Init(LISTEN_DAEMON_LIST *listen_daemon_list)
{
listen_daemon_list->head = NU_NULL ;
listen_daemon_list->tail = NU_NULL ;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* Listen_Daemon_List_Insert */
/* */
/* DESCRIPTION */
/* */
/* This Procedure insert a entry into the list */
/*************************************************************************/
STATUS Listen_Daemon_List_Insert(LISTEN_DAEMON *listen_daemon_head, LISTEN_DAEMON *listen_entry)
{
LISTEN_DAEMON *current_listen_daemon ;
if (listen_entry == NU_NULL)
return NU_SUCCESS ;
if (listen_daemon_head == NU_NULL)
{
Command_Listen_Daemon_List.head = listen_entry ;
listen_entry->next = NU_NULL ;
return NU_SUCCESS ;
}
for(current_listen_daemon = listen_daemon_head ;
current_listen_daemon != NU_NULL ;
current_listen_daemon = current_listen_daemon->next)
{
if (current_listen_daemon->port == listen_entry->port)
{
current_listen_daemon->connectnum++ ;
return NU_SUCCESS ;
}
}
if (current_listen_daemon == NU_NULL)
{
listen_entry->next = listen_daemon_head->next ;
listen_daemon_head ->next = listen_entry ;
}
return NU_SUCCESS ;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* Listen_Daemon_List_Delete */
/* */
/* DESCRIPTION */
/* */
/* This Procedure delete the taskentry which socketd = channel */
/*************************************************************************/
STATUS Listen_Daemon_List_Delete(LISTEN_DAEMON *listen_daemon_head, INT port)
{
LISTEN_DAEMON *current_listen_daemon ;
LISTEN_DAEMON *pre_listen_daemon ;
for(pre_listen_daemon= current_listen_daemon = listen_daemon_head ;
current_listen_daemon != NU_NULL ;)
{
if (current_listen_daemon->port == port)
{
if (pre_listen_daemon != NU_NULL)
{
if (pre_listen_daemon->next == NULL)
Command_Listen_Daemon_List.head = NULL ;
else
pre_listen_daemon->next = current_listen_daemon->next ;
/* before remove, deallocate memory firstly */
NU_Deallocate_Memory(current_listen_daemon) ;
break ;
}
}
else
{
pre_listen_daemon = current_listen_daemon ;
current_listen_daemon = current_listen_daemon->next ;
}
}
if (current_listen_daemon == NU_NULL)
return MSG_LISTEN_DAEMON_NOTEXIST ;
else
return NU_SUCCESS ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -