mIRC Homepage
Posted By: rogue Buffer flushing. - 08/07/03 03:21 AM
It looks like mIRC's receive buffer doesn't get flushed when the socket is closed. Here's a code snippet to illustrate:

Code:
/* server.c */
char *message = ":irc.example.com NOTICE AUTH :This is some text to send\r\n";
  .
  .
  .
new_socket = accept(create_socket,(struct sockaddr *)&address, &addrlen);
send(new_socket, message, strlen(message), 0);
close(new_socket);


When mIRC connects it displays the usual "Software caused connection abort", but with out the message... add a sleep(1); before close(); and it works as expected.

Perhaps codemastr or someone more familiar with the issue could chime in if I'm missing something.
Posted By: codemastr Re: Buffer flushing. - 08/07/03 03:02 PM
Well I'm thinking it is really a problem with your code, you shouldn't be calling close(). Close is a "hard" close. If you use shutdown instead, I'd assume it would work.
shutdown(new_socket, SHUT_RDWR);

Btw thats assuming your on a *nix OS, which based on that code it appears you are, and I'm not too good with *nix sockets so I could be wrong with the cause.
Posted By: rogue Re: Buffer flushing. - 08/07/03 07:42 PM
Yep, on *nix... I gave that a try and found sleep(1); was still needed before closing the socket. Incidentally, the message is displayed by other clients like xChat and telnet.

The man page isn't much help, but as near as I can tell all shutdown() does (becides giving more control over tearing down the socket) is throw away any data that might have arrived.

Here's some simple code if anyone wants to play.
Posted By: naki Re: Buffer flushing. - 09/07/03 01:24 AM
umm... mIRC isnt *nix?
Posted By: Watchdog Re: Buffer flushing. - 09/07/03 03:13 AM
mIRC is a chat programme. *nix is a short expression for Unix/Linux OS's.
Posted By: naki Re: Buffer flushing. - 09/07/03 04:51 AM
I knew that. But I wasnt sure if the person was asking for *nix help since this is a mIRC fourm.
Posted By: rogue Re: Buffer flushing. - 09/07/03 06:09 AM
No, I was just using some simple "IRC server" code to illustrate what appears to be a logic bug in mIRC's handling of its receive buffer.

To put it another way... it looks like when the connection is closed, the event handler that does the cleanup doesn't bother to check if anything else came in since the last time the parent checked.
© mIRC Discussion Forums