Poll() - Not returning

Hello all

I am writing some code to multiplex a GSM Modem. It is all working fine apart from one vital part, when i poll the pseudo serial ports the poll never returns.

You will notice that when the reader starts (thread body below) poll is called with just the actual serial device file descriptor first; then, once the muxed communications have been established with the modem and the channels have been opened, we poll for events on the pseudo serial devices as well.

When calling poll with just the modems serial file descriptor, it works, even when the channels are open, i can see data passed from the modem to the pseudo serial ports, but when i poll for events coming back down the pseudo serial port (as well as the modem), poll never returns, for either the modem or the pseudo devices.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
void* GsmMux::Body(void)
{
	struct pollfd pfd[1];
	struct pollfd pfd_channels[mDLC_Max+1];
	int nfd = 1;
	int nfd_channels = mDLC_Max+1; // Plus control channel
	int timeout = -1;

	// Initialise the pollfd array
	pfd_channels[0].fd = pfd[0].fd = mSerial.fd;
	pfd_channels[0].events = pfd[0].events = POLLIN;
	pfd_channels[0].revents = pfd[0].revents = NULL;

	bool openedChannels = false;
	while(mMuxing)
	{
		// If the control channel is open, then the device channels
		// are also open and we need to start listening for data on them.
		if(!openedChannels && mChannelList[0].opened)
		{
			for(int i = 1; i <= mDLC_Max; i++)
			{
				if(mChannelList[i].fd != -1)
				{
					pfd_channels[i].fd = mChannelList[i].fd;
					pfd_channels[i].events = POLLIN;
					pfd_channels[i].revents = NULL;
					nfd++;
				}
			}
			openedChannels = true;
		}

		int events = 0;
		if ((events = poll( openedChannels ? pfd_channels : pfd,
							openedChannels ? nfd_channels : nfd,
							timeout)) > 0)
		{
			// Make sure we cover all events
			for(int i = 0; i < events; i++)
			{	// Find the event fd
				int b = 0; // channel
				for(; b < mDLC_Max; b++)
				{
					if(pfd[b].revents != 0)
					{
						break;
					}
				}

				// Read appropriate device. Channel 0 data, indicates
				// that data is coming from the actual serial device.
				// Other channels indicates data coming from the pseudo devices.
				if((pfd[b].revents & POLLIN) && b == 0)
					this->SerialDeviceRead();
				else if((pfd[b].revents & POLLIN) && b < mDLC_Max)
					this->PseudoDeviceRead(b); // Shift the channel pointer as 0 is the control channel
				

				// Handled event
				pfd[b].revents = NULL;
			}
		}
	}

	return 0;
}


If anyone knows why this could be happening, please let me know.

Thanks,

Ne0
Topic archived. No new replies allowed.