here is part of the code. This module receives the packet from the peer
and forwards it to the upper layer. Very first time it is started, the upper layer does receive the data and after that any subsequent messages it writes to the socket desc (appSD), the upper layer does not receive it.
on the other hand if I change the value of state variable to START_STATE in the block (if packet_type == DATA_PACKET), everything seems to be working fine.
It may be hard to decipher from this code snippet, but if you any questions please call me @408-802-5896 (Cell). I have to get this working ASAP.
Thanks,
N
static void sig_alrm(int signo)
{
write(pipefd[1], " ", 1);
printf("sig_alrm::TIMER went off \n"

;
return;
}
int createAckPacket(int sockfd, struct datagram *recvPacket, struct datagram *sendPacket)
{
printf("so_transport :: createAckPacket\n"

;
alarm(0);
removeACPHeader(recvPacket, sendPacket);
createAcknowledgementPacket(recvPacket);
Send(sockfd, sendPacket);
printf("string sent in createAckPacket = %s\n", sendPacket->buffer);
alarm(4);
return 0;
}
int main(int argc, char **argv) {
int sd, appSD, max_fd, n_ready, packetType;
int n;
int ACK_PENDING=0;
int state = START_STATE;
fd_set readFds;
char recvLine[MAXLENGTH];
char sendLine[MAXLENGTH];
static struct datagram recvPacket;
static struct datagram sendPacket;
struct sigaction new_action[1];
struct sigaction old_action[1];
new_action->sa_handler = sig_alrm;
sigemptyset(&new_action->sa_mask);
new_action->sa_flags = SA_RESTART;
sigaction(SIGALRM, new_action, old_action);
if (argc !=4 )
{
printf("usage : %s <server_UDP_Port, Application_UDP_Port, Application_IP_Address> \n", argv[0]);
exit(0);
}
pipe(pipefd);
if ((sd = CreateUDPSocket(atoi(argv[1]), NULL)) == NET_ERR)
{
printf("could not open UDP Socket \n"

;
exit(0);
}
if ((appSD = CreateUDPSocket(0, NULL)) == NET_ERR)
{
printf("could not open UDP Socket \n"

;
exit(0);
}
MakeDatagram(&recvPacket, recvLine, MAXLENGTH,0,NULL);
MakeDatagram(&sendPacket, sendLine, MAXLENGTH, atoi(argv[2]), argv[3]);
/* set up state machine */
int errorCode = FSMsetup(FSMtable, state);
if (errorCode != 0)
{
/* log a message */
printf("so_transport: could not set up FSM \n"

;
exit(1);
}
else {
printf("so_transport: successfully established state machine\n"

;
}
printf("FSM in so_transport \n"

;
FSMdisplay();
while (1) {
FD_ZERO(&readFds);
FD_SET(sd,&readFds);
FD_SET(appSD,&readFds);
FD_SET(pipefd[0], &readFds);
if (sd > appSD) {
max_fd = sd;
}
else {
max_fd = appSD;
}
printf("so_transport::main before select \n"

;
n_ready = select(max_fd+1,&readFds,NULL,NULL,NULL);
printf("so_transport::main select returns \n"

;
if (n_ready < 0 && errno == EINTR) {
printf("so_transport::main errno is EINTR and n_Ready less than 0\n"

;
continue;
}
if (FD_ISSET(appSD, &readFds)) {
if (Receive(appSD, &sendPacket) == NET_OK)
{
printf("Condition = %d, state = %d, appSD is selected \n", MESSAGE_SEND, state);
FSMaction(MESSAGE_SEND, &state, sd, &recvPacket, &sendPacket);
printf("state after the action = %d\n", state);
}
}
if (FD_ISSET(sd, &readFds)) {
if (Receive(sd, &recvPacket) == NET_OK) {
packetType = ProcessPacket(&recvPacket);
printf("SO_TRANSPORT MAIN: Packet Type = %d\n", packetType);
if (packetType == BAD_PACKET)
{
printf("so_transport: bad packet - dropping the packet\n"

;
/* drop the packet */
continue;
}
else if (packetType == DATA_ACK_PACKET)
{
printf("Packet type = DATA_ACK_PACKET \n"

;
printf("Condition = %d, state = %d, sd is selected \n", DATA_ACK_RECEIVED, state);
FSMaction(DATA_ACK_RECEIVED, &state, appSD, &recvPacket, &sendPacket);
printf("state after the action = %d\n", state);
}
else if (packetType == DATA_PACKET)
{
/*alarm(0);
state = START_STATE;
removeACPHeader(&recvPacket, &sendPacket);
createAcknowledgementPacket(&recvPacket);
Send(sd, &recvPacket);
Send(appSD, &sendPacket);
alarm(4);*/
printf("Packet type = DATA_PACKET \n"

;
printf("Condition = %d, state = %d, sd is selected \n", DATA_RECEIVED, state);
FSMaction(DATA_RECEIVED, &state, appSD, &recvPacket, &sendPacket);
printf("state after the action = %d\n", state);
/*from so_transport */
/*state=START_STATE;
removeACPHeader(&recvPacket, &sendPacket);
createAcknowledgementPacket(&recvPacket);
Send(sd, &recvPacket);
Send(appSD, &sendPacket);*/
}
else if (packetType == ACK_PACKET) {
printf("Packet type = ACK_PACKET \n"

;
printf("Condition = %d, state = %d, sd is selected \n", ACK_RECEIVED, state);
FSMaction(ACK_RECEIVED, &state, 0, &recvPacket, &sendPacket);
printf("state after the action = %d\n", state);
}
else if (packetType == NOT_DETERMINED)
{
printf("Packet type has not been determined\n"

;
/*drop the packet */
continue;
}
}
}
if (FD_ISSET(pipefd[0], &readFds)) {
read(pipefd[0], &n, 1); /* timer expired */
printf("Packet type = TIMER_EXPIRED \n"

;
printf("Condition = %d, state = %d, pipefd is selected \n", TIMER_EXPIRED, state);
FSMaction(TIMER_EXPIRED, &state, sd, &recvPacket, &sendPacket);
printf("state after the action = %d\n", state);
}
} /* while */
}