× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Alan,

I'm not sure I understand your scenario. You say the RPG code is
"running as part of a C program". I would assume that means you have
one program written with multiple modules, the main module is C, and
another module is RPG. (Which technically is not a "C program", it's
just a program made with C and also RPG... but that's what I figured
you meant.)

But... then you say they are communicating with sendmsg/recvmsg, which
would make any sense if they are modules in the same program. You
wouldn't use sockets like this unless they were running in separate jobs...

Though, maybe you have multiple instances of this program running in
separate jobs, I guess? Please clarify what you mean, here.

As for why you aren't getting an EINTR and your handler isn't firing...
hard to say...

Maybe your job has signals blocked... or, at least the SIGALRM signal
is blocked? I know that CGI jobs, for example, have this blocked so you
can't use signals there. That is one of the reasons I never use them
anymore.

Also -- I'm not sure if I've ever used SIGALRM with sendmsg/recvmsg. I
typically use alarms with TCP sockets, not UNIX domain sockets. I'm
telling you this because I don't know if they work? They might or might
not... I haven't tried.

Maybe you should try using poll or select instead?

-SK


On 7/27/17 10:26 PM, Alan Campin wrote:
I have a piece of RPG code that is running as part of a C program. The code
is critical code and only one thread at a time can execute it.

I sendmsg and recvmsg to send message between two job.

All works perfectly if that other job is still there but when that job dies
or crashes and I attempt to a recvmsg, it hangs forever.

To avoid that problem, I am using signals Scott has discussed.

I enable the signals and then issue an alarm before I issue the recvmsg.

If I use 1 second and their is nothing out there I would expect for the
recvmsg to hang which it does but the alarm never fires.

I am trying to figure out why the alarm is not firing. Is it possible the
alarm doesn't work because the RPG code was called from a thread in C code?

I just tired some test code that had one program spawn another program and
I did an alarm in that job and it worked so that tells me that the fact
that I am running in a multi-threaded environment must be what is causing
the problem.

I am using Thread(*SERIALIZE) for the RPG module.

Any help would be appreciated.

Qp0sEnableSignals();
sigemptyset(act.sa_mask);
sigaddset(act.sa_mask: SIGALRM);
act.sa_handler = %paddr(GotAlarm);
act.sa_flags = 0;
act.sa_sigaction = *NULL;
sigaction(SIGALRM: act: *omit);

0151.00 Alarm(InTimeout);
0152.00 If RecvMsgApi(InSocket:MsgHdr:0) < 0;
0153.00 GetLastError(ErrorNumber:
0154.00 Msg);
0155.00 Qp0sDisableSignals();
0156.00 If ErrorNumber = EINTR;
0157.00 %Len(Msg) = 0;
0158.00 Return Msg;
0159.00 EndIf;
0160.00

dcl-proc GotAlarm;

dcl-pi *N;

InSignalNumber Int(10) Value;

end-Pi;



// Do nothing. The API will return EINTER("interrupted by signal")
when
// the signal is received.



end-proc;



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.