?? whipproxy.c
字號(hào):
/*********************************************************************/
/* Copyright (c) 1999, 2000 GlobeSpan Inc. */
/* Unpublished - All rights reserved under the Copyright Laws of */
/* The United States. */
/* No part of this source code may be copied, used, or modified */
/* Without the express written consent of GlobeSpan. */
/*********************************************************************/
/**
** <FILE_NAME> WhipProxy.c
** <FILE_PURPOSE> Whip Proxy file.
*/
#ifdef FILEID_IN_MEMORY
static char __fileid[] = "$Header: $";
#endif
/*
** System Include Files
*/
#include "vxWorks.h"
#include "sockLib.h"
#include "inetLib.h"
#include "stdioLib.h"
#include "strLib.h"
#include "ioLib.h"
#include "fioLib.h"
#include "taskLib.h"
/*
* Product Include Files
*/
#include "gti.h"
#include "gtiextn.h"
/*
** Component/module Include Files
*/
#include "WhipProxy.h"
/*
* Static Variables
*/
static int sFd = -1; /* socket file descriptor */
int tcpfd = -1; /* socket descriptor from accept */
GTI_BYTE aBuf[WHIP_MAX_MSG_SIZE]; /* buffer for received socket messages */
int TcpWhipReadNBytes(int fd, char *ptr, int nbytes);
extern void Gti_WhipTx(GTI_BYTE GTI_ADDRESS_QUAL *array, short length);
/*
* Function Name: TcpWhipProxy
*
* Input Arguments
* None.
*
* Return Values
* None.
*
* Description: Receives data from WHIP application, via appropriate
* device driver, and makes call to GS_WhipRx().
*
*/
GTI_WORD wsp_length; /* Legacy issue */
int
TcpWhipProxy(int param1)
{
struct sockaddr_in serverAddr; /* server's socket address */
struct sockaddr_in cli_addr; /* client's socket address */
int clilen;
int sockAddrSize; /* size of socket address structure */
int nread;
fd_set readfs; /* file descriptor set */
void* pInfo;
pInfo = (void*)param1;
Gti_WhipInit();
/* set up the local address */
sockAddrSize = sizeof (struct sockaddr_in);
bzero ((char *) &serverAddr, sockAddrSize);
serverAddr.sin_family = AF_INET;
serverAddr.sin_len = (u_char) sockAddrSize;
serverAddr.sin_port = htons (CO_SERVER_PORT_NUM);
serverAddr.sin_addr.s_addr = htonl (INADDR_ANY);
/* create a TCP-based socket */
if ((sFd = socket (AF_INET, SOCK_STREAM, 0)) == ERROR)
{
printf("TcpWhipProxy: socket error\n");
return (ERROR);
}
/* bind socket to local address */
if (bind (sFd, (struct sockaddr *) &serverAddr, sockAddrSize) == ERROR)
{
printf("TcpWhipProxy: bind error\n");
close (sFd);
return (ERROR);
}
/* create queue for client connection requests */
if (listen (sFd, SERVER_MAX_CONNECTIONS) == ERROR)
{
printf("TcpWhipProxy: listen error\n");
close (sFd);
return (ERROR);
}
/* accept new connect requests and spawn tasks to process them */
printf("TcpWhipProxy: Running...\n");
/* Loop forever */
while (1)
{
clilen = sizeof(cli_addr);
tcpfd = accept(sFd, (struct sockaddr *) & cli_addr, & clilen);
if (tcpfd < 0)
{
perror("accept");
exit(1);
}
while (1)
{
FD_ZERO(&readfs);
FD_SET(tcpfd, &readfs);
nread = select(tcpfd + 1, &readfs, NULL, NULL, NULL);
if (nread < 0)
{
perror("select");
if (errno == EINTR)
continue;
close(tcpfd);
break;
}
if (nread == 0)
continue;
if (!FD_ISSET(tcpfd, &readfs))
{
printf("select returned one fd, but read fd not ready");
continue;
}
nread = read(tcpfd, (char*)&aBuf, WHIP_MAX_MSG_SIZE);
if (nread < 0)
{
close (tcpfd);
break;
}
if (nread == 0)
{
close (tcpfd);
break;
}
Gti_WhipRxHandler(&aBuf[0], nread);
}
}
/* Should only get in error */
printf("TcpWhipProxy: ERROR - Exited\n");
return (ERROR);
}
/*
* Function Name: TcpWhipTx
*
* Input Arguments
* pBuf: Pointer to buffer containing data to transmit to WHIP interface.
* nLen: Length of buffer.
*
* Return Values
* None.
*
* Description: Transmits data to WHIP application, via appropriate device driver.
*
*/
void
TcpWhipTx(GTI_BYTE* pBuf,
GTI_WORD nLen)
{
int nwrite;
nwrite = write(tcpfd, (char*)pBuf, nLen);
}
/*
* Function Name: TcpWhipProxyExit
*
* Input Arguments
* taskname: Task name string.
*
* Return Values
* None.
*
* Description: Deletes all tasks, and associated resources created for
* TcpWhipProxyExit.
*
*/
void
TcpWhipProxyExit(char* taskname)
{
int tid;
/*
* Cleanup
*/
tid = taskNameToId(taskname);
if (tid != ERROR)
{
if (sFd)
close (sFd);
if (tcpfd)
close (tcpfd);
taskDelete(tid);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -