Exemple #1
0
SDMLIB_API long getPort()
{
	char msg[5];
	int sock;
	long value = -1;

	msg[0] = SDM_ReqPort;
	sock = UDPconnect("127.0.0.1", PORT_PM);
	if (sock != IP_SOCK_INVALID)
	{
		UDPsend(sock, msg, 1);
		if(UDPrecv(sock, msg, 5) == 5)
		{
			value = GET_LONG (&msg[1]);
		}
		UDPclose(sock);
	}
	//If the Process Manager didn't respond
	if (value < PORT_APP_START || value > 65535)
	{
		return SDM_PM_NOT_AVAILABLE;
	}

	return value;
}
Exemple #2
0
/*
    Forward a previously received message unchanged (i.e. without changing the timestamp).

    Implementation notes:  Currently, only messages of maximum size BUFSIZE can be forwarded.
    The only message that won't send as expected is SDMxTEDS.  The reason for this is that
    the DM is the only application that should ever receive SDMxTEDS, and it will never use
    this function.

    Params:
    	destination - The component id to which to forward the message
    Returns:
    	long - The length of the message sent or -1 to indicate failure
*/
long SDMmessage::Forward(const SDMComponent_ID& destination)
{
	char buf[BUFSIZE];

	if (MsgName == SDM_xTEDS)
		return -1;

	// Save the old timestamp
	long OldSeconds = sec;
	long OldSubSeconds = subsec;

	// Marshal the message, this call will assign a new timestamp
	const long MessageLength = Marshal(buf);
	if (MessageLength < 0)
		return MessageLength;

	// Reset the old timestamp
	sec = OldSeconds;
	subsec = OldSubSeconds;

	// Remarshal the header, overwriting previous data, body of message is still intact
	MarshalHeaderOldTimeStamp(buf);

	// Now send the message to the destination component id
	int sock = UDPconnect(destination.getAddress(), destination.getPort());
	if (sock < 0)
		return -1;
	long SendResult = UDPsend(sock, buf, MessageLength);
	UDPclose(sock);

#ifdef BUILD_WITH_MESSAGE_LOGGING
	Logger.MessageSent(*this);
#endif
	return SendResult;
}
Exemple #3
0
long SDMmessage::SendTo(const SDMComponent_ID& destination)
{
	int sock;
	long i;
	long result;
	char buf[LARGE_MSG_BUFSIZE];
	char ack[16];
	long address = destination.getAddress();
	int timeout = 2000;   // 2 sec
	int count = 0;
	short error = 0;

	//fill buffer
	i = Marshal(buf);
	if(i < 0)
		return SDM_MESSAGE_SEND_ERROR;
#ifdef TCP_TRANSMIT_OF_LARGE_XTEDS
	if(i>BUFSIZE)
		return SendTCP(destination.getAddress(),destination.getPort());
#endif
	//send message
	sock = UDPconnect(address,destination.getPort());
  if (sock != IP_SOCK_INVALID) // cleanup issue 26
  {
	  result = UDPsend(sock,buf,i);
	  //Look for SDM_ACK from DM for certain messages
	  if(buf[0] == SDM_xTEDS || buf[0] == SDM_CancelxTEDS)
	  {
		  if(buf[0] == SDM_xTEDS)
		  {
			  timeout = 5000;   // 5 sec
		  }
		  UDPset_recv_timeout(sock, timeout);

		  UDPrecv(sock,&ack,13);
		  while(ack[0]!=SDM_ACK && count < NUMRETRIES)
		  {
			  count++;

			  result = UDPsend(sock,buf,i);
			  UDPrecv(sock,&ack,13);
		  }
		  //remove timeout on sdm_dm_sock
		  UDPset_recv_timeout(sock, 0);

      if(count == NUMRETRIES && ack[0]!=SDM_ACK)
      {
		    result = SDM_UNABLE_TO_REGISTER;
      }
	    else
      {
		    error = GET_SHORT(&ack[11]); 
        if(error < 0)
        {
			    result = error;
        }
      }
    }
	  UDPclose (sock);
#ifdef BUILD_WITH_MESSAGE_LOGGING
	  Logger.MessageSent(*this);
#endif
  }
	return result;
}
Exemple #4
0
Status SendReply(Message *replyMessage, int s, SocketAddress clientSA){
	return UDPsend(s, replyMessage, clientSA);
}