Matthias Scheutz <mscheutz@cse.nd.edu> wrote:
> Date: Mon, 3 Mar 2003 11:02:48 -0500 (EST)
>
> I've run into a problem with sockets that are closed by a client (i.e., a
> web browser) while the server (a primitive web server written in pop11) is
> still writing to it: I keep getting the MISHAP "ERROR WRITING DEVICE",
> which crashes my web server (this is produced by the procedure
> "Write_error(dev)" in devio.p).
>
> I'm wondering if there is a way to suppress the mishap for write errors on
> sockets? E.g., is it possible to set the flag "M_UNT_IGNORE_WRITE_ERR"
> flag for the socket device, something like
>
> comm_sock!D_UNIT_N!UNT_FLAGS || M_UNT_IGNORE_WRITE_ERR ->
> comm_sock!D_UNIT_N!UNT_FLAGS;
Alas this is an example of code that is available in the pop11
system sources as compiled by popc when building the system but
cannot be compiled by the user at run time.
> (I tried to compile the above, which was modelled after the way code was
> written in devio.p, but was not successful, in particular, pop did not
> recognize the variables, it did not like the "!", and so on... obviously,
> I'm doing something very wrong here :)
There is some information on the 'system dialect' of pop-11 here
http://www.cs.bham.ac.uk/research/poplog/sysdoc/syspop11
It extends pop11 so as to give programmers some of the extra flexibility
that C programmers have (with all the associated risks).
One option would be to rewrite some of the procedures in devio.p,
recompile and rebuilt poplog. But you would really need to know what
you are doing.
> which would then make "Write_error(dev)" simply return instead of
> producing the mishap?
A really nasty but often very useful way of doing this would be to use
the fact that Write_error, defined in $popsrc/devio.p invokes
Syserr_mishap, defined in $popsrc/errors.p, and Syserr_mishap invokes
the user-definable procedure mishap, which you can define (locally, just
before you call syswrite, i.e.
define dlocal mishap(string, list);
....
exitto( ....);
enddefine;
to make control exit through various sytem procedures to one of your
procedures, using chainto or exitto or chainfrom or exitfrom (all of
which have HELP files as well as being summarised in REF procedure).
(See also HELP MISHAP, REF exception).
But there ought to be a better way of doing this. I notice that
Write_error calls the user definable procedure pop_file_write_error
but not for all devices, so maybe you can't use that to force
the sort of exit you want.
Looking at the code in $popsrc/devio.p the fact that there is the test
you noticed, using the internal variable M_UNT_IGNORE_WRITE_ERR suggests
that there should be a way of setting a device so that write errors
are ignored. However, the comment in the change notes suggests that that
bit is set only for the standard write_error device.
So I looked at LIB unix_sockets, and found that sys_socket and
sys_socket_pair call the non-exported procedure make_sock_dev, which
calls Sys_cons_device, which is exported from the system (defined in
devio.p) but undocumented. Perhaps that procedure needs to be changed to
allow users to specify that the device being constructed should not
produce write errors.
But I don't know if that really would make sense in the context you have
described.
Maybe the only option for now is to redefine mishap locally in your
procedure that calls syswrite, to trap the error. It could maybe also
return some information that indicates that the socket cannot be written
to.
Maybe someone who knows more about sockets than I do can add something
or correct what I've said.
Aaron
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
|