mcpcpc / kirc

A tiny IRC client written in POSIX C99.

Home Page:https://mcpcpc.github.io/kirc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connecting timeout issue

cfferry opened this issue · comments

Dear Kirc Staff:

I would like to suggest a small modification. It does appear that in some cases kirc gets stuck while trying to connect to a remote host that may have strong firewall policies. I can think of this example:

./kirc -s www.google.com -n test

Kirc will be hanged and will wait for remote host response for a very long period of time. I recommend the following solutions (requires including <sys/time.h>):

Adding in line 669:

struct timeval timeout;
timeout.tv_sec = 3;
timeout.tv_usec = 0;

where a timeout of 3 seconds is set, and then adding the following to line 680:

setsockopt(conn, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval));

This will cause Kirc to exit and display an error message as a connecting timeout of 3 seconds is reached.

I'm open to feedback or ideas, and certainly discuss further if this is not a proper solution.

Hi Carlos,

I think it's a reasonable solution. I am not sure about the timeout of 3 seconds though... we may want to increase that.

-mcpcpc

Hi Carlos,

I apologize for the updates that have been far and few in between. After having spent a little time looking over this issue, I have come to the conclusion to not use setsockopt() due to portability concerns. In fact, implementing this solution makes no difference in my development environment (e.g. the timeout is ~3sec regardless of the setting for timeout.tv_usec). The most robust solution I can think of would be to (1) create the socket connection (2) set the fd to non-blocking mode and (3) use poll() to check this status of the fd and see if some predetermined timeout condition is met.

More to come in the next week or two... I figured I owed some explanation for the delay. =S

Thanks for responding, Michael.

What you propose sounds like a better approach, certainly.
I will be following this issue!

Have a great week.