diff options
Diffstat (limited to 'irc.c')
-rw-r--r-- | irc.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -14,11 +14,11 @@ static int tcp_connect(const char *host, int port) struct sockaddr_in addr; struct hostent *h; int sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) + if (sock < 0) return sock; h = gethostbyname(host); - if (h == NULL) + if (h == NULL) return -1; memset(&addr, 0, sizeof(addr)); @@ -38,17 +38,17 @@ struct irc_session *irc_connect(const char* server, int port, const char *nick, { char buf[256]; struct irc_session *sess; - + sess = malloc(sizeof(struct irc_session)); if (sess == NULL) return NULL; - + sess->nick = nick; sess->server = server; sess->fd = tcp_connect(server, port); - if (sess->fd < 0) + if (sess->fd < 0) return NULL; - + /* login */ if (pass) irc_send(sess, "PASS", pass); @@ -79,7 +79,9 @@ int irc_send_ping(struct irc_session *s) int irc_close(struct irc_session *s, const char *msg) { - irc_send(s, "QUIT", msg ? msg : ""); - close(s->fd); + if (s->fd > 0) { + irc_send(s, "QUIT", msg ? msg : ""); + close(s->fd); + } free(s); } |