Recently I have done this part of code.
It does work, but select() works bad.
When it has got last reply from server, it begins repeating last reply string with some strange characters in the beginning of reply string.
So look at this:
:[email protected] PRIVMSG testuser1 :VERSION
�C���C��[email protected] PRIVMSG testuser1 :VERSION
�C���C��[email protected] PRIVMSG testuser1 :VERSION
�C���C��[email protected] PRIVMSG testuser1 :VERSION
�C���C��[email protected] PRIVMSG testuser1 :VERSION
The first string is the last reply from server. So next strings are just some junk. I tried to look for information in some search engines, but no luck.
It's not
select
that has the problem, it's the logic in your code (unsurprisingly).If
select
returns because stdin is readable, then you still look atc[0]
(from the last server read) - and even though you didn't read from the server this time, it's still\n
, because you never reset it.Move this bit of code:
inside the
else if (rc == 1) {
block.