欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

tcpserv.c

mcf5307实验源代码
C
第 1 页 / 共 2 页
字号:
/*************************************************************************/
/*                                                                       */
/*            Copyright (c) 1993 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.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                            VERSION          */
/*                                                                       */
/*      TCPSERV.C                                  QUICC/SDS  1.1        */
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      Example TCP/IP program for the NCSA TCP/IP kernel.               */
/*      Waits for a client to request a connection, accepts the          */
/*      connection, and echoes any data sent by the client back to       */
/*      the client.                                                      */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Bill Haggerty, Accelerated Technology, Inc.                      */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      tcp_server_task_ptr;               Pointer to TCP client task    */
/*                                             control block.            */
/*      StrEcho;                           Pointer to string echo task   */
/*                                         control block.                */
/*      socketQueue;                       Pointer to socket queue       */
/*                                         control block.                */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*     str_echo                            String Echo task              */
/*     Application_Initialize              Initialize Nucleus PLUS       */
/*                                         application environment       */
/*     TCP_server_task                     TCP server task               */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*     config.h         defines used for buffer sizes, header sizes, etc.*/
/*     hostform.h        Host and local machine configuration information*/
/*     externs.h         External definitions for functions in NCSA      */
/*                       Telnet.                                         */
/*     nucleus.h         contains system constants common to both the    */
/*                       application and Nucleus PLUS components.        */
/*     socketd.h         socket interface structures                     */
/*     tcpdefs.h         definitions for Nucleus - TCP/IP program        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      B. Haggerty      06-25-1997           Created version 1.0        */
/*      M. Phillips      07-14-1997           Created version 1.1        */
/*                                                                       */
/*************************************************************************/
/* Include necessary Nucleus PLUS files.  */

/*
*       Includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef MEMORY_DEBUG
    #include "memdebug.h"
#endif
#include "config.h"
#include "hostform.h"
#include "externs.h"
#include "socketd.h"    /* socket interface structures */
#include "tcpdefs.h"
#include "nucleus.h"


/* Define Application data structures.  */

NU_MEMORY_POOL    System_Memory;
NU_TASK           tcp_server_task_ptr;
NU_TASK           StrEcho0;
NU_TASK           StrEcho1;
NU_QUEUE          socketQueue;

/* Define prototypes for function references.  */

void    tcp_server_task(UNSIGNED argc, VOID *argv);
void    str_echo(UNSIGNED argc, VOID *argv);

#ifdef INTERRUPT
   extern sint NU_Vect_Number;
#endif /* INTERRUPT */

#define ECHO_LENGTH 1500
char    line[ECHO_LENGTH + 1];

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      Application_Initialize                                           */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      Define the Application_Initialize routine that determines the    */
/*      initial Nucleus PLUS application environment.                    */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Neil Henderson, Accelerated Technology, Inc.                     */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      NU_Create_Memory_Pool          Create dynamic memory pool        */
/*      NU_Allocate_Memory             Allocate memory from memory pool  */
/*      NU_Create_Task                 Create an application task.       */
/*      NU_Create_Queue                Create a message Queue            */
/*      NU_Create_Semaphore           Create a counting Semaphore       */
/*      NU_Init_Net                 Set up Nucleus NET internal data     */
/*                                  structures and initialize network    */
/*                                  hardware.                            */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      first_available_memory              Pointer to first available   */
/*                                          memory address               */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      none                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      N. Henderson    06-28-1994      Created initial version 1.0      */
/*      MQ Qian         02-05-1996      Modified for QUICC with SDS      */
/*                                                                       */
/*************************************************************************/
void    Application_Initialize(void *first_available_memory)
{

    VOID           *pointer;
    STATUS         status;

    /* Create a system memory pool that will be used to allocate task stacks,
       queue areas, etc.  */
    status = NU_Create_Memory_Pool(&System_Memory, "SYSMEM",
						first_available_memory, 250000, 50, NU_FIFO);

    if (status != NU_SUCCESS)
		while (-1);

    /* Allocate stack space for and create each task in the system.  */
    
    /* Create tcp_server_task.  */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
		while (-1);

	status = NU_Create_Task(&tcp_server_task_ptr, "TCPSERV", tcp_server_task,
						0, NU_NULL, pointer, 2000, 3, 0, NU_PREEMPT, NU_START);
	if (status != NU_SUCCESS)
		while (2);

    status = NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
		while (-1);

    status = NU_Create_Task(&StrEcho0, "strecho", str_echo, 0, NU_NULL,
		pointer,2000, 3, 0, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
		while (2);

	status = NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
	if (status != NU_SUCCESS)
		while (-1);

	status = NU_Create_Task(&StrEcho1, "strecho", str_echo, 0, NU_NULL,
		pointer, 2000, 3, 0, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
		while (2);

    /* Create Socket queue.  */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 10*sizeof(UNSIGNED),
							NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
		while (-1);

    status = NU_Create_Queue(&socketQueue, "SocQueue", pointer, 10, NU_FIXED_SIZE,
			     1, NU_FIFO);
    if (status != NU_SUCCESS)
		while (-1);
}   /* end Application_Initialize */


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCP_server_task                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */

⌨️ 快捷键说明

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