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"< }
}