[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference clt::cma

Title:DECthreads Conference
Moderator:PTHRED::MARYSTEON
Created:Mon May 14 1990
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1553
Total number of notes:9541

1482.0. "Catching SIGPIPE as exception" by BER::BALAMIR () Mon Feb 10 1997 12:47

Hi 

I have cma related calls , i would like to port it to UNIX Version 4.0A

The code has the following form TRY
            {
            sent = send(conn_id, send_bufr, send_len, 0);
            }
        CATCH (exc_SIGPIPE_e)
            {
            sigpipe = 1;
            }
        ENDTRY


How can i change under new POSIX stantard 

Thanks

It is very urgent
T.RTitleUserPersonal
Name
DateLines
1482.1DCETHD::BUTENHOFDave Butenhof, DECthreadsMon Feb 10 1997 15:5137
Actually, this turns out to be pretty easy (easier than I thought when we
talked on the phone... the definition was just hidden in a macro). The names
have changed, but that's all. The changes are mostly because, with support
for the formal POSIX standard, we had to be much more careful about
"namespace pollution"... we're not allowed to define names like TRY, CATCH,
ENDTRY, or exc_* names when you include <pthread.h> unless you do something
"non-standard". (Including <cma.h> or <pthread_d4.h> is always
"non-standard", so they define the old names for compatibility.)

#include <pthread.h>
#include <pthread_exception.h>

	.
	.
	.

    PTHREAD_TRY_NP {
	.
	.
	.
	}
    PTHREAD_CATCH_NP (pthread_exc_SIGPIPE_e) {
	.
	.
	.
	}
    PTHREAD_ENDTRY_NP

And, a reminder... POSIX doesn't have exceptions, so if you use our exception
package, you are not using the "POSIX standard", and your code won't be
portable to other implementations of POSIX threads. To be completely
portable, you need to give up the power, modularity, and flexibility of
exceptions and simply set up a signal action for SIGPIPE. (Of course, doing
so will overwrite the DECthreads signal handler, and prevent any other code
in the process from catching SIGPIPE as an exception...)

	/dave
1482.2DCETHD::BUTENHOFDave Butenhof, DECthreadsMon Feb 10 1997 15:533
(By the way, I deleted your second note, 1483, on this topic. We didn't
really need two, and I think the wording of your first attempt is a little
better.)
1482.3VAXCPU::michaudJeff Michaud - ObjectBrokerTue Feb 11 1997 14:4922
> The code has the following form TRY
>             {
>             sent = send(conn_id, send_bufr, send_len, 0);
>             }
>         CATCH (exc_SIGPIPE_e)
>             {
>             sigpipe = 1;
>             }
>         ENDTRY

	Personally I prefer what Dave hinted at, simply do a:

	    signal(SIGPIPE, SIG_IGN);

	at the appropropriate place in your startup code and
	then you can code like this:

	    sent = send(conn_id, send_bufr, send_len, 0);
	    if( sent == -1 && errno == EPIPE )
		sigpipe = 1; /* or whatever */

	which is relatively portable to most UNIXes.