CORDET Framework - C2 Implementation
CrFwClientSocket.c File Reference

Implementation of interface to control the client socket. More...

Go to the source code of this file.

Macros

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

Functions

void CrFwClientSocketInitAction (FwPrDesc_t prDesc)
 Initialization action for the client socket. More...
 
void CrFwClientSocketShutdownAction (FwSmDesc_t smDesc)
 Shutdown action for the client socket. More...
 
void CrFwClientSocketInitCheck (FwPrDesc_t prDesc)
 Initialization check for the client socket. More...
 
void CrFwClientSocketConfigAction (FwPrDesc_t prDesc)
 Configuration action for the client socket. More...
 
void CrFwClientSocketPoll ()
 Poll the client socket to check whether a new packet has arrived. More...
 
CrFwPckt_t CrFwClientSocketPcktCollect (CrFwDestSrc_t nofPcktSrc, CrFwDestSrc_t *pcktSrcs)
 Function implementing the Packet Collect Operation for the client socket. More...
 
CrFwBool_t CrFwClientSocketIsPcktAvail (CrFwDestSrc_t nofPcktSrc, CrFwDestSrc_t *pcktSrcs)
 Function implementing the Packet Available Check Operation for the client socket. More...
 
CrFwBool_t CrFwClientSocketPcktHandover (CrFwPckt_t pckt)
 Function implementing the hand-over operation for the client socket. More...
 
void CrFwClientSocketSetPort (unsigned short n)
 Set the port number for the socket. More...
 
void CrFwClientSocketSetHost (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 = 0
 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 interface to control the client socket.

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 CrFwClientSocket.c.

Function Documentation

◆ CrFwClientSocketConfigAction()

void CrFwClientSocketConfigAction ( FwPrDesc_t  prDesc)

Configuration action for the client socket.

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

Parameters
prDescthe configuration procedure descriptor.

Definition at line 181 of file CrFwClientSocket.c.

◆ CrFwClientSocketInitAction()

void CrFwClientSocketInitAction ( FwPrDesc_t  prDesc)

Initialization action for the client socket.

If the client socket has already been initialized, this function calls the Initialization Action of the base InStream/OutStream and then returns. If the client socket has not yet been initialized, this action:

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

Definition at line 71 of file CrFwClientSocket.c.

◆ CrFwClientSocketInitCheck()

void CrFwClientSocketInitCheck ( FwPrDesc_t  prDesc)

Initialization check for the client socket.

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 158 of file CrFwClientSocket.c.

◆ CrFwClientSocketIsPcktAvail()

CrFwBool_t CrFwClientSocketIsPcktAvail ( CrFwDestSrc_t  nofPcktSrc,
CrFwDestSrc_t pcktSrcs 
)

Function implementing the Packet Available Check Operation for the client socket.

This function implements the following logic:

  • The function begins by checking the Read Buffer.
  • If it is full and the source attribute of the packet it contains is equal one of sources in pcktSrcs, the function returns 1.
  • If the Read Buffer is not full or it is full but the source attribute of the packet it contains is not equal to any of the sources in pcktSrc, the function performs a non-blocking read on the socket.
  • If the read operation returns nothing or returns a packet with a source attribute other than those in pcktSrcs, the function returns 0.
  • If the read operation returns a packet with a source attribute equal to one of the sources in pcktSrc, the function stores it in the Read Buffer and then returns 1.
Parameters
nofPcktSrcthe number of packet sources associated to the InStream
pcktSrcsthe sources associated to the InStream
Returns
the value of a predefined flag

Definition at line 251 of file CrFwClientSocket.c.

◆ CrFwClientSocketPcktCollect()

CrFwPckt_t CrFwClientSocketPcktCollect ( CrFwDestSrc_t  nofPcktSrc,
CrFwDestSrc_t pcktSrcs 
)

Function implementing the Packet Collect Operation for the client socket.

If the packet in the Read Buffer has a source attribute equal to one of those in pcktSrcs, 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 holds a packet from a source other than those in pcktSrcs, this function returns NULL. Note that the logic of the client socket module guarantees that the Read Buffer will always be full when this function is called.

Parameters
nofPcktSrcthe number of packet sources associated to the InStream
pcktSrcsthe sources associated to the InStream
Returns
the packet

Definition at line 231 of file CrFwClientSocket.c.

◆ CrFwClientSocketPcktHandover()

CrFwBool_t CrFwClientSocketPcktHandover ( CrFwPckt_t  pckt)

Function implementing the hand-over operation for the client socket.

This function performs a non-blocking write on the socket and, if it succeeds, it returns 1; otherwise, it returns 0.

Parameters
pcktthe packet to be written to the socket
Returns
1 if the packet was successfully written to the socket; 0 otherwise.

Definition at line 286 of file CrFwClientSocket.c.

◆ CrFwClientSocketPoll()

void CrFwClientSocketPoll ( )

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

This function should be called periodically by an external scheduler. If there is a pending packet (i.e. if the Read Buffer is full), its source is determined, and then function CrFwInStreamPcktAvail is called on the InStream associated to that packet source. If there is no pending packet (i.e. if the Read Buffer is empty), a non-blocking read is performed 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, its source is determined, and then function CrFwInStreamPcktAvail is called on the InStream associated to that packet source. This implementation is intended for use with the test cases of CrFwSocketTestCase.h.

Definition at line 198 of file CrFwClientSocket.c.

◆ CrFwClientSocketSetHost()

void CrFwClientSocketSetHost ( 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 309 of file CrFwClientSocket.c.

◆ CrFwClientSocketSetPort()

void CrFwClientSocketSetPort ( 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 304 of file CrFwClientSocket.c.

◆ CrFwClientSocketShutdownAction()

void CrFwClientSocketShutdownAction ( FwSmDesc_t  smDesc)

Shutdown action for the client socket.

If the client socket has already been shut down, this function calls the Shutdown Action of the base InStream/OutStream and then returns. If the client socket has not yet been shut down, this action executes the Shutdown Action of the base InStream/OutStream, releases the Read Buffer, and closes the socket.

Parameters
smDescthe InStream or OutStream State Machine descriptor.

Definition at line 138 of file CrFwClientSocket.c.

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