📄 sockprot.c
字号:
//--------------------------------------------------------------------------
// Ip Stack
//--------------------------------------------------------------------------
// SOCK.C
//
// Object member functions for the Sock device object.
//
// These functions get access to the SOCK object structure and can
// adjust values, but usually call protocol functions for perform
// action.
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stkmain.h>
#include "sock.h"
//--------------------------------------------------------------------
// SockPrAttach()
//
// Called to invoke protocol attach
//--------------------------------------------------------------------
int SockPrAttach( SOCK *ps )
{
// Should only be TCP, but make sure
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrAttach( (HANDLE)ps, &ps->hTP ) );
else
return( SockPcbAttach( ps ) );
}
//--------------------------------------------------------------------
// SockPrDetach()
//
// Called to invoke protocol detach
//--------------------------------------------------------------------
int SockPrDetach( SOCK *ps )
{
// Should only be TCP, but make sure
if( ps->SockProt == SOCKPROT_TCP )
{
// If we've already started the closing process, then this
// is a hard drop - tell TCP to just free it and return.
// Otherwise, TCP will try and tell the peer that we've
// dropped the socket
if( ps->StateFlags & SS_CLOSING )
return( TcpPrDetach( (HANDLE)ps, &ps->hTP, 1 ) );
else
return( TcpPrDetach( (HANDLE)ps, &ps->hTP, 0 ) );
}
else
return( SockPcbDetach( ps ) );
}
//--------------------------------------------------------------------
// SockPrRecv()
//
// Called to notify the protocol that data has been consumed
//--------------------------------------------------------------------
int SockPrRecv( SOCK *ps )
{
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrRecv( (HANDLE)ps, ps->hTP ) );
else
return( EINVAL );
}
//--------------------------------------------------------------------
// SockPrSend()
//
// Called to notify request protocol to send data
//--------------------------------------------------------------------
int SockPrSend( SOCK *ps, UINT8 *pBuf, INT32 size, INT32 *pRetSize )
{
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrSend( (HANDLE)ps, ps->hTP, pBuf, size, pRetSize ) );
else if( ps->SockProt == SOCKPROT_UDP )
return( UdpOutput( (HANDLE)ps, pBuf, size, pRetSize ) );
else if( ps->SockProt == SOCKPROT_RAW )
return( RawOutput( (HANDLE)ps, pBuf, size, pRetSize ) );
else
return( EINVAL );
}
//--------------------------------------------------------------------
// SockPrSendOOB()
//
// Called to notify request protocol to send OOB data
//--------------------------------------------------------------------
int SockPrSendOOB( SOCK *ps, UINT8 *pBuf, INT32 size, INT32 *pRetSize )
{
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrSendOOB( (HANDLE)ps, ps->hTP, pBuf, size, pRetSize ) );
else
return( EINVAL );
}
int Code2Err[] = { 0, 0, 0, 0,
0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
EMSGSIZE, EHOSTUNREACH, 0, 0,
0, 0, 0, 0,
ENOPROTOOPT };
//--------------------------------------------------------------------
// SockPrCtlError()
//
// Called to notify socket of a problem
//--------------------------------------------------------------------
void SockPrCtlError( SOCK *ps, uint Code )
{
if( ps->SockProt == SOCKPROT_TCP )
TcpPrCtlError( ps, ps->hTP, Code, Code2Err[Code] );
else if( ps->SockProt == SOCKPROT_UDP )
{
// UDP is easy, just set the socket error
if( !ps->ErrorPending )
ps->ErrorPending = Code2Err[Code];
}
return;
}
//
// The TCP Only Functions can be #define'd
//
#ifdef _STRONG_CHECKING
//--------------------------------------------------------------------
// SockPrListen()
//
// Called to invoke protocol listen
//--------------------------------------------------------------------
int SockPrListen( SOCK *ps )
{
// Should only be TCP, but make sure
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrListen( (HANDLE)ps, ps->hTP ) );
else
return( EINVAL );
}
//--------------------------------------------------------------------
// SockPrConnect()
//
// Called to invoke protocol connect request
//--------------------------------------------------------------------
int SockPrConnect( SOCK *ps )
{
// Should only be TCP, but make sure
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrConnect( (HANDLE)ps, ps->hTP ) );
else
return( EINVAL );
}
//--------------------------------------------------------------------
// SockPrDisconnect()
//
// Called to invoke protocol disconnect request
//--------------------------------------------------------------------
int SockPrDisconnect( SOCK *ps )
{
// Should only be TCP, but make sure
if( ps->SockProt == SOCKPROT_TCP )
return( TcpPrDisconnect( (HANDLE)ps, ps->hTP ) );
else
return( EINVAL );
}
//--------------------------------------------------------------------
// SockPrInherit()
//
// Called at spawn time so child can inherit parent options
//--------------------------------------------------------------------
void SockPrInherit( SOCK *psP, SOCK *psC )
{
// Should only be TCP, but make sure
if( psC->SockProt == SOCKPROT_TCP )
TcpPrInherit( (HANDLE)psP, psP->hTP, (HANDLE)psC, psC->hTP );
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -