Re: Preliminary fix for blocked socket closing.

From: George (
Date: 01/16/99

On Fri, 15 Jan 1999, Daniel Koepke wrote:

>I prefer,
>  if ((d->has_prompt = process_output(d)) < 0)
>    close_socket(d);

Good point.  My original thought was that -1 wasn't a valid '->has_prompt'
value.  But since we're disconnecting them, what's the difference if it is
invalid? :)

>>  int process_output(struct descriptor_data *t)
>>  {
>>    char i[MAX_SOCK_BUF];
>>    int written, offset;
>     int result;
>>    if (t->has_prompt)           /* && !t->connected) */
>>      offset = 0;
>     else
>       offset = 2;
>     result = write_to_descriptor(t->descriptor, i + offset, &written);

We have to retain the code to remove the large_outbuf and reset the small
bufsize otherwize the call to write_to_output() will simply append to the
text we already have in the buffer.  The problem with that being we've
already written the first part of the buffer.

Current problem with my code is if we had to restart the output, the
snooping immortal will get the end portion twice.

>     if (result == 0)
>       write_to_output(i + written + offset, t);
>     return (result);

I played with doing the buffer processing myself to avoid the reset/append
cycle with a simple strcpy() but it wasn't so simple.  You have to take
into account if they have a large buffer and only now need a smaller
buffer and the offset issue gave me a minor headache too.  The
write_to_output() gave me a nice clean way to do it, after resetting the
output queue info.

> *  1  All is well and good.
> *  0  The socket write would block, written is modified with the
> *     number of bytes written previously.
> * -1  An error was encountered, disconnect the socket.
> */
> int write_to_descriptor(socket_t desc, const char *txt, int * written)
> {

While less efficient, I don't care about efficiency in this case.  :) This
would be nice to retain the '-1 = cya' behavior of the socket functions and
prevent my 'result = -result' transformation later to avoid negatives.

Ok, new patch forthcoming.  Something tells me I probably want to fix the
snooping problem too or I'll never hear the end of the bug reports...

George Greer

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 12/15/00 PST