mIRC Home    About    Download    Register    News    Help

Print Thread
#34911 08/07/03 03:21 AM
Joined: Jan 2003
Posts: 73
R
rogue Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Jan 2003
Posts: 73
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.

#34912 08/07/03 03:02 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

#34913 08/07/03 07:42 PM
Joined: Jan 2003
Posts: 73
R
rogue Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Jan 2003
Posts: 73
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.

#34914 09/07/03 01:24 AM
Joined: Feb 2003
Posts: 143
N
Vogon poet
Offline
Vogon poet
N
Joined: Feb 2003
Posts: 143
umm... mIRC isnt *nix?


We don't just write the scripts, we put them to the test! (ScriptBusters)
#34915 09/07/03 03:13 AM
Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
mIRC is a chat programme. *nix is a short expression for Unix/Linux OS's.

#34916 09/07/03 04:51 AM
Joined: Feb 2003
Posts: 143
N
Vogon poet
Offline
Vogon poet
N
Joined: Feb 2003
Posts: 143
I knew that. But I wasnt sure if the person was asking for *nix help since this is a mIRC fourm.


We don't just write the scripts, we put them to the test! (ScriptBusters)
#34917 09/07/03 06:09 AM
Joined: Jan 2003
Posts: 73
R
rogue Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Jan 2003
Posts: 73
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.


Link Copied to Clipboard