Welcome, Guest. Please login or register.

Author Topic: ReplyMsg() not working  (Read 3887 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
ReplyMsg() not working
« on: March 15, 2003, 11:49:04 PM »
I have two tasks running at the same time and I want them to talk to each other. A message is sent from task a to task b..if that is sucessful, then task a will ReplyMsg() it. Task b is doing a WaitPort() waiting for the ReplyMsg(), but for some reason it never seems to get it, because at that point it just waits forever. I've tried to just paste the relevant parts of my program. There may be some missing close brackets from my pasting, but dont take any notice of those. Would really appreciate it if someone could help me out..

ULONG signals;
ULONG portsig;
ULONG portsig2;

struct MsgPort *SlapshotNBX_port;
struct MsgPort *SlapshotNBX_replyport;

struct SM_Message {
    struct Message xym_Msg;
    char           SM_info[50];
} *ss_msg, *reply_msg;

int main()
{

 if (SlapshotNBX_port = CreateMsgPort() )
   {
      SlapshotNBX_port->mp_Node.ln_Name = "SlapshotNBX_port";
      SlapshotNBX_port->mp_Node.ln_Pri = 0;

      AddPort(SlapshotNBX_port);
      portsig = 1 << SlapshotNBX_port->mp_SigBit;

   } else cout<<"Unable to create an Exec MsgPort!\n"<
   if (SlapshotNBX_replyport = CreateMsgPort() )
   {
      SlapshotNBX_replyport->mp_Node.ln_Name = "SlapshotNBX_replyport";
      SlapshotNBX_replyport->mp_Node.ln_Pri = 0;

      AddPort(SlapshotNBX_replyport);
      portsig2 = 1 << SlapshotNBX_replyport->mp_SigBit;

   } else cout<<"Unable to create an Exec MsgPort!\n"<
   while (running)
   {

      switch(DoMethod(app->App,MUIM_Application_Input,&signals))
      {

         case MUIV_Application_ReturnID_Quit:
            running = FALSE;
            break;

// ETC ETC ETC

      }

      if (running && signals) signals = Wait(signals | portsig | portsig2); // | SIGBREAKF_CTRL_C);

        if(ng_config_gui_active) newsgroup_parta_task();


   }

int newsgroup_parta_task()
{

if(have_we_connected_sucessfully)
      {
         if(signals & portsig)
           {
              if(ss_msg = (struct SM_Message *)GetMsg(SlapshotNBX_port));
            {
                 if( strcmp(ss_msg->SM_info, "a")==0 )
               {
                  cout<<"Message recieved, did not connect!\n"<                  set2(app->TX_ng_config_status_window,MUIA_Text_Contents,"Unable to connect");
                  have_we_connected_sucessfully=0;

                  ReplyMsg((struct Message *)ss_msg);

               }

               if( strcmp(ss_msg->SM_info, "b")==0)
               {
                   cout<<"Message recieved, connected okay!\n"<                   set2(app->TX_ng_config_status_window,MUIA_Text_Contents,"Connected to server");
                   have_we_connected_sucessfully=0;
                   ReplyMsg((struct Message *)ss_msg);
               }
            }

         }



NOW.. heres task b which runs at the same time..

int ng_config_main()
{

struct SM_Message
{    struct Message xym_Msg;
   char           SM_info[50];
   } *ss3_msg, *ss2_msg;

    struct MsgPort *SlapshotNBX_replyport = FindPort("SlapshotNBX_replyport");
    struct MsgPort *SlapshotNBX_port=FindPort("SlapshotNBX_port");

if (connect(a, (struct sockaddr*)&slapshot_in, sizeof(struct sockaddr)) == -1)
    {
//          ss3_msg->xym_Msg.mn_Node.ln_Type = NT_MESSAGE;
//         ss3_msg->xym_Msg.mn_Node
           ss3_msg->xym_Msg.mn_Length = sizeof(struct SM_Message);
           ss3_msg->xym_Msg.mn_ReplyPort = SlapshotNBX_replyport;
           strcpy(ss3_msg->SM_info,"a");
            
           perror("connect");
           if (SafePutToPort((struct Message *)ss3_msg, "SlapshotNBX_port"))
         {  
              cout<<"Unable to connect, message sent from ng_config_task\n"<              WaitPort(SlapshotNBX_replyport);
           }
    }
    else
    {
           ss3_msg->xym_Msg.mn_Node.ln_Type = NT_MSGPORT;
           ss3_msg->xym_Msg.mn_Length = sizeof(struct SM_Message);
           ss3_msg->xym_Msg.mn_ReplyPort = SlapshotNBX_replyport;
           strcpy(ss3_msg->SM_info,"b");
           
           if (SafePutToPort((struct Message *)ss3_msg, "SlapshotNBX_port"))
         {         
            WaitPort(SlapshotNBX_replyport);
            //ss3_msg = (struct SM_Message *)GetMsg(SlapshotNBX_replyport);
            
              cout<<"Connected, message sent from ng_config_task\n"<           }
    }
 

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Re: ReplyMsg() not working
« Reply #1 on: March 15, 2003, 11:51:20 PM »
A bit more information. I'm using WinUAE with OS 3.9 and StormC 3.0.
 

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Re: ReplyMsg() not working
« Reply #2 on: March 17, 2003, 12:12:57 AM »
Thanks for your help guys, someone has basically told me the same thing on the Amiga C mailing list as well, so I shall attempt to rewrite that part of my program.

 

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Re: ReplyMsg() not working
« Reply #3 on: March 17, 2003, 12:19:31 AM »
It works!!

Yes the problem was the reply port had to be created in task b, we couldnt just use FindPort() there...

Thanks again for your help.

I'm sure there was nothing about this in the RKM's though..