src/irc_net.c
changeset 47 7d4094eb3117
parent 46 0c13bca53ae1
child 48 4841f4398fd2
equal deleted inserted replaced
46:0c13bca53ae1 47:7d4094eb3117
   172     *net_ptr = net;
   172     *net_ptr = net;
   173 
   173 
   174     return SUCCESS;
   174     return SUCCESS;
   175 
   175 
   176 error:
   176 error:
   177     // cleanup
   177     if (sock && !net->conn)
   178     if (net->conn)
       
   179         // irc_conn takes care of the socket as well
       
   180         irc_conn_destroy(net->conn);
       
   181     
       
   182     else if (sock)
       
   183         // we need to clean up the socket ourself
   178         // we need to clean up the socket ourself
   184         sock_stream_release(sock);
   179         sock_stream_release(sock);
   185     
   180     
   186     // release our state
   181     // cleanup main
       
   182     irc_net_destroy(net);
       
   183 
       
   184     return ERROR_CODE(err);
       
   185 }
       
   186 
       
   187 void irc_net_destroy (struct irc_net *net)
       
   188 {
       
   189     struct irc_chan *next = TAILQ_FIRST(&net->channels), *chan;
       
   190 
       
   191     // our conn
       
   192     if (net->conn)
       
   193         irc_conn_destroy(net->conn);
       
   194 
       
   195     // our channels
       
   196     while (next) {
       
   197         chan = next;
       
   198         next = TAILQ_NEXT(chan, node);
       
   199 
       
   200         irc_chan_destroy(chan);
       
   201     }
       
   202 
       
   203     // ourselves
   187     free(net);
   204     free(net);
   188 
       
   189     return ERROR_CODE(err);
       
   190 }
   205 }
   191 
   206 
   192 struct irc_chan* irc_net_add_chan (struct irc_net *net, const struct irc_chan_info *info)
   207 struct irc_chan* irc_net_add_chan (struct irc_net *net, const struct irc_chan_info *info)
   193 {
   208 {
   194     struct irc_chan *chan;
   209     struct irc_chan *chan;