diff options
-rw-r--r-- | sock_conn.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/sock_conn.c b/sock_conn.c index c926dd1..0c206ea 100644 --- a/sock_conn.c +++ b/sock_conn.c @@ -289,11 +289,11 @@ int irc_connect( char *hostname, char *port ) if (fret!=0) { PERM(); + freeaddrinfo(res); return -1; } - //? - //freeaddrinfo(&serv); + freeaddrinfo(res); return fd; } @@ -305,10 +305,6 @@ int irc_open(char *hostname, char *port, irc_conn *conn) int fd, fret; struct addrinfo serv, *res; - struct timespec tv; - tv.tv_sec = 10; - tv.tv_nsec = 0; - if (conn == NULL) { PERM(); @@ -345,6 +341,9 @@ int irc_open(char *hostname, char *port, irc_conn *conn) conn->liberr = errno; conn->err = ERR_SC_CONN; ERROR("%s:%s\n",conn->hostname, conn->port); + free(conn->hostname); + free(conn->port); + freeaddrinfo(res); return -1; } @@ -354,6 +353,9 @@ int irc_open(char *hostname, char *port, irc_conn *conn) conn->liberr = errno; conn->err = ERR_SC_CONN; perror("OPEN: Couldnt get socket"); + free(conn->hostname); + free(conn->port); + freeaddrinfo(res); return -1; } @@ -364,6 +366,9 @@ int irc_open(char *hostname, char *port, irc_conn *conn) conn->liberr = errno; perror("OPEN: Cant connect"); PERM(); + free(conn->hostname); + free(conn->port); + freeaddrinfo(res); return -1; } @@ -375,6 +380,8 @@ int irc_open(char *hostname, char *port, irc_conn *conn) conn->err = ERR_SC_NONE; conn->liberr = 0; + freeaddrinfo(res); + return 0; } @@ -426,30 +433,23 @@ int irc_read(irc_conn *conn, char *buf, size_t sz) int fret; int save_err; - //PNL(); fret = read(conn->conn_fd, buf, sz); save_err = errno; - //PNL(); if (fret<0) { - //PNL(); if (save_err == EAGAIN) { - //PNL(); uint64_t proc_sec; struct timespec cur_clock; - //PRINT("%d\n", conn->err); //if last time was without error then lets update last error clock if (conn->err == ERR_SC_NONE) { - //PNL(); clock_gettime(CLOCK_REALTIME, &conn->last_read); } if (conn->timeout > 0) { - PNL(); //first read of clock is in irc_read_timeout_function if (-1 == clock_gettime(CLOCK_REALTIME, &cur_clock)) { @@ -492,7 +492,6 @@ int irc_read(irc_conn *conn, char *buf, size_t sz) int irc_reconnect(irc_conn *conn) { int fret; - int fd; char *hostname=NULL; char *port=NULL; int timeout=-1; @@ -507,7 +506,6 @@ int irc_reconnect(irc_conn *conn) //close connection close(conn->conn_fd); - fd = conn->conn_fd; //do we need that to restore connection? hostname = conn->hostname; port = conn->port; @@ -522,16 +520,19 @@ int irc_reconnect(irc_conn *conn) if (-1 == irc_read_timeout(&reconn, timeout)) { + ENL(); } - //BUG lets think about this case deeper - //free(hostname); - //free(port); + free(conn->hostname); + conn->hostname = NULL; + free(conn->port); + conn->port = NULL; memcpy(conn, &reconn, sizeof(irc_conn)); + return 0; } @@ -546,5 +547,7 @@ int irc_close(irc_conn *conn) close(conn->conn_fd); free(conn->hostname); free(conn->port); + + return 0; } |