CORDET Framework - C2 Implementation
CrFwInStreamSocket.c File Reference

Implementation of Socket-Based InStream. More...

Go to the source code of this file.

Macros

#define h_addr   h_addr_list[0]
 Required for backward compatibility.
 

Functions

void CrFwInStreamSocketInitAction (FwPrDesc_t prDesc)
 Initialization action for the socket-based InStream. More...
 
void CrFwInStreamSocketShutdownAction (FwSmDesc_t smDesc)
 Shutdown action for the socket-based InStream. More...
 
void CrFwInStreamSocketInitCheck (FwPrDesc_t prDesc)
 Initialization check for the socket-based InStream. More...
 
void CrFwInStreamSocketConfigAction (FwPrDesc_t prDesc)
 Configuration action for the socket-based InStream. More...
 
void CrFwInStreamSocketPoll (FwSmDesc_t inStream)
 Poll the socket to check whether a new packet has arrived. More...
 
CrFwPckt_t CrFwInStreamSocketPcktCollect (CrFwDestSrc_t src)
 Function implementing the Packet Collect Operation for the socket-based InStream. More...
 
CrFwBool_t CrFwInStreamSocketIsPcktAvail (CrFwDestSrc_t src)
 Function implementing the Packet Available Check Operation for the InStream. More...
 
void CrFwInStreamSocketSetPort (unsigned short n)
 Set the port number for the socket. More...
 
void CrFwInStreamSocketSetHost (char *name)
 Set the host name of the server. More...
 

Variables

static unsigned short portno = 0
 The port number.
 
static char * hostName = NULL
 The host name.
 
static int sockfd
 The file descriptor for the socket.
 
static unsigned int pcktMaxLength
 The maximum size of an incoming packet.
 
static unsigned char * readBuffer
 The Read Buffer.
 

Detailed Description

Implementation of Socket-Based InStream.

Author
Vaclav Cechticky vacla.nosp@m.v.ce.nosp@m.chtic.nosp@m.ky@p.nosp@m.np-so.nosp@m.ftwa.nosp@m.re.co.nosp@m.m
Alessandro Pasetti paset.nosp@m.ti@p.nosp@m.np-so.nosp@m.ftwa.nosp@m.re.co.nosp@m.m

This file is part of the CORDET Framework.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

For information on alternative licensing, please contact P&P Software GmbH.

Definition in file CrFwInStreamSocket.c.

Function Documentation

void CrFwInStreamSocketConfigAction ( FwPrDesc_t  prDesc)

Configuration action for the socket-based InStream.

This action clears the Read Buffer and executes the the Configuration Action of the base InStream (function CrFwInStreamDefConfigAction)

Parameters
prDescthe configuration procedure descriptor.

Definition at line 157 of file CrFwInStreamSocket.c.

void CrFwInStreamSocketInitAction ( FwPrDesc_t  prDesc)

Initialization action for the socket-based InStream.

This action:

  • creates the Read Buffer;
  • creates and connects the socket as a non-blocking socket;
  • executes the Initialization Action of the base InStream (function CrFwInStreamDefInitAction)
  • sets the outcome to "success" if the previous operations are successful.
Parameters
prDescthe initialization procedure descriptor.

Definition at line 71 of file CrFwInStreamSocket.c.

void CrFwInStreamSocketInitCheck ( FwPrDesc_t  prDesc)

Initialization check for the socket-based InStream.

The check is successful if: the maximum length of a packet (as retrieved from CrFwPcktGetMaxLength) is smaller than 256; and the port number and server host name have been set.

Parameters
prDescthe initialization procedure descriptor.

Definition at line 134 of file CrFwInStreamSocket.c.

CrFwBool_t CrFwInStreamSocketIsPcktAvail ( CrFwDestSrc_t  src)

Function implementing the Packet Available Check Operation for the InStream.

This function implements the following logic:

  • The function begins by checking the Read Buffer.
  • If it is full, the function returns 1.
  • If the Read Buffer is not full, the function performs a non-blocking read on the socket.
  • If the read operation returns nothing, the function returns 0.
  • If the read operation returns a packet, the function stores it in the Read Buffer and then returns 1.
Parameters
srcthe source associated to the InStream (not used in this stub)
Returns
the value of a predefined flag

Definition at line 201 of file CrFwInStreamSocket.c.

CrFwPckt_t CrFwInStreamSocketPcktCollect ( CrFwDestSrc_t  src)

Function implementing the Packet Collect Operation for the socket-based InStream.

If the Read Buffer is full, this function:

  • creates a packet instance through a call to CrFwPcktMake
  • copies the content of the Read Buffer into the newly created packet instance
  • clears the Read Buffer
  • returns the packet instance

If the Read Buffer is empty, this function returns NULL. Note that the logic of the socket-based InStream guarantees that the Read Buffer will always be full when this function is called.

Parameters
srcthe source associated to the InStream (not used in this stub)
Returns
the packet

Definition at line 187 of file CrFwInStreamSocket.c.

void CrFwInStreamSocketPoll ( FwSmDesc_t  inStream)

Poll the socket to check whether a new packet has arrived.

This function should be called periodically by an external scheduler. It performs a non-blocking read on the socket to check whether a packet is available at the socket. If a packet is available, it is placed into the Read Buffer and then function CrFwInStreamPcktAvail is called to signal the arrival of a new packet.

Parameters
inStreamthe socket-based InStream

Definition at line 166 of file CrFwInStreamSocket.c.

void CrFwInStreamSocketSetHost ( char *  name)

Set the host name of the server.

If a local socket is being created, the host name should be set to "localhost".

Parameters
namethe host number.

Definition at line 234 of file CrFwInStreamSocket.c.

void CrFwInStreamSocketSetPort ( unsigned short  n)

Set the port number for the socket.

The port number must be an integer greater than 2000.

Parameters
nthe port number.

Definition at line 229 of file CrFwInStreamSocket.c.

void CrFwInStreamSocketShutdownAction ( FwSmDesc_t  smDesc)

Shutdown action for the socket-based InStream.

This action executes the Shutdown Action of the base InStream (function CrFwInStreamDefShutdownAction), releases the Read Buffer, and closes the socket.

Parameters
smDescthe InStream State Machine descriptor (this parameter is not used).

Definition at line 127 of file CrFwInStreamSocket.c.

P&P Software GmbH, Copyright 2012-2013, All Rights Reserved