Can I detect who detached from a channel very easily?


I’m not sure if I’m missing something obvious here but I want to be able to detect who detached from my resource manager.

In my manager, I spawn a thread for each connection. When one closes, I’d like to remove the thread that was assigned to that connection. The reason I care is that I do some statistics gathering so I can’t just re-assign the thread to the next connection, I need to reset all the stats on it so I need to know when someone disconnects, which thread they were assigned.

The problem is that I don’t seem to get the information I need when a process detaches to figure this out. Looking in MsgReceive() I see I can get pulses for DISCONNECT, THREADDEATH and COIDDEATH. I currently handle all these and I get them when processes/threads disconnect (or die). But most of these don’t give any information that would let me determine who the other side was.

DISCONNECT - Gives nothing. I looked at the scoid value and it’s a number I don’t recognize as a thread id or process id or connection
THREADDEATH - Gives a thread id. So I can handle this one by having my remote sides pass in their thread id.
COIDDEATH - The value here seems to be the scoid value in DISCONNECT

So is there a way to associate the scoid value with a thread/process? I tried looking at the IO_CONNECT message and what it passes in but it does not seem to give the scoid value (unless I missed it someplace)



You can the scoid you see in the DISCONNECT and COIDDEATH pulse from your IO_CONNECT message, it’s just hidden in the _msg_info structure.

You can either extract the msg_info from the message using the MsgInfo() function or always have it by including a msg_info struct in your MsgReceive.

For example:

struct _msg_info msg_info;
MsgReceive( chid, &recv_buf, sizeof (recv_buf), &msg_info );

if ( recv_buf.type == _IO_CONNECT ) {
my_connection_scoid = msg_info.scoid;
MsgReply( rcvid, EOK, NULL, 0 );


MsgReceive( chid, &recv_buf, sizeof (recv_buf), NULL );

if ( recv_buf.type == _IO_CONNECT ) {
struct _msg_info msg_info;
MsgInfo(rcvid, &msg_info);
my_connection_scoid = msg_info.scoid;
MsgReply( rcvid, EOK, NULL, 0 );

You can then handle your connection scoid differently wherever you handle the DISCONNECT

if (recv_buf.pulse.scoid == my_connection_scoid) {
//received disconnect for my connection, do something with it
ConnectDetach( recv_buf.pulse.scoid );

Does that work for you?

Note … if you have a scoid, this is kind of a reverse handle back to the process and you can extract more information using ConnectClientInfo() in addition to what Steven wrote.

If you use the resource manager frame work, all these would be handled in the frame work (library) for you.

A CODE_DISCONNECT pulse, would be changed into a close() message, so your close_ocb() callout
get called, and from the ocb, you know which open() it belongs to.