I've got a program that communicates with users directly through TCP stream
sockets using the stdio libraries (had to write my own putchar macro that
writes a \r\n for a \n and my own printf that calls vsprintf then my putchar
macro, fun fun) There is an alarm signal received every five minutes, which
will of course interrupt system calls. Since the program would be unworkable
in its current form otherwise, the system calls are always restarted after
the signal completes (its HP-UX, I have a choice of which behavior I want)
The situation is this: When a user far away loses their connection due to
routing problems, my program of course cannot know this. My problem is that
if my program is writing stuff to this user, it will pile up and eventually
the write will block due to the socket buffer being full. I'd like for my
every-five-minute alarm signal to check and see if the process was interrupted
while blocked on a write -- if it is blocked in the same write two consecutive
alarms I'll assume the connection is mucked up and drop it to avoid wasting
resources. I can be a bit tricky/* and access the stdout->__cnt field and
see if there is stuff in the stdout buffer ready to be written. I'd like to
access the file pointer of the socket. fgetpos(3), ftell(3), and lseek(2) all
work fine for ttys, but don't work for sockets. If I could get this
information for the socket I could compare and if there is stuff in the stdout
buffer two consecutive times but the file pointer is the same I could decide
to terminate that connection.
I know this information exists somewhere, the HP-UX program 'monitor' can
examine a process and show various information about it, including the files
that are open and their current file position. It shows the values when I
examine my program, they are in there somewhere, I just can't figure out how
to get at them. Anyone know how? Is it portable to other systems? Or,
alternatively, can you figure out a better way to do what I want to do? I
can't send anything to the user, that'll cause problems, I have to be able
to do it from the state available to my program, without grunging in the
kernel.
Thanks for any ideas/suggestions!
--
/--------------------------------------------------------------------------
| Doug Siebert | "I don't have to take this abuse |
| ICBM: 41d 39m 55s N, 91d 30m 43s W | me!" Bill Murray, Ghostbusters |
\--------------------------------------------------------------------------